QGIS API Documentation  2.12.0-Lyon
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 #include "qgscomposerframe.h"
21 
23 {
24 
25 }
26 
28 {
29 
30 }
31 
33 {
34  //update existing column headings, or add new columns if required
35  QStringList::const_iterator labelIt = labels.constBegin();
36  int idx = 0;
37  for ( ; labelIt != labels.constEnd(); ++labelIt )
38  {
40  if ( idx < mColumns.count() )
41  {
42  col = mColumns.at( idx );
43  }
44  else
45  {
46  col = new QgsComposerTableColumn;
47  mColumns.append( col );
48  }
49  col->setHeading(( *labelIt ) );
50  idx++;
51  }
52 }
53 
55 {
56  QDomElement composerTableElem = doc.createElement( "ComposerTextTable" );
57  //todo: write headers and text entries
58  bool ok = _writeXML( composerTableElem, doc );
59  elem.appendChild( composerTableElem );
60  return ok;
61 }
62 
63 bool QgsComposerTextTable::readXML( const QDomElement& itemElem, const QDomDocument& doc )
64 {
65  //todo: read headers and text entries
66  return tableReadXML( itemElem, doc );
67 }
68 
70 {
71  attributeMaps.clear();
72 
74  QStringList currentStringList;
75  for ( ; rowIt != mRowText.constEnd(); ++rowIt )
76  {
77  currentStringList = *rowIt;
78 
79  attributeMaps.push_back( QgsAttributeMap() );
80  for ( int i = 0; i < currentStringList.size(); ++i )
81  {
82  attributeMaps.last().insert( i, QVariant( currentStringList.at( i ) ) );
83  }
84  }
85 
86  return true;
87 }
88 
89 
91  : QgsComposerTableV2( c, createUndoCommands )
92 {
93 
94 }
95 
97 {
98 
99 }
100 
102 {
103  mRowText.append( row );
105 }
106 
108 {
109  mRowText = contents;
111 }
112 
114 {
115  contents.clear();
116 
118  for ( ; rowIt != mRowText.constEnd(); ++rowIt )
119  {
120  QgsComposerTableRow currentRow;
121 
122  for ( int i = 0; i < mColumns.count(); ++i )
123  {
124  if ( i < ( *rowIt ).count() )
125  {
126  currentRow << ( *rowIt ).at( i );
127  }
128  else
129  {
130  currentRow << QString();
131  }
132  }
133  contents << currentRow;
134  }
135 
137  return true;
138 }
139 
140 void QgsComposerTextTableV2::addFrame( QgsComposerFrame* frame, bool recalcFrameSizes )
141 {
142  mFrameItems.push_back( frame );
143  connect( frame, SIGNAL( sizeChanged() ), this, SLOT( recalculateFrameSizes() ) );
144 
145  if ( mComposition )
146  {
147  //TODO - if QgsComposerTextTableV2 gains a UI, this will need a dedicated add method
148  //added to QgsComposition
149  mComposition->addItem( frame );
150  }
151 
152  if ( recalcFrameSizes )
153  {
155  }
156 }
void clear()
bool getTableContents(QgsComposerTableContents &contents) override
Fetches the contents used for the cells in the table.
QMap< int, QVariant > QgsAttributeMap
Definition: qgsfeature.h:104
QDomNode appendChild(const QDomNode &newChild)
void push_back(const T &value)
void setContents(const QList< QStringList > &contents)
Sets the contents of the text table.
const T & at(int i) const
void addRow(const QStringList &row)
Adds a row to the table.
void setHeaderLabels(const QStringList &labels)
Sets the text to use for the header row for the table.
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.
int size() const
A class to display feature attributes in the print composer.
int count(const T &value) const
void append(const T &value)
void setHeading(const QString &heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
QList< QgsComposerFrame * > mFrameItems
QgsComposerTextTable(QgsComposition *c)
virtual void addFrame(QgsComposerFrame *frame, bool recalcFrameSizes=true) override
Adds a frame to the multiframe.
A class to display a table in the print composer, and allow the table to span over multiple frames...
void recalculateFrameSizes() override
bool writeXML(QDomElement &elem, QDomDocument &doc) const override
Writes properties specific to text tables.
Stores properties of a column in a QgsComposerTable.
bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps) override
Queries the text table for text to show in the cells.
Graphics scene for map printing.
Frame item for a composer multiframe item.
QList< QgsComposerTableColumn * > mColumns
QgsComposition * mComposition
QgsComposerTableColumns mColumns
Columns to show in table.
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.
virtual void refreshAttributes()
Refreshes the contents shown in the table by querying for new data.
T & last()
QgsComposerTextTableV2(QgsComposition *c, bool createUndoCommands)
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
const_iterator constBegin() const
void addItem(QGraphicsItem *item)
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Reads the properties specific to a text table from xml.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QgsComposerTableContents * contents()
Returns the current contents of the table.