QGIS API Documentation  2.99.0-Master (ae4d26a)
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  , mHeading( heading )
23 {
24 
25 }
26 
27 bool QgsComposerTableColumn::writeXml( QDomElement &columnElem, QDomDocument &doc ) const
28 {
29  //background color
30  QDomElement bgColorElem = doc.createElement( QStringLiteral( "backgroundColor" ) );
31  bgColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mBackgroundColor.red() ) );
32  bgColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mBackgroundColor.green() ) );
33  bgColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mBackgroundColor.blue() ) );
34  bgColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mBackgroundColor.alpha() ) );
35  columnElem.appendChild( bgColorElem );
36 
37  columnElem.setAttribute( QStringLiteral( "hAlignment" ), mHAlignment );
38  columnElem.setAttribute( QStringLiteral( "vAlignment" ), mVAlignment );
39 
40  columnElem.setAttribute( QStringLiteral( "heading" ), mHeading );
41  columnElem.setAttribute( QStringLiteral( "attribute" ), mAttribute );
42 
43  columnElem.setAttribute( QStringLiteral( "sortByRank" ), QString::number( mSortByRank ) );
44  columnElem.setAttribute( QStringLiteral( "sortOrder" ), QString::number( mSortOrder ) );
45 
46  columnElem.setAttribute( QStringLiteral( "width" ), QString::number( mWidth ) );
47 
48  return true;
49 }
50 
51 bool QgsComposerTableColumn::readXml( const QDomElement &columnElem )
52 {
53  mHAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "hAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
54  mVAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "vAlignment" ), QString::number( Qt::AlignVCenter ) ).toInt() );
55  mHeading = columnElem.attribute( QStringLiteral( "heading" ), QLatin1String( "" ) );
56  mAttribute = columnElem.attribute( QStringLiteral( "attribute" ), QLatin1String( "" ) );
57  mSortByRank = columnElem.attribute( QStringLiteral( "sortByRank" ), QStringLiteral( "0" ) ).toInt();
58  mSortOrder = static_cast< Qt::SortOrder >( columnElem.attribute( QStringLiteral( "sortOrder" ), QString::number( Qt::AscendingOrder ) ).toInt() );
59  mWidth = columnElem.attribute( QStringLiteral( "width" ), QStringLiteral( "0.0" ) ).toDouble();
60 
61  QDomNodeList bgColorList = columnElem.elementsByTagName( QStringLiteral( "backgroundColor" ) );
62  if ( !bgColorList.isEmpty() )
63  {
64  QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
65  bool redOk, greenOk, blueOk, alphaOk;
66  int bgRed, bgGreen, bgBlue, bgAlpha;
67  bgRed = bgColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
68  bgGreen = bgColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
69  bgBlue = bgColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
70  bgAlpha = bgColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
71  if ( redOk && greenOk && blueOk && alphaOk )
72  {
73  mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
74  }
75  }
76 
77  return true;
78 }
79 
81 {
83  newColumn->setAttribute( mAttribute );
84  newColumn->setHeading( mHeading );
85  newColumn->setHAlignment( mHAlignment );
86  newColumn->setVAlignment( mVAlignment );
87  newColumn->setSortByRank( mSortByRank );
88  newColumn->setSortOrder( mSortOrder );
89  newColumn->setWidth( mWidth );
90  return newColumn;
91 }
void setAttribute(const QString &attribute)
Sets the attribute name or expression used for the column&#39;s values.
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.
virtual bool writeXml(QDomElement &columnElem, QDomDocument &doc) const
Writes the column&#39;s properties to xml for storage.
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.