QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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(QgsLayout *layout)
Constructor for QgsLayoutItemTextTable, for the specified layout.
int type() const override
Returns unique multiframe type id.
static QgsLayoutItemTextTable * create(QgsLayout *layout)
Returns a new QgsLayoutItemTextTable for the specified parent layout.
A class to display a table in the print layout, and allow the table to span over multiple frames...
virtual void refreshAttributes()
Refreshes the contents shown in the table by querying for new data.
const QgsLayout * layout() const
Returns the layout the object is attached to.
void setContents(const QVector< QStringList > &contents)
Sets the contents of the text table.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
void addRow(const QStringList &row)
Adds a row to the table.
QString displayName() const override
Returns the multiframe display name.
QgsLayoutTableColumns mColumns
Columns to show in table.
QgsLayoutTableContents & contents()
Returns the current contents of the table.
bool getTableContents(QgsLayoutTableContents &contents) override
Fetches the contents used for the cells in the table.
A text table item that reads text from string lists.
QVector< QgsLayoutTableRow > QgsLayoutTableContents
List of QgsLayoutTableRows, representing rows and column cell contents for a QgsLayoutTable.
QVector< QVariant > QgsLayoutTableRow
List of QVariants, representing a the contents of a single row in a QgsComposerTable.
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.