QGIS API Documentation  2.14.0-Essen
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 
33 
39 
44 
45 
52 class CORE_EXPORT QgsComposerTableStyle
53 {
54  public:
55 
57  : enabled( false )
58  , cellBackgroundColor( QColor( 255, 255, 255, 255 ) )
59  {}
60 
62  bool enabled;
63 
66 
72  bool writeXML( QDomElement& styleElem, QDomDocument & doc ) const;
73 
78  bool readXML( const QDomElement& styleElem );
79 
80 };
81 
87 class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
88 {
89  Q_OBJECT
90 
91  public:
92 
96  {
100  HeaderRight
101  };
102 
106  {
107  FirstFrame = 0,
109  NoHeaders
110  };
111 
115  {
116  HeadersOnly = 0,
118  ShowMessage
119  };
120 
124  {
125  TruncateText = 0,
126  WrapText
127  };
128 
132  {
141  LastRow
142  };
143 
144  QgsComposerTableV2( QgsComposition* composition, bool createUndoCommands );
146 
147  virtual ~QgsComposerTableV2();
148 
153  void setCellMargin( const double margin );
154 
159  double cellMargin() const { return mCellMargin; }
160 
165  void setEmptyTableBehaviour( const EmptyTableMode mode );
166 
172  EmptyTableMode emptyTableBehaviour() const { return mEmptyTableMode; }
173 
181  void setEmptyTableMessage( const QString& message );
182 
190  QString emptyTableMessage() const { return mEmptyTableMessage; }
191 
196  void setShowEmptyRows( const bool showEmpty );
197 
202  bool showEmptyRows() const { return mShowEmptyRows; }
203 
209  void setHeaderFont( const QFont& font );
210 
216  QFont headerFont() const { return mHeaderFont; }
217 
224  void setHeaderFontColor( const QColor& color );
225 
232  QColor headerFontColor() const { return mHeaderFontColor; }
233 
238  void setHeaderHAlignment( const HeaderHAlignment alignment );
239 
244  HeaderHAlignment headerHAlignment() const { return mHeaderHAlignment; }
245 
251  void setHeaderMode( const HeaderMode mode );
252 
258  HeaderMode headerMode() const { return mHeaderMode; }
259 
265  void setContentFont( const QFont& font );
266 
272  QFont contentFont() const { return mContentFont; }
273 
280  void setContentFontColor( const QColor& color );
281 
288  QColor contentFontColor() const { return mContentFontColor; }
289 
296  void setShowGrid( const bool showGrid );
297 
304  bool showGrid() const { return mShowGrid; }
305 
312  void setGridStrokeWidth( const double width );
313 
320  double gridStrokeWidth() const { return mGridStrokeWidth; }
321 
328  void setGridColor( const QColor& color );
329 
336  QColor gridColor() const { return mGridColor; }
337 
343  void setBackgroundColor( const QColor& color );
344 
350  QColor backgroundColor() const { return mBackgroundColor; }
351 
358  void setWrapBehaviour( WrapBehaviour behaviour );
359 
366  WrapBehaviour wrapBehaviour() const { return mWrapBehaviour; }
367 
372  QgsComposerTableColumns* columns() { return &mColumns; }
373 
378  void setColumns( const QgsComposerTableColumns& columns );
379 
386  void setCellStyle( CellStyleGroup group, const QgsComposerTableStyle& style );
387 
393  const QgsComposerTableStyle* cellStyle( CellStyleGroup group ) const;
394 
400  virtual QMap<int, QString> headerLabels() const;
401 
407  virtual bool getTableContents( QgsComposerTableContents &contents ) = 0;
408 
412  QgsComposerTableContents* contents() { return &mTableContents; }
413 
414  //reimplemented to return fixed table width
415  virtual QSizeF fixedFrameSize( const int frameIndex = -1 ) const override;
416 
417  //reimplemented to return min frame height
418  virtual QSizeF minFrameSize( const int frameIndex = -1 ) const override;
419 
420  virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const override;
421  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false ) override;
422  virtual QSizeF totalSize() const override;
423  virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex ) override;
424 
425  public slots:
426 
432  virtual void refreshAttributes();
433 
434  void recalculateFrameSizes() override;
435 
436  protected:
438  double mCellMargin;
439 
442 
445 
448 
451 
454 
457 
460 
463 
466 
468  bool mShowGrid;
469 
472 
475 
478 
481 
484 
487 
490 
492 
494 
496 
499  virtual bool calculateMaxColumnWidths();
500 
504  virtual bool calculateMaxRowHeights();
505 
510  //not const, as needs to call calculateMaxColumnWidths()
511  double totalWidth();
512 
517  //not const, as needs to call calculateMaxRowHeights()
518  double totalHeight();
519 
531  int rowsVisible( double frameHeight, int firstRow, bool includeHeader, bool includeEmptyRows ) const;
532 
542  int rowsVisible( int frameIndex, int firstRow, bool includeEmptyRows ) const;
543 
549  QPair<int, int> rowRange( const int frameIndex ) const;
550 
560  void drawHorizontalGridLines( QPainter* painter, int firstRow, int lastRow, bool drawHeaderLines ) const;
561 
577  void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, int firstRow, int lastRow, bool hasHeader, bool mergeCells = false ) const;
578 
581  void recalculateTableSize();
582 
588  bool contentsContainsRow( const QgsComposerTableContents &contents, const QgsComposerTableRow &row ) const;
589 
590  //deprecated methods
591 
597  Q_DECL_DEPRECATED int rowsVisible( const int frameIndex ) const;
598 
606  Q_DECL_DEPRECATED int rowsVisible( const double frameHeight, const bool includeHeader ) const;
607 
615  Q_DECL_DEPRECATED QPair<int, int> rowRange( const QRectF &extent, const int frameIndex ) const;
616 
624  Q_DECL_DEPRECATED void drawHorizontalGridLines( QPainter* painter, const int rows, const bool drawHeaderLines ) const;
625 
639  Q_DECL_DEPRECATED void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, const int numberRows, const bool hasHeader, const bool mergeCells = false ) const;
640 
641  private:
642 
643  QMap< CellStyleGroup, QString > mCellStyleNames;
644 
646  void initStyles();
647 
648  bool textRequiresWrapping( const QString& text, double columnWidth , const QFont &font ) const;
649 
650  QString wrappedText( const QString &value, double columnWidth, const QFont &font ) const;
651 
657  QColor backgroundColor( int row, int column ) const;
658 
659  friend class TestQgsComposerTableV2;
660 };
661 
662 #endif // QGSCOMPOSERTABLEV2_H
QColor mContentFontColor
Table contents font color.
QFont mContentFont
Table contents font.
virtual void recalculateFrameSizes()
Recalculates the portion of the multiframe item which is shown in each of it&#39;s component frames...
QColor backgroundColor() const
Returns the color used for the background of the table.
bool showEmptyRows() const
Returns whether empty rows are drawn in the table.
WrapBehaviour mWrapBehaviour
bool mShowGrid
True if grid should be shown.
QColor gridColor() const
Returns the color used for grid lines in the table.
double mGridStrokeWidth
Width of grid lines.
QFont headerFont() const
Returns the font used to draw header text in the table.
HeaderMode
Controls where headers are shown in the table.
QMap< CellStyleGroup, QgsComposerTableStyle * > mCellStyles
QFont mHeaderFont
Header font.
virtual QSizeF totalSize() const =0
Returns the total size of the multiframe&#39;s content.
EmptyTableMode mEmptyTableMode
Behaviour for empty tables.
QColor mHeaderFontColor
Header font color.
double mCellMargin
Margin between cell borders and cell text.
EmptyTableMode
Controls how empty tables are displayed.
HeaderMode mHeaderMode
Header display mode.
bool enabled
Whether the styling option is enabled.
QList< QgsComposerTableRow > QgsComposerTableContents
List of QgsComposerTableRows, representing rows and column cell contents for a QgsComposerTable.
WrapBehaviour wrapBehaviour() const
Returns the wrap behaviour for the table, which controls how text within cells is automatically wrapp...
bool mShowEmptyRows
True if empty rows should be shown in the table.
double gridStrokeWidth() const
Returns the width of grid lines in the table.
double cellMargin() const
Returns the margin distance between cell borders and their contents.
Abstract base class for composer items with the ability to distribute the content to several frames (...
HeaderHAlignment mHeaderHAlignment
Alignment for table headers.
WrapBehaviour
Controls how long strings in the table are handled.
A class to display a table in the print composer, and allow the table to span over multiple frames...
QMap< int, double > mMaxColumnWidthMap
Map of maximum width for each column.
QColor contentFontColor() const
Returns the color used to draw text in table body cells.
Stores properties of a column in a QgsComposerTable.
QString emptyTableMessage() const
Returns the message for empty tables with no content rows.
Graphics scene for map printing.
virtual QSizeF minFrameSize(const int frameIndex=-1) const
Returns the minimum size for a frames, if desired.
QColor mGridColor
Color for grid lines.
HeaderHAlignment
Controls how headers are horizontally aligned in a table.
QFont contentFont() const
Returns the font used to draw text in table body cells.
QgsComposerTableContents mTableContents
Contents to show in table.
QString mEmptyTableMessage
String to show in empty tables.
QgsComposerTableColumns mColumns
Columns to show in table.
CellStyleGroup
Row or column groups for cell styling.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const =0
Stores state information about multiframe in DOM element.
virtual Q_DECL_DEPRECATED void render(QPainter *p, const QRectF &renderExtent)
Renders a portion of the multiframe&#39;s content into a painter.
QList< QgsComposerTableColumn * > QgsComposerTableColumns
List of column definitions for a QgsComposerTable.
virtual QSizeF fixedFrameSize(const int frameIndex=-1) const
Returns the fixed size for a frame, if desired.
QgsComposerTableColumns * columns()
Returns a pointer to the list of QgsComposerTableColumns shown in the table.
bool showGrid() const
Returns whether grid lines are drawn in the table.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)=0
Reads multiframe state information from a DOM element.
HeaderMode headerMode() const
Returns the display mode for headers in the table.
QList< QVariant > QgsComposerTableRow
List of QVariants, representing a the contents of a single row in a QgsComposerTable.
Styling option for a composer table cell.
QColor mBackgroundColor
Color for table background.
QgsComposerTableContents * contents()
Returns the current contents of the table.
HeaderHAlignment headerHAlignment() const
Returns the horizontal alignment for table headers.
QColor headerFontColor() const
Returns the color used to draw header text in the table.
QMap< int, double > mMaxRowHeightMap
Map of maximum height for each row.
EmptyTableMode emptyTableBehaviour() const
Returns the behaviour mode for empty tables.
QColor cellBackgroundColor
Cell background color.