QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposertablev2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposertablev2.h
3  ------------------
4  begin : July 2014
5  copyright : (C) 2014 by Nyall Dawson, Marco Hugentobler
6  email : nyall dot dawson at gmail dot com
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 QGSCOMPOSERTABLEV2_H
19 #define QGSCOMPOSERTABLEV2_H
20 
21 #include "qgscomposermultiframe.h"
22 #include <QFont>
23 #include <QColor>
24 #include <QPair>
25 
27 
32 typedef QList< QVariant > QgsComposerTableRow;
33 
38 typedef QList< QgsComposerTableRow > QgsComposerTableContents;
39 
43 typedef QList<QgsComposerTableColumn*> QgsComposerTableColumns;
44 
49 class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
50 {
51  Q_OBJECT
52 
53  public:
54 
58  {
62  HeaderRight
63  };
64 
68  {
69  FirstFrame = 0,
71  NoHeaders
72  };
73 
77  {
78  HeadersOnly = 0,
80  ShowMessage
81  };
82 
83  QgsComposerTableV2( QgsComposition* composition, bool createUndoCommands );
85 
86  virtual ~QgsComposerTableV2();
87 
92  void setCellMargin( const double margin );
93 
98  double cellMargin() const { return mCellMargin; }
99 
104  void setEmptyTableBehaviour( const EmptyTableMode mode );
105 
111  EmptyTableMode emptyTableBehaviour() const { return mEmptyTableMode; }
112 
120  void setEmptyTableMessage( const QString message );
121 
129  QString emptyTableMessage() const { return mEmptyTableMessage; }
130 
135  void setShowEmptyRows( const bool showEmpty );
136 
141  bool showEmptyRows() const { return mShowEmptyRows; }
142 
148  void setHeaderFont( const QFont& font );
149 
155  QFont headerFont() const { return mHeaderFont; }
156 
163  void setHeaderFontColor( const QColor& color );
164 
171  QColor headerFontColor() const { return mHeaderFontColor; }
172 
177  void setHeaderHAlignment( const HeaderHAlignment alignment );
178 
183  HeaderHAlignment headerHAlignment() const { return mHeaderHAlignment; }
184 
190  void setHeaderMode( const HeaderMode mode );
191 
197  HeaderMode headerMode() const { return mHeaderMode; }
198 
204  void setContentFont( const QFont& font );
205 
211  QFont contentFont() const { return mContentFont; }
212 
219  void setContentFontColor( const QColor& color );
220 
227  QColor contentFontColor() const { return mContentFontColor; }
228 
235  void setShowGrid( const bool showGrid );
236 
243  bool showGrid() const { return mShowGrid; }
244 
251  void setGridStrokeWidth( const double width );
252 
259  double gridStrokeWidth() const { return mGridStrokeWidth; }
260 
267  void setGridColor( const QColor& color );
268 
275  QColor gridColor() const { return mGridColor; }
276 
282  void setBackgroundColor( const QColor& color );
283 
289  QColor backgroundColor() const { return mBackgroundColor; }
290 
295  QgsComposerTableColumns* columns() { return &mColumns; }
296 
301  void setColumns( QgsComposerTableColumns columns );
302 
308  virtual QMap<int, QString> headerLabels() const;
309 
315  virtual bool getTableContents( QgsComposerTableContents &contents ) = 0;
316 
320  QgsComposerTableContents* contents() { return &mTableContents; }
321 
322  //reimplemented to return fixed table width
323  virtual QSizeF fixedFrameSize( const int frameIndex = -1 ) const;
324 
325  //reimplemented to return min frame height
326  virtual QSizeF minFrameSize( const int frameIndex = -1 ) const;
327 
328  virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
329  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
330  virtual QSizeF totalSize() const;
331  virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
332 
333  public slots:
334 
340  virtual void refreshAttributes();
341 
342  void recalculateFrameSizes();
343 
344  protected:
346  double mCellMargin;
347 
350 
353 
356 
358  QFont mHeaderFont;
359 
362 
365 
368 
371 
374 
376  bool mShowGrid;
377 
380 
382  QColor mGridColor;
383 
386 
389 
392 
394  QMap<int, double> mMaxColumnWidthMap;
395 
396  QSizeF mTableSize;
397 
400  virtual bool calculateMaxColumnWidths();
401 
406  //not const, as needs to call calculateMaxColumnWidths()
407  double totalWidth();
408 
413  double totalHeight() const;
414 
419  int rowsVisible( const int frameIndex ) const;
420 
427  int rowsVisible( const double frameHeight, const bool includeHeader ) const;
428 
435  QPair<int, int> rowRange( const QRectF extent, const int frameIndex ) const;
436 
443  void drawHorizontalGridLines( QPainter* painter, const int rows, const bool drawHeaderLines ) const;
444 
457  void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, const int numberRows, const bool hasHeader, const bool mergeCells = false ) const;
458 
461  void recalculateTableSize();
462 
468  bool contentsContainsRow( const QgsComposerTableContents &contents, const QgsComposerTableRow &row ) const;
469 
470  friend class TestQgsComposerTableV2;
471 };
472 
473 #endif // QGSCOMPOSERTABLEV2_H