QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
34 {
35 
36 }
37 
39 {
40  //background color
41  QDomElement bgColorElem = doc.createElement( "backgroundColor" );
42  bgColorElem.setAttribute( "red", QString::number( mBackgroundColor.red() ) );
43  bgColorElem.setAttribute( "green", QString::number( mBackgroundColor.green() ) );
44  bgColorElem.setAttribute( "blue", QString::number( mBackgroundColor.blue() ) );
45  bgColorElem.setAttribute( "alpha", QString::number( mBackgroundColor.alpha() ) );
46  columnElem.appendChild( bgColorElem );
47 
48  columnElem.setAttribute( "hAlignment", mHAlignment );
49  columnElem.setAttribute( "vAlignment", mVAlignment );
50 
51  columnElem.setAttribute( "heading", mHeading );
52  columnElem.setAttribute( "attribute", mAttribute );
53 
54  columnElem.setAttribute( "sortByRank", QString::number( mSortByRank ) );
55  columnElem.setAttribute( "sortOrder", QString::number( mSortOrder ) );
56 
57  columnElem.setAttribute( "width", QString::number( mWidth ) );
58 
59  return true;
60 }
61 
63 {
64  mHAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( "hAlignment", QString::number( Qt::AlignLeft ) ).toInt() );
65  mVAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( "vAlignment", QString::number( Qt::AlignVCenter ) ).toInt() );
66  mHeading = columnElem.attribute( "heading", "" );
67  mAttribute = columnElem.attribute( "attribute", "" );
68  mSortByRank = columnElem.attribute( "sortByRank", "0" ).toInt();
69  mSortOrder = static_cast< Qt::SortOrder >( columnElem.attribute( "sortOrder", QString::number( Qt::AscendingOrder ) ).toInt() );
70  mWidth = columnElem.attribute( "width", "0.0" ).toDouble();
71 
72  QDomNodeList bgColorList = columnElem.elementsByTagName( "backgroundColor" );
73  if ( !bgColorList.isEmpty() )
74  {
75  QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
76  bool redOk, greenOk, blueOk, alphaOk;
77  int bgRed, bgGreen, bgBlue, bgAlpha;
78  bgRed = bgColorElem.attribute( "red" ).toDouble( &redOk );
79  bgGreen = bgColorElem.attribute( "green" ).toDouble( &greenOk );
80  bgBlue = bgColorElem.attribute( "blue" ).toDouble( &blueOk );
81  bgAlpha = bgColorElem.attribute( "alpha" ).toDouble( &alphaOk );
82  if ( redOk && greenOk && blueOk && alphaOk )
83  {
84  mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
85  }
86  }
87 
88  return true;
89 }
90 
92 {
94  newColumn->setAttribute( mAttribute );
95  newColumn->setHeading( mHeading );
96  newColumn->setHAlignment( mHAlignment );
97  newColumn->setVAlignment( mVAlignment );
98  newColumn->setSortByRank( mSortByRank );
99  newColumn->setSortOrder( mSortOrder );
100  newColumn->setWidth( mWidth );
101  return newColumn;
102 }
QDomNodeList elementsByTagName(const QString &tagname) const
void setAttribute(const QString &attribute)
Sets the attribute name or expression used for the column&#39;s values.
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const
virtual bool writeXML(QDomElement &columnElem, QDomDocument &doc) const
Writes the column&#39;s properties to xml for storage.
double toDouble(bool *ok) const
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...
QDomElement toElement() const
bool isEmpty() const
QString number(int n, int base)
void setHeading(const QString &heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
int red() const
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const
Stores properties of a column in a QgsComposerTable.
int alpha() const
int green() const
QgsComposerTableColumn(const QString &heading=QString())
Constructor for QgsComposerTableColumn.
int blue() const
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.
virtual bool readXML(const QDomElement &columnElem)
Reads the column&#39;s properties from xml.
QDomElement createElement(const QString &tagName)
void setSortByRank(int sortByRank)
Sets the sort rank for the column.
QDomNode at(int index) const