QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
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
44void QgsLayoutItemTextTable::addRow( const QStringList &row )
45{
46 mRowText.append( row );
48}
49
50void QgsLayoutItemTextTable::setContents( const QVector<QStringList> &contents )
51{
52 mRowText = contents;
54}
55
57{
58 contents.clear();
59
60 for ( const QStringList &row : std::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}
@ LayoutTextTable
Preset text table.
A text table item that reads text from string lists.
static QgsLayoutItemTextTable * create(QgsLayout *layout)
Returns a new QgsLayoutItemTextTable for the specified parent layout.
QgsLayoutItemTextTable(QgsLayout *layout)
Constructor for QgsLayoutItemTextTable, for the specified layout.
QString displayName() const override
Returns the multiframe display name.
bool getTableContents(QgsLayoutTableContents &contents) override
Fetches the contents used for the cells in the table.
int type() const override
Returns unique multiframe type id.
void addRow(const QStringList &row)
Adds a row to the table.
void setContents(const QVector< QStringList > &contents)
Sets the contents of the text table.
const QgsLayout * layout() const
Returns the layout the object is attached to.
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.
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.
QgsLayoutTableColumns mColumns
Columns to show in table.
QgsLayoutTableContents & contents()
Returns the current contents of the table.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
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 QgsLayoutTable.