Skip to content

Commit 9cf6e0a

Browse files
committedNov 24, 2017
Start porting table items
1 parent a615a48 commit 9cf6e0a

File tree

8 files changed

+3039
-0
lines changed

8 files changed

+3039
-0
lines changed
 

‎python/core/core_auto.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
%Include layout/qgslayoutserializableobject.sip
169169
%Include layout/qgslayoutsize.sip
170170
%Include layout/qgslayoutsnapper.sip
171+
%Include layout/qgslayouttablecolumn.sip
171172
%Include layout/qgslayoutundocommand.sip
172173
%Include layout/qgslayoututils.sip
173174
%Include metadata/qgslayermetadata.sip
@@ -428,6 +429,7 @@
428429
%Include layout/qgslayoutmultiframe.sip
429430
%Include layout/qgslayoutpagecollection.sip
430431
%Include layout/qgslayoutobject.sip
432+
%Include layout/qgslayouttable.sip
431433
%Include layout/qgslayoutundostack.sip
432434
%Include symbology/qgscptcityarchive.sip
433435
%Include symbology/qgssvgcache.sip

‎python/core/layout/qgslayouttable.sip

Lines changed: 586 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayouttablecolumn.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
class QgsLayoutTableColumn
14+
{
15+
%Docstring
16+
Stores properties of a column for a QgsLayoutTable. Some properties of aQgsLayoutTableColumn
17+
are applicable only in certain contexts. For instance, the attribute and setAttribute methods only
18+
have an effect for QgsLayoutItemAttributeTables, and have no effect for QgsLayoutItemTextTables.
19+
.. versionadded:: 3.0
20+
%End
21+
22+
%TypeHeaderCode
23+
#include "qgslayouttablecolumn.h"
24+
%End
25+
public:
26+
27+
QgsLayoutTableColumn( const QString &heading = QString() );
28+
%Docstring
29+
Constructor for QgsLayoutTableColumn.
30+
\param heading column heading
31+
%End
32+
33+
bool writeXml( QDomElement &columnElem, QDomDocument &doc ) const;
34+
%Docstring
35+
Writes the column's properties to xml for storage.
36+
\param columnElem an existing QDomElement in which to store the column's properties.
37+
\param doc QDomDocument for the destination xml.
38+
.. seealso:: readXml()
39+
:rtype: bool
40+
%End
41+
42+
bool readXml( const QDomElement &columnElem );
43+
%Docstring
44+
Reads the column's properties from xml.
45+
\param columnElem a QDomElement holding the column's desired properties.
46+
.. seealso:: writeXml()
47+
:rtype: bool
48+
%End
49+
50+
double width() const;
51+
%Docstring
52+
Returns the width for the column in mm,
53+
or 0 if column width is automatically calculated.
54+
.. seealso:: setWidth()
55+
:rtype: float
56+
%End
57+
58+
void setWidth( const double width );
59+
%Docstring
60+
Sets the width for a column in mm. Set the ``width`` to 0 if the column width is to be automatically calculated.
61+
.. seealso:: width()
62+
%End
63+
64+
QString heading() const;
65+
%Docstring
66+
Returns the heading for a column, which is the value displayed in the column's
67+
header cell.
68+
.. seealso:: setHeading()
69+
:rtype: str
70+
%End
71+
72+
void setHeading( const QString &heading );
73+
%Docstring
74+
Sets the ``heading`` for a column, which is the value displayed in the column's
75+
header cell.
76+
.. seealso:: heading()
77+
%End
78+
79+
Qt::AlignmentFlag hAlignment() const;
80+
%Docstring
81+
Returns the horizontal alignment for a column, which controls the alignment
82+
used for drawing column values within cells.
83+
.. seealso:: setHAlignment()
84+
.. seealso:: vAlignment()
85+
:rtype: Qt.AlignmentFlag
86+
%End
87+
88+
void setHAlignment( Qt::AlignmentFlag alignment );
89+
%Docstring
90+
Sets the horizontal ``alignment`` for a column, which controls the alignment
91+
used for drawing column values within cells.
92+
.. seealso:: hAlignment()
93+
.. seealso:: setVAlignment()
94+
%End
95+
96+
Qt::AlignmentFlag vAlignment() const;
97+
%Docstring
98+
Returns the vertical alignment for a column, which controls the alignment
99+
used for drawing column values within cells.
100+
.. seealso:: setVAlignment()
101+
.. seealso:: hAlignment()
102+
:rtype: Qt.AlignmentFlag
103+
%End
104+
105+
void setVAlignment( Qt::AlignmentFlag alignment );
106+
%Docstring
107+
Sets the vertical ``alignment`` for a column, which controls the alignment
108+
used for drawing column values within cells.
109+
.. seealso:: vAlignment()
110+
.. seealso:: setHAlignment()
111+
%End
112+
113+
QString attribute() const;
114+
%Docstring
115+
Returns the attribute name or expression used for the column's values. This property
116+
is only used when the column is part of a QgsLayoutItemAttributeTable.
117+
.. note::
118+
119+
only applicable when used in a QgsLayoutItemAttributeTable
120+
.. seealso:: setAttribute()
121+
:rtype: str
122+
%End
123+
124+
void setAttribute( const QString &attribute );
125+
%Docstring
126+
Sets the ``attribute`` name or expression used for the column's values. This property
127+
is only used when the column is part of a QgsLayoutItemAttributeTable.
128+
.. note::
129+
130+
only applicable when used in a QgsLayoutItemAttributeTable
131+
.. seealso:: attribute()
132+
%End
133+
134+
Qt::SortOrder sortOrder() const;
135+
%Docstring
136+
Returns the sort order for the column. This property is only used when the column
137+
is part of a QgsLayoutItemAttributeTable and when sortByRank is > 0.
138+
.. note::
139+
140+
only applicable when used in a QgsLayoutItemAttributeTable
141+
.. seealso:: setSortOrder()
142+
.. seealso:: sortByRank()
143+
:rtype: Qt.SortOrder
144+
%End
145+
146+
void setSortOrder( Qt::SortOrder order );
147+
%Docstring
148+
Sets the sort ``order`` for the column. This property is only used when the column
149+
is part of a QgsLayoutItemAttributeTable and when sortByRank() is > 0.
150+
.. note::
151+
152+
only applicable when used in a QgsLayoutItemAttributeTable
153+
.. seealso:: sortOrder()
154+
.. seealso:: setSortByRank()
155+
%End
156+
157+
int sortByRank() const;
158+
%Docstring
159+
Returns the sort rank for the column. If the sort rank is > 0 then the column
160+
will be sorted in the table. The sort rank specifies the priority given to the
161+
column when the table is sorted by multiple columns, with lower sort ranks
162+
having higher priority. This property is only used when the column
163+
is part of a QgsLayoutItemAttributeTable.
164+
165+
If sort rank is <= 0 then the column is not being sorted.
166+
167+
.. note::
168+
169+
only applicable when used in a QgsLayoutItemAttributeTable
170+
.. seealso:: setSortByRank()
171+
.. seealso:: sortOrder()
172+
:rtype: int
173+
%End
174+
175+
void setSortByRank( int rank );
176+
%Docstring
177+
Sets the sort ``rank`` for the column. If the sort rank is > 0 then the column
178+
will be sorted in the table. The sort rank specifies the priority given to the
179+
column when the table is sorted by multiple columns, with lower sort ranks
180+
having higher priority. This property is only used when the column
181+
is part of a QgsComposerAttributeTable.
182+
If the sort ``rank`` is <= 0 then the column is not being sorted.
183+
184+
.. note::
185+
186+
only applicable when used in a QgsLayoutItemAttributeTable
187+
.. seealso:: sortByRank()
188+
.. seealso:: setSortOrder()
189+
%End
190+
191+
QgsLayoutTableColumn *clone() /Factory/;
192+
%Docstring
193+
Creates a duplicate column which is a deep copy of this column.
194+
:return: a new QgsLayoutTableColumn with same properties as this column.
195+
:rtype: QgsLayoutTableColumn
196+
%End
197+
198+
};
199+
200+
/************************************************************************
201+
* This file has been generated automatically from *
202+
* *
203+
* src/core/layout/qgslayouttablecolumn.h *
204+
* *
205+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
206+
************************************************************************/

‎src/core/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ SET(QGIS_CORE_SRCS
398398
layout/qgslayoutpagecollection.cpp
399399
layout/qgslayoutserializableobject.cpp
400400
layout/qgslayoutsnapper.cpp
401+
layout/qgslayouttable.cpp
402+
layout/qgslayouttablecolumn.cpp
401403
layout/qgslayoutundocommand.cpp
402404
layout/qgslayoutundostack.cpp
403405
layout/qgslayoututils.cpp
@@ -757,6 +759,7 @@ SET(QGIS_CORE_MOC_HDRS
757759
layout/qgslayoutmultiframe.h
758760
layout/qgslayoutpagecollection.h
759761
layout/qgslayoutobject.h
762+
layout/qgslayouttable.h
760763
layout/qgslayoutundostack.h
761764

762765
symbology/qgscptcityarchive.h
@@ -1021,6 +1024,7 @@ SET(QGIS_CORE_HDRS
10211024
layout/qgslayoutserializableobject.h
10221025
layout/qgslayoutsize.h
10231026
layout/qgslayoutsnapper.h
1027+
layout/qgslayouttablecolumn.h
10241028
layout/qgslayoutundocommand.h
10251029
layout/qgslayoututils.h
10261030

‎src/core/layout/qgslayouttable.cpp

Lines changed: 1268 additions & 0 deletions
Large diffs are not rendered by default.

‎src/core/layout/qgslayouttable.h

Lines changed: 681 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/***************************************************************************
2+
QgsLayoutTableColumn.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 "qgslayouttablecolumn.h"
19+
#include "qgis.h"
20+
#include <memory>
21+
22+
QgsLayoutTableColumn::QgsLayoutTableColumn( const QString &heading )
23+
: mHeading( heading )
24+
{}
25+
26+
bool QgsLayoutTableColumn::writeXml( QDomElement &columnElem, QDomDocument &doc ) const
27+
{
28+
//background color
29+
QDomElement bgColorElem = doc.createElement( QStringLiteral( "backgroundColor" ) );
30+
bgColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mBackgroundColor.red() ) );
31+
bgColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mBackgroundColor.green() ) );
32+
bgColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mBackgroundColor.blue() ) );
33+
bgColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mBackgroundColor.alpha() ) );
34+
columnElem.appendChild( bgColorElem );
35+
36+
columnElem.setAttribute( QStringLiteral( "hAlignment" ), mHAlignment );
37+
columnElem.setAttribute( QStringLiteral( "vAlignment" ), mVAlignment );
38+
39+
columnElem.setAttribute( QStringLiteral( "heading" ), mHeading );
40+
columnElem.setAttribute( QStringLiteral( "attribute" ), mAttribute );
41+
42+
columnElem.setAttribute( QStringLiteral( "sortByRank" ), QString::number( mSortByRank ) );
43+
columnElem.setAttribute( QStringLiteral( "sortOrder" ), QString::number( mSortOrder ) );
44+
45+
columnElem.setAttribute( QStringLiteral( "width" ), QString::number( mWidth ) );
46+
47+
return true;
48+
}
49+
50+
bool QgsLayoutTableColumn::readXml( const QDomElement &columnElem )
51+
{
52+
mHAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "hAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
53+
mVAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "vAlignment" ), QString::number( Qt::AlignVCenter ) ).toInt() );
54+
mHeading = columnElem.attribute( QStringLiteral( "heading" ), QLatin1String( "" ) );
55+
mAttribute = columnElem.attribute( QStringLiteral( "attribute" ), QLatin1String( "" ) );
56+
mSortByRank = columnElem.attribute( QStringLiteral( "sortByRank" ), QStringLiteral( "0" ) ).toInt();
57+
mSortOrder = static_cast< Qt::SortOrder >( columnElem.attribute( QStringLiteral( "sortOrder" ), QString::number( Qt::AscendingOrder ) ).toInt() );
58+
mWidth = columnElem.attribute( QStringLiteral( "width" ), QStringLiteral( "0.0" ) ).toDouble();
59+
60+
QDomNodeList bgColorList = columnElem.elementsByTagName( QStringLiteral( "backgroundColor" ) );
61+
if ( !bgColorList.isEmpty() )
62+
{
63+
QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
64+
bool redOk, greenOk, blueOk, alphaOk;
65+
int bgRed, bgGreen, bgBlue, bgAlpha;
66+
bgRed = bgColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
67+
bgGreen = bgColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
68+
bgBlue = bgColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
69+
bgAlpha = bgColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
70+
if ( redOk && greenOk && blueOk && alphaOk )
71+
{
72+
mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
73+
}
74+
}
75+
76+
return true;
77+
}
78+
79+
QgsLayoutTableColumn *QgsLayoutTableColumn::clone()
80+
{
81+
std::unique_ptr< QgsLayoutTableColumn > newColumn = qgis::make_unique< QgsLayoutTableColumn >();
82+
newColumn->setAttribute( mAttribute );
83+
newColumn->setHeading( mHeading );
84+
newColumn->setHAlignment( mHAlignment );
85+
newColumn->setVAlignment( mVAlignment );
86+
newColumn->setSortByRank( mSortByRank );
87+
newColumn->setSortOrder( mSortOrder );
88+
newColumn->setWidth( mWidth );
89+
return newColumn.release();
90+
}
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/***************************************************************************
2+
QgsLayoutTableColumn.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 QGSLAYOUTTABLECOLUMN_H
19+
#define QGSLAYOUTTABLECOLUMN_H
20+
21+
#include <QObject>
22+
#include <QDomDocument>
23+
#include <QDomElement>
24+
#include <QColor>
25+
26+
#include "qgis_core.h"
27+
#include "qgis_sip.h"
28+
29+
/**
30+
* \ingroup core
31+
* Stores properties of a column for a QgsLayoutTable. Some properties of aQgsLayoutTableColumn
32+
* are applicable only in certain contexts. For instance, the attribute and setAttribute methods only
33+
* have an effect for QgsLayoutItemAttributeTables, and have no effect for QgsLayoutItemTextTables.
34+
* \since QGIS 3.0
35+
*/
36+
class CORE_EXPORT QgsLayoutTableColumn
37+
{
38+
public:
39+
40+
/**
41+
* Constructor for QgsLayoutTableColumn.
42+
* \param heading column heading
43+
*/
44+
QgsLayoutTableColumn( const QString &heading = QString() );
45+
46+
/**
47+
* Writes the column's properties to xml for storage.
48+
* \param columnElem an existing QDomElement in which to store the column's properties.
49+
* \param doc QDomDocument for the destination xml.
50+
* \see readXml()
51+
*/
52+
bool writeXml( QDomElement &columnElem, QDomDocument &doc ) const;
53+
54+
/**
55+
* Reads the column's properties from xml.
56+
* \param columnElem a QDomElement holding the column's desired properties.
57+
* \see writeXml()
58+
*/
59+
bool readXml( const QDomElement &columnElem );
60+
61+
/**
62+
* Returns the width for the column in mm,
63+
* or 0 if column width is automatically calculated.
64+
* \see setWidth()
65+
*/
66+
double width() const { return mWidth; }
67+
68+
/**
69+
* Sets the width for a column in mm. Set the \a width to 0 if the column width is to be automatically calculated.
70+
* \see width()
71+
*/
72+
void setWidth( const double width ) { mWidth = width; }
73+
74+
/**
75+
* Returns the heading for a column, which is the value displayed in the column's
76+
* header cell.
77+
* \see setHeading()
78+
*/
79+
QString heading() const { return mHeading; }
80+
81+
/**
82+
* Sets the \a heading for a column, which is the value displayed in the column's
83+
* header cell.
84+
* \see heading()
85+
*/
86+
void setHeading( const QString &heading ) { mHeading = heading; }
87+
88+
/**
89+
* Returns the horizontal alignment for a column, which controls the alignment
90+
* used for drawing column values within cells.
91+
* \see setHAlignment()
92+
* \see vAlignment()
93+
*/
94+
Qt::AlignmentFlag hAlignment() const { return mHAlignment; }
95+
96+
/**
97+
* Sets the horizontal \a alignment for a column, which controls the alignment
98+
* used for drawing column values within cells.
99+
* \see hAlignment()
100+
* \see setVAlignment()
101+
*/
102+
void setHAlignment( Qt::AlignmentFlag alignment ) { mHAlignment = alignment; }
103+
104+
/**
105+
* Returns the vertical alignment for a column, which controls the alignment
106+
* used for drawing column values within cells.
107+
* \see setVAlignment()
108+
* \see hAlignment()
109+
*/
110+
Qt::AlignmentFlag vAlignment() const { return mVAlignment; }
111+
112+
/**
113+
* Sets the vertical \a alignment for a column, which controls the alignment
114+
* used for drawing column values within cells.
115+
* \see vAlignment()
116+
* \see setHAlignment()
117+
*/
118+
void setVAlignment( Qt::AlignmentFlag alignment ) { mVAlignment = alignment; }
119+
120+
/**
121+
* Returns the attribute name or expression used for the column's values. This property
122+
* is only used when the column is part of a QgsLayoutItemAttributeTable.
123+
* \note only applicable when used in a QgsLayoutItemAttributeTable
124+
* \see setAttribute()
125+
*/
126+
QString attribute() const { return mAttribute; }
127+
128+
/**
129+
* Sets the \a attribute name or expression used for the column's values. This property
130+
* is only used when the column is part of a QgsLayoutItemAttributeTable.
131+
* \note only applicable when used in a QgsLayoutItemAttributeTable
132+
* \see attribute()
133+
*/
134+
void setAttribute( const QString &attribute ) { mAttribute = attribute; }
135+
136+
/**
137+
* Returns the sort order for the column. This property is only used when the column
138+
* is part of a QgsLayoutItemAttributeTable and when sortByRank is > 0.
139+
* \note only applicable when used in a QgsLayoutItemAttributeTable
140+
* \see setSortOrder()
141+
* \see sortByRank()
142+
*/
143+
Qt::SortOrder sortOrder() const { return mSortOrder; }
144+
145+
/**
146+
* Sets the sort \a order for the column. This property is only used when the column
147+
* is part of a QgsLayoutItemAttributeTable and when sortByRank() is > 0.
148+
* \note only applicable when used in a QgsLayoutItemAttributeTable
149+
* \see sortOrder()
150+
* \see setSortByRank()
151+
*/
152+
void setSortOrder( Qt::SortOrder order ) { mSortOrder = order; }
153+
154+
/**
155+
* Returns the sort rank for the column. If the sort rank is > 0 then the column
156+
* will be sorted in the table. The sort rank specifies the priority given to the
157+
* column when the table is sorted by multiple columns, with lower sort ranks
158+
* having higher priority. This property is only used when the column
159+
* is part of a QgsLayoutItemAttributeTable.
160+
*
161+
* If sort rank is <= 0 then the column is not being sorted.
162+
*
163+
* \note only applicable when used in a QgsLayoutItemAttributeTable
164+
* \see setSortByRank()
165+
* \see sortOrder()
166+
*/
167+
int sortByRank() const { return mSortByRank; }
168+
169+
/**
170+
* Sets the sort \a rank for the column. If the sort rank is > 0 then the column
171+
* will be sorted in the table. The sort rank specifies the priority given to the
172+
* column when the table is sorted by multiple columns, with lower sort ranks
173+
* having higher priority. This property is only used when the column
174+
* is part of a QgsComposerAttributeTable.
175+
* If the sort \a rank is <= 0 then the column is not being sorted.
176+
*
177+
* \note only applicable when used in a QgsLayoutItemAttributeTable
178+
* \see sortByRank()
179+
* \see setSortOrder()
180+
*/
181+
void setSortByRank( int rank ) { mSortByRank = rank; }
182+
183+
/**
184+
* Creates a duplicate column which is a deep copy of this column.
185+
* \returns a new QgsLayoutTableColumn with same properties as this column.
186+
*/
187+
QgsLayoutTableColumn *clone() SIP_FACTORY;
188+
189+
private:
190+
191+
QColor mBackgroundColor = Qt::transparent; //currently unused
192+
Qt::AlignmentFlag mHAlignment = Qt::AlignLeft;
193+
Qt::AlignmentFlag mVAlignment = Qt::AlignVCenter;
194+
QString mHeading;
195+
QString mAttribute;
196+
int mSortByRank = 0;
197+
Qt::SortOrder mSortOrder = Qt::AscendingOrder;
198+
double mWidth = 0.0;
199+
200+
};
201+
202+
#endif //QGSLAYOUTTABLECOLUMN_H

0 commit comments

Comments
 (0)
Please sign in to comment.