QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
26 
27 
29 class CORE_EXPORT QgsComposerTable: public QgsComposerItem
30 {
31  public:
32  QgsComposerTable( QgsComposition* composition );
33  virtual ~QgsComposerTable();
34 
36  virtual int type() const { return ComposerTable; }
37 
39  virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
40 
41  virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const = 0;
42  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) = 0;
43 
44  void setLineTextDistance( double d ) { mLineTextDistance = d; }
45  double lineTextDistance() const { return mLineTextDistance; }
46 
47  void setHeaderFont( const QFont& f ) { mHeaderFont = f;}
48  QFont headerFont() const { return mHeaderFont; }
49 
50  void setContentFont( const QFont& f ) { mContentFont = f; }
51  QFont contentFont() const { return mContentFont; }
52 
53  void setShowGrid( bool show ) { mShowGrid = show;}
54  bool showGrid() const { return mShowGrid; }
55 
56  void setGridStrokeWidth( double w ) { mGridStrokeWidth = w; }
57  double gridStrokeWidth() const { return mGridStrokeWidth; }
58 
59  void setGridColor( const QColor& c ) { mGridColor = c; }
60  QColor gridColor() const { return mGridColor; }
61 
64  void adjustFrameToSize();
65 
66  protected:
69 
70  QFont mHeaderFont;
71  QFont mContentFont;
72 
73  bool mShowGrid;
75  QColor mGridColor;
76 
78 
79  virtual bool getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps ) { Q_UNUSED( attributeMaps ); return false; }
80  virtual QMap<int, QString> getHeaderLabels() const { return QMap<int, QString>(); } //= 0;
82  virtual bool calculateMaxColumnWidths( QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeMaps ) const;
84 
85  void adaptItemFrame( const QMap<int, double>& maxWidthMap, const QList<QgsAttributeMap>& attributeMaps );
86  void drawHorizontalGridLines( QPainter* p, int nAttributes );
88  void drawVerticalGridLines( QPainter* p, const QMap<int, double>& maxWidthMap );
89 
90  bool tableWriteXML( QDomElement& itemElem, QDomDocument& doc ) const;
91  bool tableReadXML( const QDomElement& itemElem, const QDomDocument& doc );
92 };
93 
94 #endif // QGSCOMPOSERTABLE_H