QGIS API Documentation  2.4.0-Chugiak
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposertexttable.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposertexttable.h
3  ----------------------
4  begin : April 2010
5  copyright : (C) 2010 by Marco Hugentobler
6  email : marco at hugis dot net
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 "qgscomposertexttable.h"
19 #include "qgscomposertablecolumn.h"
20 
22 {
23 
24 }
25 
27 {
28 
29 }
30 
31 void QgsComposerTextTable::setHeaderLabels( const QStringList& labels )
32 {
33  //update existing column headings, or add new columns if required
34  QStringList::const_iterator labelIt = labels.constBegin();
35  int idx = 0;
36  for ( ; labelIt != labels.constEnd(); ++labelIt )
37  {
39  if ( idx < mColumns.count() )
40  {
41  col = mColumns.at( idx );
42  }
43  else
44  {
45  col = new QgsComposerTableColumn;
46  mColumns.append( col );
47  }
48  col->setHeading(( *labelIt ) );
49  idx++;
50  }
51 }
52 
53 bool QgsComposerTextTable::writeXML( QDomElement& elem, QDomDocument & doc ) const
54 {
55  QDomElement composerTableElem = doc.createElement( "ComposerTextTable" );
56  //todo: write headers and text entries
57  bool ok = _writeXML( composerTableElem , doc );
58  elem.appendChild( composerTableElem );
59  return ok;
60 }
61 
62 bool QgsComposerTextTable::readXML( const QDomElement& itemElem, const QDomDocument& doc )
63 {
64  //todo: read headers and text entries
65  return tableReadXML( itemElem, doc );
66 }
67 
68 bool QgsComposerTextTable::getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps )
69 {
70  attributeMaps.clear();
71 
72  QList< QStringList >::const_iterator rowIt = mRowText.constBegin();
73  QStringList currentStringList;
74  for ( ; rowIt != mRowText.constEnd(); ++rowIt )
75  {
76  currentStringList = *rowIt;
77 
78  attributeMaps.push_back( QgsAttributeMap() );
79  for ( int i = 0; i < currentStringList.size(); ++i )
80  {
81  attributeMaps.last().insert( i, QVariant( currentStringList.at( i ) ) );
82  }
83  }
84 
85  return true;
86 }
QList< QStringList > mRowText
One stringlist per row.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads the properties specific to a text table from xml.
QMap< int, QVariant > QgsAttributeMap
Definition: qgsfeature.h:98
bool writeXML(QDomElement &elem, QDomDocument &doc) const
Writes properties specific to text tables.
void setHeaderLabels(const QStringList &labels)
Sets the text to use for the header row for the table.
void setHeading(QString heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
A class to display feature attributes in the print composer.
QgsComposerTextTable(QgsComposition *c)
Stores properties of a column in a QgsComposerTable.
Graphics scene for map printing.
QList< QgsComposerTableColumn * > mColumns
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
bool tableReadXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads the table's common properties from xml.
bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps)
Queries the text table for text to show in the cells.