Skip to content

Commit 3a0f943

Browse files
committed
Port text table
1 parent 9cf6e0a commit 3a0f943

File tree

5 files changed

+195
-0
lines changed

5 files changed

+195
-0
lines changed

python/core/core_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@
425425
%Include layout/qgslayoutitemregistry.sip
426426
%Include layout/qgslayoutitemscalebar.sip
427427
%Include layout/qgslayoutitemshape.sip
428+
%Include layout/qgslayoutitemtexttable.sip
428429
%Include layout/qgslayoutmodel.sip
429430
%Include layout/qgslayoutmultiframe.sip
430431
%Include layout/qgslayoutpagecollection.sip
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayoutitemtexttable.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsLayoutItemTextTable : QgsLayoutTable
13+
{
14+
%Docstring
15+
A text table item that reads text from string lists
16+
.. versionadded:: 3.0
17+
%End
18+
19+
%TypeHeaderCode
20+
#include "qgslayoutitemtexttable.h"
21+
%End
22+
public:
23+
24+
QgsLayoutItemTextTable( QgsLayout *layout );
25+
%Docstring
26+
Constructor for QgsLayoutItemTextTable, for the specified ``layout``.
27+
%End
28+
29+
void addRow( const QStringList &row );
30+
%Docstring
31+
Adds a row to the table
32+
\param row list of strings to use for each cell's value in the newly added row
33+
.. note::
34+
35+
If row is shorter than the number of columns in the table than blank cells
36+
will be inserted at the end of the row. If row contains more strings then the number
37+
of columns in the table then these extra strings will be ignored.
38+
.. note::
39+
40+
if adding many rows, setContents() is much faster
41+
%End
42+
43+
void setContents( const QVector< QStringList > &contents );
44+
%Docstring
45+
Sets the contents of the text table.
46+
\param contents list of table rows
47+
.. seealso:: addRow
48+
%End
49+
50+
virtual bool getTableContents( QgsLayoutTableContents &contents );
51+
52+
53+
};
54+
55+
/************************************************************************
56+
* This file has been generated automatically from *
57+
* *
58+
* src/core/layout/qgslayoutitemtexttable.h *
59+
* *
60+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
61+
************************************************************************/

src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ SET(QGIS_CORE_SRCS
388388
layout/qgslayoutitemregistry.cpp
389389
layout/qgslayoutitemscalebar.cpp
390390
layout/qgslayoutitemshape.cpp
391+
layout/qgslayoutitemtexttable.cpp
391392
layout/qgslayoutitemundocommand.cpp
392393
layout/qgslayoutmeasurement.cpp
393394
layout/qgslayoutmeasurementconverter.cpp
@@ -755,6 +756,7 @@ SET(QGIS_CORE_MOC_HDRS
755756
layout/qgslayoutitemregistry.h
756757
layout/qgslayoutitemscalebar.h
757758
layout/qgslayoutitemshape.h
759+
layout/qgslayoutitemtexttable.h
758760
layout/qgslayoutmodel.h
759761
layout/qgslayoutmultiframe.h
760762
layout/qgslayoutpagecollection.h
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
23+
QgsLayoutItemTextTable::QgsLayoutItemTextTable( QgsLayout *layout )
24+
: QgsLayoutTable( layout )
25+
{
26+
27+
}
28+
29+
void QgsLayoutItemTextTable::addRow( const QStringList &row )
30+
{
31+
mRowText.append( row );
32+
refreshAttributes();
33+
}
34+
35+
void QgsLayoutItemTextTable::setContents( const QVector<QStringList> &contents )
36+
{
37+
mRowText = contents;
38+
refreshAttributes();
39+
}
40+
41+
bool QgsLayoutItemTextTable::getTableContents( QgsLayoutTableContents &contents )
42+
{
43+
contents.clear();
44+
45+
for ( const QStringList &row : qgis::as_const( mRowText ) )
46+
{
47+
QgsLayoutTableRow currentRow;
48+
49+
for ( int i = 0; i < mColumns.count(); ++i )
50+
{
51+
if ( i < row.count() )
52+
{
53+
currentRow << row.at( i );
54+
}
55+
else
56+
{
57+
currentRow << QString();
58+
}
59+
}
60+
contents << currentRow;
61+
}
62+
63+
recalculateTableSize();
64+
return true;
65+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/***************************************************************************
2+
qgslayoutitemtexttable.h
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+
#ifndef QGSLAYOUTTEXTTABLE_H
19+
#define QGSLAYOUTTEXTTABLE_H
20+
21+
#include "qgis_core.h"
22+
#include "qgis.h"
23+
#include "qgslayouttable.h"
24+
25+
/**
26+
* \ingroup core
27+
* A text table item that reads text from string lists
28+
* \since QGIS 3.0
29+
*/
30+
class CORE_EXPORT QgsLayoutItemTextTable : public QgsLayoutTable
31+
{
32+
33+
Q_OBJECT
34+
35+
public:
36+
37+
/**
38+
* Constructor for QgsLayoutItemTextTable, for the specified \a layout.
39+
*/
40+
QgsLayoutItemTextTable( QgsLayout *layout );
41+
42+
/**
43+
* Adds a row to the table
44+
* \param row list of strings to use for each cell's value in the newly added row
45+
* \note If row is shorter than the number of columns in the table than blank cells
46+
* will be inserted at the end of the row. If row contains more strings then the number
47+
* of columns in the table then these extra strings will be ignored.
48+
* \note if adding many rows, setContents() is much faster
49+
*/
50+
void addRow( const QStringList &row );
51+
52+
/**
53+
* Sets the contents of the text table.
54+
* \param contents list of table rows
55+
* \see addRow
56+
*/
57+
void setContents( const QVector< QStringList > &contents );
58+
59+
bool getTableContents( QgsLayoutTableContents &contents ) override;
60+
61+
private:
62+
//! One stringlist per row
63+
QVector< QStringList > mRowText;
64+
};
65+
66+
#endif // QGSLAYOUTTEXTTABLE_H

0 commit comments

Comments
 (0)