QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgscomposertable.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposertable.h
3  ------------------
4  begin : January 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 #ifndef QGSCOMPOSERTABLE_H
19 #define QGSCOMPOSERTABLE_H
20 
21 #include "qgscomposeritem.h"
22 #include "qgscomposition.h"
23 #include "qgsfeature.h"
24 #include <QSet>
25 #include <QObject>
26 
28 
30 class CORE_EXPORT QgsComposerTable: public QgsComposerItem
31 {
32  Q_OBJECT
33 
34  public:
35 
39  {
43  HeaderRight
44  };
45 
46  QgsComposerTable( QgsComposition* composition );
47  virtual ~QgsComposerTable();
48 
50  virtual int type() const { return ComposerTable; }
51 
53  virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
54 
55  virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const = 0;
56  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) = 0;
57 
62  void setLineTextDistance( double d );
63 
68  double lineTextDistance() const { return mLineTextDistance; }
69 
75  void setHeaderFont( const QFont& f );
76 
82  QFont headerFont() const { return mHeaderFont; }
83 
91  void setHeaderFontColor( const QColor& color );
92 
100  QColor headerFontColor() const { return mHeaderFontColor; }
101 
107  void setHeaderHAlignment( const HeaderHAlignment alignment );
108 
114  HeaderHAlignment headerHAlignment() const { return mHeaderHAlignment; }
115 
121  void setContentFont( const QFont& f );
122 
128  QFont contentFont() const { return mContentFont; }
129 
137  void setContentFontColor( const QColor& color );
138 
146  QColor contentFontColor() const { return mContentFontColor; }
147 
154  void setShowGrid( bool show );
155 
162  bool showGrid() const { return mShowGrid; }
163 
170  void setGridStrokeWidth( double w );
171 
178  double gridStrokeWidth() const { return mGridStrokeWidth; }
179 
186  void setGridColor( const QColor& c ) { mGridColor = c; }
187 
194  QColor gridColor() const { return mGridColor; }
195 
202  virtual QMap<int, QString> headerLabels() const;
203 
204  //TODO - make this more generic for next API break, eg rename as getRowValues, use QStringList rather than
205  //QgsAttributeMap
206 
212  virtual bool getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps ) { Q_UNUSED( attributeMaps ); return false; }
213 
219  QList<QgsComposerTableColumn*>* columns() { return &mColumns; }
220 
226  void setColumns( QList<QgsComposerTableColumn*> columns );
227 
228  public slots:
229 
236  virtual void refreshAttributes();
237 
245  virtual void adjustFrameToSize();
246 
247  protected:
250 
251  QFont mHeaderFont;
255 
257 
258  bool mShowGrid;
260  QColor mGridColor;
261 
262  QList<QgsAttributeMap> mAttributeMaps;
263  QMap<int, double> mMaxColumnWidthMap;
264 
265  QList<QgsComposerTableColumn*> mColumns;
266 
274  virtual bool calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeMaps ) const;
275 
283  void adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeMaps );
284 
290  void drawHorizontalGridLines( QPainter* p, int nAttributes );
291 
300  void drawVerticalGridLines( QPainter* p, const QMap<int, double>& maxWidthMap );
301 
308  bool tableWriteXML( QDomElement& itemElem, QDomDocument& doc ) const;
309 
316  bool tableReadXML( const QDomElement& itemElem, const QDomDocument& doc );
317 };
318 
319 #endif // QGSCOMPOSERTABLE_H
QColor gridColor() const
Returns the color used for grid lines in the table.
Definition: qgscomposertable.h:194
virtual int type() const
return correct graphics item type.
Definition: qgscomposertable.h:50
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
Definition: qgscomposerobject.cpp:61
bool mShowGrid
Definition: qgscomposertable.h:258
QColor headerFontColor() const
Returns the color used to draw header text in the table.
Definition: qgscomposertable.h:100
QColor mGridColor
Definition: qgscomposertable.h:260
Definition: qgscomposertable.h:40
HeaderHAlignment
Definition: qgscomposertable.h:38
double mGridStrokeWidth
Definition: qgscomposertable.h:259
QColor mHeaderFontColor
Definition: qgscomposertable.h:252
A item that forms part of a map composition.
Definition: qgscomposeritem.h:38
HeaderHAlignment mHeaderHAlignment
Definition: qgscomposertable.h:256
Definition: qgscomposertable.h:42
QList< QgsComposerTableColumn * > * columns()
Returns a pointer to the list of QgsComposerTableColumns shown in the table.
Definition: qgscomposertable.h:219
void setGridColor(const QColor &c)
Sets color used for grid lines in the table.
Definition: qgscomposertable.h:186
A class to display feature attributes in the print composer.
Definition: qgscomposertable.h:30
QFont mContentFont
Definition: qgscomposertable.h:253
QFont headerFont() const
Returns the font used to draw header text in the table.
Definition: qgscomposertable.h:82
QColor mContentFontColor
Definition: qgscomposertable.h:254
bool showGrid() const
Returns whether grid lines are drawn in the table.
Definition: qgscomposertable.h:162
Stores properties of a column in a QgsComposerTable.
Definition: qgscomposertablecolumn.h:27
Graphics scene for map printing.
Definition: qgscomposition.h:73
virtual bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps)
Fetches the text used for the rows of the table.
Definition: qgscomposertable.h:212
QList< QgsComposerTableColumn * > mColumns
Definition: qgscomposertable.h:265
Definition: qgscomposeritem.h:58
HeaderHAlignment headerHAlignment() const
Returns the horizontal alignment for table headers.
Definition: qgscomposertable.h:114
QFont contentFont() const
Returns the font used to draw text in table body cells.
Definition: qgscomposertable.h:128
QList< QgsAttributeMap > mAttributeMaps
Definition: qgscomposertable.h:262
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
Definition: qgscomposerobject.cpp:74
Definition: qgscomposertable.h:41
double mLineTextDistance
Distance between table lines and text.
Definition: qgscomposertable.h:249
QColor contentFontColor() const
Returns the color used to draw text in table body cells.
Definition: qgscomposertable.h:146
QMap< int, double > mMaxColumnWidthMap
Definition: qgscomposertable.h:263
QFont mHeaderFont
Definition: qgscomposertable.h:251
double gridStrokeWidth() const
Returns the width of grid lines in the table.
Definition: qgscomposertable.h:178
double lineTextDistance() const
Returns the margin distance between cell borders and their contents.
Definition: qgscomposertable.h:68