QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
18 #include "qgslayouttablecolumn.h"
19 #include "qgis.h"
20 #include <memory>
21 
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" ), QString() );
55  mAttribute = columnElem.attribute( QStringLiteral( "attribute" ), QString() );
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  const QDomNodeList bgColorList = columnElem.elementsByTagName( QStringLiteral( "backgroundColor" ) );
61  if ( !bgColorList.isEmpty() )
62  {
63  const 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 }
bool readXml(const QDomElement &columnElem)
Reads the column's properties from xml.
bool writeXml(QDomElement &columnElem, QDomDocument &doc) const
Writes the column's properties to xml for storage.
QgsLayoutTableColumn(const QString &heading=QString())
Constructor for QgsLayoutTableColumn.