QGIS API Documentation  2.99.0-Master (08c2e66)
qgscomposertablecolumn.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposertablecolumn.cpp
3  --------------------------
4  begin : May 2014
5  copyright : (C) 2014 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 "qgscomposertablecolumn.h"
19 
21  : mBackgroundColor( Qt::transparent )
22  , mHAlignment( Qt::AlignLeft )
23  , mVAlignment( Qt::AlignVCenter )
24  , mHeading( heading )
25  , mSortByRank( 0 )
26  , mSortOrder( Qt::AscendingOrder )
27  , mWidth( 0.0 )
28 {
29 
30 }
31 
32 bool QgsComposerTableColumn::writeXml( QDomElement& columnElem, QDomDocument& doc ) const
33 {
34  //background color
35  QDomElement bgColorElem = doc.createElement( QStringLiteral( "backgroundColor" ) );
36  bgColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mBackgroundColor.red() ) );
37  bgColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mBackgroundColor.green() ) );
38  bgColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mBackgroundColor.blue() ) );
39  bgColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mBackgroundColor.alpha() ) );
40  columnElem.appendChild( bgColorElem );
41 
42  columnElem.setAttribute( QStringLiteral( "hAlignment" ), mHAlignment );
43  columnElem.setAttribute( QStringLiteral( "vAlignment" ), mVAlignment );
44 
45  columnElem.setAttribute( QStringLiteral( "heading" ), mHeading );
46  columnElem.setAttribute( QStringLiteral( "attribute" ), mAttribute );
47 
48  columnElem.setAttribute( QStringLiteral( "sortByRank" ), QString::number( mSortByRank ) );
49  columnElem.setAttribute( QStringLiteral( "sortOrder" ), QString::number( mSortOrder ) );
50 
51  columnElem.setAttribute( QStringLiteral( "width" ), QString::number( mWidth ) );
52 
53  return true;
54 }
55 
56 bool QgsComposerTableColumn::readXml( const QDomElement& columnElem )
57 {
58  mHAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "hAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
59  mVAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "vAlignment" ), QString::number( Qt::AlignVCenter ) ).toInt() );
60  mHeading = columnElem.attribute( QStringLiteral( "heading" ), QLatin1String( "" ) );
61  mAttribute = columnElem.attribute( QStringLiteral( "attribute" ), QLatin1String( "" ) );
62  mSortByRank = columnElem.attribute( QStringLiteral( "sortByRank" ), QStringLiteral( "0" ) ).toInt();
63  mSortOrder = static_cast< Qt::SortOrder >( columnElem.attribute( QStringLiteral( "sortOrder" ), QString::number( Qt::AscendingOrder ) ).toInt() );
64  mWidth = columnElem.attribute( QStringLiteral( "width" ), QStringLiteral( "0.0" ) ).toDouble();
65 
66  QDomNodeList bgColorList = columnElem.elementsByTagName( QStringLiteral( "backgroundColor" ) );
67  if ( !bgColorList.isEmpty() )
68  {
69  QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
70  bool redOk, greenOk, blueOk, alphaOk;
71  int bgRed, bgGreen, bgBlue, bgAlpha;
72  bgRed = bgColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
73  bgGreen = bgColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
74  bgBlue = bgColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
75  bgAlpha = bgColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
76  if ( redOk && greenOk && blueOk && alphaOk )
77  {
78  mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
79  }
80  }
81 
82  return true;
83 }
84 
86 {
88  newColumn->setAttribute( mAttribute );
89  newColumn->setHeading( mHeading );
90  newColumn->setHAlignment( mHAlignment );
91  newColumn->setVAlignment( mVAlignment );
92  newColumn->setSortByRank( mSortByRank );
93  newColumn->setSortOrder( mSortOrder );
94  newColumn->setWidth( mWidth );
95  return newColumn;
96 }
void setAttribute(const QString &attribute)
Sets the attribute name or expression used for the column&#39;s values.
virtual bool writeXml(QDomElement &columnElem, QDomDocument &doc) const
Writes the column&#39;s properties to xml for storage.
QgsComposerTableColumn * clone()
Creates a duplicate column which is a deep copy of this column.
void setHAlignment(Qt::AlignmentFlag alignment)
Sets the horizontal alignment for a column, which controls the alignment used for drawing column valu...
virtual bool readXml(const QDomElement &columnElem)
Reads the column&#39;s properties from xml.
void setHeading(const QString &heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
Stores properties of a column in a QgsComposerTable.
QgsComposerTableColumn(const QString &heading=QString())
Constructor for QgsComposerTableColumn.
void setSortOrder(Qt::SortOrder sortOrder)
Sets the sort order for the column.
void setVAlignment(Qt::AlignmentFlag alignment)
Sets the vertical alignment for a column, which controls the alignment used for drawing column values...
void setWidth(const double width)
Sets the width for a column.
void setSortByRank(int sortByRank)
Sets the sort rank for the column.