QGIS API Documentation  2.4.0-Chugiak
 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  mSortByRank( 0 ),
24  mSortOrder( Qt::AscendingOrder )
25 {
26 
27 }
28 
30 {
31 
32 }
33 
34 bool QgsComposerTableColumn::writeXML( QDomElement& columnElem, QDomDocument& doc ) const
35 {
36  //background color
37  QDomElement bgColorElem = doc.createElement( "backgroundColor" );
38  bgColorElem.setAttribute( "red", QString::number( mBackgroundColor.red() ) );
39  bgColorElem.setAttribute( "green", QString::number( mBackgroundColor.green() ) );
40  bgColorElem.setAttribute( "blue", QString::number( mBackgroundColor.blue() ) );
41  bgColorElem.setAttribute( "alpha", QString::number( mBackgroundColor.alpha() ) );
42  columnElem.appendChild( bgColorElem );
43 
44  columnElem.setAttribute( "hAlignment", mHAlignment );
45 
46  columnElem.setAttribute( "heading", mHeading );
47  columnElem.setAttribute( "attribute", mAttribute );
48 
49  columnElem.setAttribute( "sortByRank", QString::number( mSortByRank ) );
50  columnElem.setAttribute( "sortOrder", QString::number( mSortOrder ) );
51 
52  return true;
53 }
54 
55 bool QgsComposerTableColumn::readXML( const QDomElement& columnElem )
56 {
57  mHAlignment = ( Qt::AlignmentFlag )columnElem.attribute( "hAlignment", QString::number( Qt::AlignLeft ) ).toInt();
58  mHeading = columnElem.attribute( "heading", "" );
59  mAttribute = columnElem.attribute( "attribute", "" );
60  mSortByRank = columnElem.attribute( "sortByRank", "0" ).toInt();
61  mSortOrder = ( Qt::SortOrder )columnElem.attribute( "sortOrder", QString::number( Qt::AscendingOrder ) ).toInt();
62 
63  QDomNodeList bgColorList = columnElem.elementsByTagName( "backgroundColor" );
64  if ( bgColorList.size() > 0 )
65  {
66  QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
67  bool redOk, greenOk, blueOk, alphaOk;
68  int bgRed, bgGreen, bgBlue, bgAlpha;
69  bgRed = bgColorElem.attribute( "red" ).toDouble( &redOk );
70  bgGreen = bgColorElem.attribute( "green" ).toDouble( &greenOk );
71  bgBlue = bgColorElem.attribute( "blue" ).toDouble( &blueOk );
72  bgAlpha = bgColorElem.attribute( "alpha" ).toDouble( &alphaOk );
73  if ( redOk && greenOk && blueOk && alphaOk )
74  {
75  mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
76  }
77  }
78 
79  return true;
80 }
81 
83 {
85  newColumn->setAttribute( mAttribute );
86  newColumn->setHeading( mHeading );
87  newColumn->setHAlignment( mHAlignment );
88  newColumn->setSortByRank( mSortByRank );
89  newColumn->setSortOrder( mSortOrder );
90  return newColumn;
91 }
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.
void setHeading(QString heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
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...
Stores properties of a column in a QgsComposerTable.
void setSortOrder(Qt::SortOrder sortOrder)
Sets the sort order for the column.
virtual bool readXML(const QDomElement &columnElem)
Reads the column's properties from xml.
void setSortByRank(int sortByRank)
Sets the sort rank for the column.