QGIS API Documentation  2.15.0-Master (972fc9f)
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 
32 //TODO QGIS 3.0 -remove
33 class CORE_EXPORT QgsComposerTable: public QgsComposerItem
34 {
35  Q_OBJECT
36 
37  public:
38 
42  {
46  HeaderRight
47  };
48 
49  QgsComposerTable( QgsComposition* composition );
50  virtual ~QgsComposerTable();
51 
53  virtual int type() const override { return ComposerTable; }
54 
56  virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
57 
58  virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const override = 0;
59  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override = 0;
60 
65  void setLineTextDistance( double d );
66 
71  double lineTextDistance() const { return mLineTextDistance; }
72 
78  void setHeaderFont( const QFont& f );
79 
85  QFont headerFont() const { return mHeaderFont; }
86 
94  void setHeaderFontColor( const QColor& color );
95 
103  QColor headerFontColor() const { return mHeaderFontColor; }
104 
110  void setHeaderHAlignment( const HeaderHAlignment alignment );
111 
117  HeaderHAlignment headerHAlignment() const { return mHeaderHAlignment; }
118 
124  void setContentFont( const QFont& f );
125 
131  QFont contentFont() const { return mContentFont; }
132 
140  void setContentFontColor( const QColor& color );
141 
149  QColor contentFontColor() const { return mContentFontColor; }
150 
157  void setShowGrid( bool show );
158 
165  bool showGrid() const { return mShowGrid; }
166 
173  void setGridStrokeWidth( double w );
174 
181  double gridStrokeWidth() const { return mGridStrokeWidth; }
182 
189  void setGridColor( const QColor& c ) { mGridColor = c; }
190 
197  QColor gridColor() const { return mGridColor; }
198 
205  virtual QMap<int, QString> headerLabels() const;
206 
207  //TODO - make this more generic for next API break, eg rename as getRowValues, use QStringList rather than
208  //QgsAttributeMap
209 
215  virtual bool getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps ) { Q_UNUSED( attributeMaps ); return false; }
216 
222  QList<QgsComposerTableColumn*>* columns() { return &mColumns; }
223 
229  void setColumns( const QList<QgsComposerTableColumn*>& columns );
230 
231  public slots:
232 
239  virtual void refreshAttributes();
240 
248  virtual void adjustFrameToSize();
249 
250  protected:
253 
258 
260 
261  bool mShowGrid;
264 
267 
269 
277  virtual bool calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeMaps ) const;
278 
286  void adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeMaps );
287 
293  void drawHorizontalGridLines( QPainter* p, int nAttributes );
294 
303  void drawVerticalGridLines( QPainter* p, const QMap<int, double>& maxWidthMap );
304 
311  bool tableWriteXML( QDomElement& itemElem, QDomDocument& doc ) const;
312 
319  bool tableReadXML( const QDomElement& itemElem, const QDomDocument& doc );
320 };
321 
322 #endif // QGSCOMPOSERTABLE_H
QColor gridColor() const
Returns the color used for grid lines in the table.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
QColor headerFontColor() const
Returns the color used to draw header text in the table.
HeaderHAlignment
Controls how headers are horizontally aligned in a table.
A item that forms part of a map composition.
HeaderHAlignment mHeaderHAlignment
QList< QgsComposerTableColumn * > * columns()
Returns a pointer to the list of QgsComposerTableColumns shown 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.
QFont headerFont() const
Returns the font used to draw header text in the table.
bool showGrid() const
Returns whether grid lines are drawn in the table.
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
HeaderHAlignment headerHAlignment() const
Returns the horizontal alignment for table headers.
QFont contentFont() const
Returns the font used to draw text in table body cells.
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.
QColor contentFontColor() const
Returns the color used to draw text in table body cells.
QMap< int, double > mMaxColumnWidthMap
double gridStrokeWidth() const
Returns the width of grid lines in the table.
double lineTextDistance() const
Returns the margin distance between cell borders and their contents.