QGIS API Documentation  2.18.3-Las Palmas (77b8c3d)
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 
34 
41 
47 
48 
55 class CORE_EXPORT QgsComposerTableStyle
56 {
57  public:
58 
60  : enabled( false )
61  , cellBackgroundColor( QColor( 255, 255, 255, 255 ) )
62  {}
63 
65  bool enabled;
66 
69 
75  bool writeXML( QDomElement& styleElem, QDomDocument & doc ) const;
76 
81  bool readXML( const QDomElement& styleElem );
82 
83 };
84 
90 class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
91 {
92  Q_OBJECT
93 
94  public:
95 
99  {
103  HeaderRight
104  };
105 
109  {
110  FirstFrame = 0,
112  NoHeaders
113  };
114 
118  {
119  HeadersOnly = 0,
121  ShowMessage
122  };
123 
127  {
128  TruncateText = 0,
129  WrapText
130  };
131 
135  {
144  LastRow
145  };
146 
147  QgsComposerTableV2( QgsComposition* composition, bool createUndoCommands );
149 
150  virtual ~QgsComposerTableV2();
151 
156  void setCellMargin( const double margin );
157 
162  double cellMargin() const { return mCellMargin; }
163 
168  void setEmptyTableBehaviour( const EmptyTableMode mode );
169 
175  EmptyTableMode emptyTableBehaviour() const { return mEmptyTableMode; }
176 
184  void setEmptyTableMessage( const QString& message );
185 
193  QString emptyTableMessage() const { return mEmptyTableMessage; }
194 
199  void setShowEmptyRows( const bool showEmpty );
200 
205  bool showEmptyRows() const { return mShowEmptyRows; }
206 
212  void setHeaderFont( const QFont& font );
213 
219  QFont headerFont() const { return mHeaderFont; }
220 
227  void setHeaderFontColor( const QColor& color );
228 
235  QColor headerFontColor() const { return mHeaderFontColor; }
236 
241  void setHeaderHAlignment( const HeaderHAlignment alignment );
242 
247  HeaderHAlignment headerHAlignment() const { return mHeaderHAlignment; }
248 
254  void setHeaderMode( const HeaderMode mode );
255 
261  HeaderMode headerMode() const { return mHeaderMode; }
262 
268  void setContentFont( const QFont& font );
269 
275  QFont contentFont() const { return mContentFont; }
276 
283  void setContentFontColor( const QColor& color );
284 
291  QColor contentFontColor() const { return mContentFontColor; }
292 
299  void setShowGrid( const bool showGrid );
300 
307  bool showGrid() const { return mShowGrid; }
308 
315  void setGridStrokeWidth( const double width );
316 
323  double gridStrokeWidth() const { return mGridStrokeWidth; }
324 
331  void setGridColor( const QColor& color );
332 
339  QColor gridColor() const { return mGridColor; }
340 
346  void setBackgroundColor( const QColor& color );
347 
353  QColor backgroundColor() const { return mBackgroundColor; }
354 
361  void setWrapBehaviour( WrapBehaviour behaviour );
362 
369  WrapBehaviour wrapBehaviour() const { return mWrapBehaviour; }
370 
375  QgsComposerTableColumns* columns() { return &mColumns; }
376 
382  void setColumns( const QgsComposerTableColumns& columns );
383 
390  void setCellStyle( CellStyleGroup group, const QgsComposerTableStyle& style );
391 
397  const QgsComposerTableStyle* cellStyle( CellStyleGroup group ) const;
398 
404  virtual QMap<int, QString> headerLabels() const;
405 
411  virtual bool getTableContents( QgsComposerTableContents &contents ) = 0;
412 
416  QgsComposerTableContents* contents() { return &mTableContents; }
417 
418  //reimplemented to return fixed table width
419  virtual QSizeF fixedFrameSize( const int frameIndex = -1 ) const override;
420 
421  //reimplemented to return min frame height
422  virtual QSizeF minFrameSize( const int frameIndex = -1 ) const override;
423 
424  virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const override;
425  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false ) override;
426  virtual QSizeF totalSize() const override;
427  virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex ) override;
428 
429  public slots:
430 
436  virtual void refreshAttributes();
437 
438  void recalculateFrameSizes() override;
439 
440  protected:
442  double mCellMargin;
443 
446 
449 
452 
455 
458 
461 
464 
467 
470 
472  bool mShowGrid;
473 
476 
479 
482 
485 
488 
491 
494 
496 
498 
500 
503  virtual bool calculateMaxColumnWidths();
504 
508  virtual bool calculateMaxRowHeights();
509 
514  //not const, as needs to call calculateMaxColumnWidths()
515  double totalWidth();
516 
521  //not const, as needs to call calculateMaxRowHeights()
522  double totalHeight();
523 
535  int rowsVisible( double frameHeight, int firstRow, bool includeHeader, bool includeEmptyRows ) const;
536 
546  int rowsVisible( int frameIndex, int firstRow, bool includeEmptyRows ) const;
547 
553  QPair<int, int> rowRange( const int frameIndex ) const;
554 
564  void drawHorizontalGridLines( QPainter* painter, int firstRow, int lastRow, bool drawHeaderLines ) const;
565 
581  void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, int firstRow, int lastRow, bool hasHeader, bool mergeCells = false ) const;
582 
585  void recalculateTableSize();
586 
592  bool contentsContainsRow( const QgsComposerTableContents &contents, const QgsComposerTableRow &row ) const;
593 
594  //deprecated methods
595 
601  Q_DECL_DEPRECATED int rowsVisible( const int frameIndex ) const;
602 
610  Q_DECL_DEPRECATED int rowsVisible( const double frameHeight, const bool includeHeader ) const;
611 
619  Q_DECL_DEPRECATED QPair<int, int> rowRange( const QRectF &extent, const int frameIndex ) const;
620 
628  Q_DECL_DEPRECATED void drawHorizontalGridLines( QPainter* painter, const int rows, const bool drawHeaderLines ) const;
629 
643  Q_DECL_DEPRECATED void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, const int numberRows, const bool hasHeader, const bool mergeCells = false ) const;
644 
645  private:
646 
647  QMap< CellStyleGroup, QString > mCellStyleNames;
648 
650  void initStyles();
651 
652  bool textRequiresWrapping( const QString& text, double columnWidth , const QFont &font ) const;
653 
654  QString wrappedText( const QString &value, double columnWidth, const QFont &font ) const;
655 
661  QColor backgroundColor( int row, int column ) const;
662 
663  friend class TestQgsComposerTableV2;
664 };
665 
666 #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.
QList< QgsComposerTableRow > QgsComposerTableContents
List of QgsComposerTableRows, representing rows and column cell contents for a QgsComposerTable.
HeaderMode mHeaderMode
Header display mode.
bool enabled
Whether the styling option is enabled.
QList< QVariant > QgsComposerTableRow
List of QVariants, representing a the contents of a single row in 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.
QList< QgsComposerTableColumn * > QgsComposerTableColumns
List of column definitions for a QgsComposerTable.
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.
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.
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.