QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgslayoutitemtexttable.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitemtexttable.cpp
3  --------------------------
4  begin : November 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgslayoutitemtexttable.h"
19 #include "qgslayouttablecolumn.h"
20 #include "qgslayoutframe.h"
21 #include "qgslayout.h"
22 
24  : QgsLayoutTable( layout )
25 {
26 
27 }
28 
30 {
32 }
33 
35 {
36  return tr( "<Text table frame>" );
37 }
38 
40 {
41  return new QgsLayoutItemTextTable( layout );
42 }
43 
44 void QgsLayoutItemTextTable::addRow( const QStringList &row )
45 {
46  mRowText.append( row );
48 }
49 
50 void QgsLayoutItemTextTable::setContents( const QVector<QStringList> &contents )
51 {
52  mRowText = contents;
54 }
55 
57 {
58  contents.clear();
59 
60  for ( const QStringList &row : qgis::as_const( mRowText ) )
61  {
62  QgsLayoutTableRow currentRow;
63 
64  for ( int i = 0; i < mColumns.count(); ++i )
65  {
66  if ( i < row.count() )
67  {
68  currentRow << row.at( i );
69  }
70  else
71  {
72  currentRow << QString();
73  }
74  }
75  contents << currentRow;
76  }
77 
79  return true;
80 }
QgsLayoutItemTextTable::addRow
void addRow(const QStringList &row)
Adds a row to the table.
Definition: qgslayoutitemtexttable.cpp:44
QgsLayoutObject::layout
const QgsLayout * layout() const
Returns the layout the object is attached to.
Definition: qgslayoutobject.cpp:126
QgsLayoutItemTextTable::setContents
void setContents(const QVector< QStringList > &contents)
Sets the contents of the text table.
Definition: qgslayoutitemtexttable.cpp:50
QgsLayoutItemTextTable::displayName
QString displayName() const override
Returns the multiframe display name.
Definition: qgslayoutitemtexttable.cpp:34
QgsLayoutTableContents
QVector< QgsLayoutTableRow > QgsLayoutTableContents
List of QgsLayoutTableRows, representing rows and column cell contents for a QgsLayoutTable.
Definition: qgslayouttable.h:47
QgsLayoutItemTextTable::getTableContents
bool getTableContents(QgsLayoutTableContents &contents) override
Fetches the contents used for the cells in the table.
Definition: qgslayoutitemtexttable.cpp:56
qgslayoutframe.h
QgsLayoutTable::contents
QgsLayoutTableContents & contents()
Returns the current contents of the table.
Definition: qgslayouttable.h:550
QgsLayoutItemTextTable::create
static QgsLayoutItemTextTable * create(QgsLayout *layout)
Returns a new QgsLayoutItemTextTable for the specified parent layout.
Definition: qgslayoutitemtexttable.cpp:39
QgsLayoutItemTextTable::type
int type() const override
Returns unique multiframe type id.
Definition: qgslayoutitemtexttable.cpp:29
QgsLayoutTable
A class to display a table in the print layout, and allow the table to span over multiple frames.
Definition: qgslayouttable.h:113
QgsLayoutTable::refreshAttributes
virtual void refreshAttributes()
Refreshes the contents shown in the table by querying for new data.
Definition: qgslayouttable.cpp:1031
qgslayout.h
QgsLayoutTable::recalculateTableSize
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.
Definition: qgslayouttable.cpp:1530
QgsLayoutItemTextTable::QgsLayoutItemTextTable
QgsLayoutItemTextTable(QgsLayout *layout)
Constructor for QgsLayoutItemTextTable, for the specified layout.
Definition: qgslayoutitemtexttable.cpp:23
QgsLayoutItemTextTable
A text table item that reads text from string lists.
Definition: qgslayoutitemtexttable.h:31
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
qgslayouttablecolumn.h
QgsLayoutItemRegistry::LayoutTextTable
@ LayoutTextTable
Preset text table.
Definition: qgslayoutitemregistry.h:334
qgslayoutitemtexttable.h
QgsLayoutTableRow
QVector< QVariant > QgsLayoutTableRow
List of QVariants, representing a the contents of a single row in a QgsLayoutTable.
Definition: qgslayouttable.h:30
QgsLayoutTable::mColumns
QgsLayoutTableColumns mColumns
Columns to show in table.
Definition: qgslayouttable.h:615