QGIS API Documentation  2.8.2-Wien
 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  mWidth( 0.0 )
26 {
27 
28 }
29 
31 {
32 
33 }
34 
35 bool QgsComposerTableColumn::writeXML( QDomElement& columnElem, QDomDocument& doc ) const
36 {
37  //background color
38  QDomElement bgColorElem = doc.createElement( "backgroundColor" );
39  bgColorElem.setAttribute( "red", QString::number( mBackgroundColor.red() ) );
40  bgColorElem.setAttribute( "green", QString::number( mBackgroundColor.green() ) );
41  bgColorElem.setAttribute( "blue", QString::number( mBackgroundColor.blue() ) );
42  bgColorElem.setAttribute( "alpha", QString::number( mBackgroundColor.alpha() ) );
43  columnElem.appendChild( bgColorElem );
44 
45  columnElem.setAttribute( "hAlignment", mHAlignment );
46 
47  columnElem.setAttribute( "heading", mHeading );
48  columnElem.setAttribute( "attribute", mAttribute );
49 
50  columnElem.setAttribute( "sortByRank", QString::number( mSortByRank ) );
51  columnElem.setAttribute( "sortOrder", QString::number( mSortOrder ) );
52 
53  columnElem.setAttribute( "width", QString::number( mWidth ) );
54 
55  return true;
56 }
57 
58 bool QgsComposerTableColumn::readXML( const QDomElement& columnElem )
59 {
60  mHAlignment = ( Qt::AlignmentFlag )columnElem.attribute( "hAlignment", QString::number( Qt::AlignLeft ) ).toInt();
61  mHeading = columnElem.attribute( "heading", "" );
62  mAttribute = columnElem.attribute( "attribute", "" );
63  mSortByRank = columnElem.attribute( "sortByRank", "0" ).toInt();
64  mSortOrder = ( Qt::SortOrder )columnElem.attribute( "sortOrder", QString::number( Qt::AscendingOrder ) ).toInt();
65  mWidth = columnElem.attribute( "width", "0.0" ).toDouble();
66 
67  QDomNodeList bgColorList = columnElem.elementsByTagName( "backgroundColor" );
68  if ( bgColorList.size() > 0 )
69  {
70  QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
71  bool redOk, greenOk, blueOk, alphaOk;
72  int bgRed, bgGreen, bgBlue, bgAlpha;
73  bgRed = bgColorElem.attribute( "red" ).toDouble( &redOk );
74  bgGreen = bgColorElem.attribute( "green" ).toDouble( &greenOk );
75  bgBlue = bgColorElem.attribute( "blue" ).toDouble( &blueOk );
76  bgAlpha = bgColorElem.attribute( "alpha" ).toDouble( &alphaOk );
77  if ( redOk && greenOk && blueOk && alphaOk )
78  {
79  mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
80  }
81  }
82 
83  return true;
84 }
85 
87 {
89  newColumn->setAttribute( mAttribute );
90  newColumn->setHeading( mHeading );
91  newColumn->setHAlignment( mHAlignment );
92  newColumn->setSortByRank( mSortByRank );
93  newColumn->setSortOrder( mSortOrder );
94  newColumn->setWidth( mWidth );
95  return newColumn;
96 }