QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgslayouttablecolumn.cpp
Go to the documentation of this file.
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
19
20#include <memory>
21
22#include "qgis.h"
23
25 : mHeading( heading )
26{}
27
28bool QgsLayoutTableColumn::writeXml( QDomElement &columnElem, QDomDocument &doc ) const
29{
30 //background color
31 QDomElement bgColorElem = doc.createElement( QStringLiteral( "backgroundColor" ) );
32 bgColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mBackgroundColor.red() ) );
33 bgColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mBackgroundColor.green() ) );
34 bgColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mBackgroundColor.blue() ) );
35 bgColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mBackgroundColor.alpha() ) );
36 columnElem.appendChild( bgColorElem );
37
38 columnElem.setAttribute( QStringLiteral( "hAlignment" ), mHAlignment );
39 columnElem.setAttribute( QStringLiteral( "vAlignment" ), mVAlignment );
40
41 columnElem.setAttribute( QStringLiteral( "heading" ), mHeading );
42 columnElem.setAttribute( QStringLiteral( "attribute" ), mAttribute );
43
44 columnElem.setAttribute( QStringLiteral( "sortByRank" ), QString::number( mSortByRank ) );
45 columnElem.setAttribute( QStringLiteral( "sortOrder" ), QString::number( mSortOrder ) );
46
47 columnElem.setAttribute( QStringLiteral( "width" ), QString::number( mWidth ) );
48
49 return true;
50}
51
52bool QgsLayoutTableColumn::readXml( const QDomElement &columnElem )
53{
54 mHAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "hAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
55 mVAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "vAlignment" ), QString::number( Qt::AlignVCenter ) ).toInt() );
56 mHeading = columnElem.attribute( QStringLiteral( "heading" ), QString() );
57 mAttribute = columnElem.attribute( QStringLiteral( "attribute" ), QString() );
58 mSortByRank = columnElem.attribute( QStringLiteral( "sortByRank" ), QStringLiteral( "0" ) ).toInt();
59 mSortOrder = static_cast< Qt::SortOrder >( columnElem.attribute( QStringLiteral( "sortOrder" ), QString::number( Qt::AscendingOrder ) ).toInt() );
60 mWidth = columnElem.attribute( QStringLiteral( "width" ), QStringLiteral( "0.0" ) ).toDouble();
61
62 const QDomNodeList bgColorList = columnElem.elementsByTagName( QStringLiteral( "backgroundColor" ) );
63 if ( !bgColorList.isEmpty() )
64 {
65 const QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
66 bool redOk, greenOk, blueOk, alphaOk;
67 int bgRed, bgGreen, bgBlue, bgAlpha;
68 bgRed = bgColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
69 bgGreen = bgColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
70 bgBlue = bgColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
71 bgAlpha = bgColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
72 if ( redOk && greenOk && blueOk && alphaOk )
73 {
74 mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
75 }
76 }
77
78 return true;
79}
bool readXml(const QDomElement &columnElem)
Reads the column's properties from xml.
QString heading() const
Returns the heading for a column, which is the value displayed in the column's header cell.
bool writeXml(QDomElement &columnElem, QDomDocument &doc) const
Writes the column's properties to xml for storage.
QgsLayoutTableColumn(const QString &heading=QString())
Constructor for QgsLayoutTableColumn.