QGIS API Documentation  2.17.0-Master (0497e4a)
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 
33 //TODO QGIS 3.0 -remove
34 class CORE_EXPORT QgsComposerTable: public QgsComposerItem
35 {
36  Q_OBJECT
37 
38  public:
39 
43  {
47  HeaderRight
48  };
49 
50  QgsComposerTable( QgsComposition* composition );
51  virtual ~QgsComposerTable();
52 
54  virtual int type() const override { return ComposerTable; }
55 
57  virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
58 
59  virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const override = 0;
60  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override = 0;
61 
66  void setLineTextDistance( double d );
67 
72  double lineTextDistance() const { return mLineTextDistance; }
73 
79  void setHeaderFont( const QFont& f );
80 
86  QFont headerFont() const { return mHeaderFont; }
87 
95  void setHeaderFontColor( const QColor& color );
96 
104  QColor headerFontColor() const { return mHeaderFontColor; }
105 
111  void setHeaderHAlignment( const HeaderHAlignment alignment );
112 
118  HeaderHAlignment headerHAlignment() const { return mHeaderHAlignment; }
119 
125  void setContentFont( const QFont& f );
126 
132  QFont contentFont() const { return mContentFont; }
133 
141  void setContentFontColor( const QColor& color );
142 
150  QColor contentFontColor() const { return mContentFontColor; }
151 
158  void setShowGrid( bool show );
159 
166  bool showGrid() const { return mShowGrid; }
167 
174  void setGridStrokeWidth( double w );
175 
182  double gridStrokeWidth() const { return mGridStrokeWidth; }
183 
190  void setGridColor( const QColor& c ) { mGridColor = c; }
191 
198  QColor gridColor() const { return mGridColor; }
199 
206  virtual QMap<int, QString> headerLabels() const;
207 
208  //TODO - make this more generic for next API break, eg rename as getRowValues, use QStringList rather than
209  //QgsAttributeMap
210 
216  virtual bool getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps ) { Q_UNUSED( attributeMaps ); return false; }
217 
223  QList<QgsComposerTableColumn*>* columns() { return &mColumns; }
224 
230  void setColumns( const QList<QgsComposerTableColumn*>& columns );
231 
232  public slots:
233 
240  virtual void refreshAttributes();
241 
249  virtual void adjustFrameToSize();
250 
251  protected:
254 
259 
261 
262  bool mShowGrid;
265 
268 
270 
278  virtual bool calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeMaps ) const;
279 
287  void adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeMaps );
288 
294  void drawHorizontalGridLines( QPainter* p, int nAttributes );
295 
304  void drawVerticalGridLines( QPainter* p, const QMap<int, double>& maxWidthMap );
305 
312  bool tableWriteXML( QDomElement& itemElem, QDomDocument& doc ) const;
313 
320  bool tableReadXML( const QDomElement& itemElem, const QDomDocument& doc );
321 };
322 
323 #endif // QGSCOMPOSERTABLE_H
QColor headerFontColor() const
Returns the color used to draw header text in the table.
QFont contentFont() const
Returns the font used to draw text in table body cells.
HeaderHAlignment
Controls how headers are horizontally aligned in a table.
QColor contentFontColor() const
Returns the color used to draw text in table body cells.
A item that forms part of a map composition.
bool showGrid() const
Returns whether grid lines are drawn in the table.
HeaderHAlignment mHeaderHAlignment
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
QList< QgsComposerTableColumn * > * columns()
Returns a pointer to the list of QgsComposerTableColumns shown in the table.
QColor gridColor() const
Returns the color used for grid lines in the table.
void setGridColor(const QColor &c)
Sets color used for grid lines in the table.
A class to display feature attributes in the print composer.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
virtual int type() const override
Return correct graphics item type.
HeaderHAlignment headerHAlignment() const
Returns the horizontal alignment for table headers.
Stores properties of a column in a QgsComposerTable.
Graphics scene for map printing.
virtual bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps)
Fetches the text used for the rows of the table.
QList< QgsComposerTableColumn * > mColumns
double lineTextDistance() const
Returns the margin distance between cell borders and their contents.
double gridStrokeWidth() const
Returns the width of grid lines in the table.
QList< QgsAttributeMap > mAttributeMaps
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
double mLineTextDistance
Distance between table lines and text.
QMap< int, double > mMaxColumnWidthMap
QFont headerFont() const
Returns the font used to draw header text in the table.