QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  mHeading( heading ),
24  mSortByRank( 0 ),
25  mSortOrder( Qt::AscendingOrder ),
26  mWidth( 0.0 )
27 {
28 
29 }
30 
31 
33 {
34 
35 }
36 
38 {
39  //background color
40  QDomElement bgColorElem = doc.createElement( "backgroundColor" );
41  bgColorElem.setAttribute( "red", QString::number( mBackgroundColor.red() ) );
42  bgColorElem.setAttribute( "green", QString::number( mBackgroundColor.green() ) );
43  bgColorElem.setAttribute( "blue", QString::number( mBackgroundColor.blue() ) );
44  bgColorElem.setAttribute( "alpha", QString::number( mBackgroundColor.alpha() ) );
45  columnElem.appendChild( bgColorElem );
46 
47  columnElem.setAttribute( "hAlignment", mHAlignment );
48 
49  columnElem.setAttribute( "heading", mHeading );
50  columnElem.setAttribute( "attribute", mAttribute );
51 
52  columnElem.setAttribute( "sortByRank", QString::number( mSortByRank ) );
53  columnElem.setAttribute( "sortOrder", QString::number( mSortOrder ) );
54 
55  columnElem.setAttribute( "width", QString::number( mWidth ) );
56 
57  return true;
58 }
59 
61 {
62  mHAlignment = ( Qt::AlignmentFlag )columnElem.attribute( "hAlignment", QString::number( Qt::AlignLeft ) ).toInt();
63  mHeading = columnElem.attribute( "heading", "" );
64  mAttribute = columnElem.attribute( "attribute", "" );
65  mSortByRank = columnElem.attribute( "sortByRank", "0" ).toInt();
66  mSortOrder = ( Qt::SortOrder )columnElem.attribute( "sortOrder", QString::number( Qt::AscendingOrder ) ).toInt();
67  mWidth = columnElem.attribute( "width", "0.0" ).toDouble();
68 
69  QDomNodeList bgColorList = columnElem.elementsByTagName( "backgroundColor" );
70  if ( bgColorList.size() > 0 )
71  {
72  QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
73  bool redOk, greenOk, blueOk, alphaOk;
74  int bgRed, bgGreen, bgBlue, bgAlpha;
75  bgRed = bgColorElem.attribute( "red" ).toDouble( &redOk );
76  bgGreen = bgColorElem.attribute( "green" ).toDouble( &greenOk );
77  bgBlue = bgColorElem.attribute( "blue" ).toDouble( &blueOk );
78  bgAlpha = bgColorElem.attribute( "alpha" ).toDouble( &alphaOk );
79  if ( redOk && greenOk && blueOk && alphaOk )
80  {
81  mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
82  }
83  }
84 
85  return true;
86 }
87 
89 {
91  newColumn->setAttribute( mAttribute );
92  newColumn->setHeading( mHeading );
93  newColumn->setHAlignment( mHAlignment );
94  newColumn->setSortByRank( mSortByRank );
95  newColumn->setSortOrder( mSortOrder );
96  newColumn->setWidth( mWidth );
97  return newColumn;
98 }
QDomNodeList elementsByTagName(const QString &tagname) const
virtual bool writeXML(QDomElement &columnElem, QDomDocument &doc) const
Writes the column's properties to xml for storage.
void setAttribute(QString attribute)
Sets the attribute name or expression used for the column's values.
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const
void setHeading(QString heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
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
QString number(int n, int base)
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 setWidth(const double width)
Sets the width for a column.
virtual bool readXML(const QDomElement &columnElem)
Reads the column's properties from xml.
int size() const
QDomElement createElement(const QString &tagName)
void setSortByRank(int sortByRank)
Sets the sort rank for the column.
QDomNode at(int index) const