QGIS API Documentation  2.12.0-Lyon
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 
46 
53 class CORE_EXPORT QgsComposerTableStyle
54 {
55  public:
56 
58  : enabled( false )
59  , cellBackgroundColor( QColor( 255, 255, 255, 255 ) )
60  {}
61 
63  bool enabled;
64 
67 
73  bool writeXML( QDomElement& styleElem, QDomDocument & doc ) const;
74 
79  bool readXML( const QDomElement& styleElem );
80 
81 };
82 
88 class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
89 {
90  Q_OBJECT
91 
92  public:
93 
97  {
101  HeaderRight
102  };
103 
107  {
108  FirstFrame = 0,
110  NoHeaders
111  };
112 
116  {
117  HeadersOnly = 0,
119  ShowMessage
120  };
121 
125  {
126  TruncateText = 0,
127  WrapText
128  };
129 
133  {
142  LastRow
143  };
144 
145  QgsComposerTableV2( QgsComposition* composition, bool createUndoCommands );
147 
148  virtual ~QgsComposerTableV2();
149 
154  void setCellMargin( const double margin );
155 
160  double cellMargin() const { return mCellMargin; }
161 
166  void setEmptyTableBehaviour( const EmptyTableMode mode );
167 
173  EmptyTableMode emptyTableBehaviour() const { return mEmptyTableMode; }
174 
182  void setEmptyTableMessage( const QString& message );
183 
191  QString emptyTableMessage() const { return mEmptyTableMessage; }
192 
197  void setShowEmptyRows( const bool showEmpty );
198 
203  bool showEmptyRows() const { return mShowEmptyRows; }
204 
210  void setHeaderFont( const QFont& font );
211 
217  QFont headerFont() const { return mHeaderFont; }
218 
225  void setHeaderFontColor( const QColor& color );
226 
233  QColor headerFontColor() const { return mHeaderFontColor; }
234 
239  void setHeaderHAlignment( const HeaderHAlignment alignment );
240 
245  HeaderHAlignment headerHAlignment() const { return mHeaderHAlignment; }
246 
252  void setHeaderMode( const HeaderMode mode );
253 
259  HeaderMode headerMode() const { return mHeaderMode; }
260 
266  void setContentFont( const QFont& font );
267 
273  QFont contentFont() const { return mContentFont; }
274 
281  void setContentFontColor( const QColor& color );
282 
289  QColor contentFontColor() const { return mContentFontColor; }
290 
297  void setShowGrid( const bool showGrid );
298 
305  bool showGrid() const { return mShowGrid; }
306 
313  void setGridStrokeWidth( const double width );
314 
321  double gridStrokeWidth() const { return mGridStrokeWidth; }
322 
329  void setGridColor( const QColor& color );
330 
337  QColor gridColor() const { return mGridColor; }
338 
344  void setBackgroundColor( const QColor& color );
345 
351  QColor backgroundColor() const { return mBackgroundColor; }
352 
359  void setWrapBehaviour( WrapBehaviour behaviour );
360 
367  WrapBehaviour wrapBehaviour() const { return mWrapBehaviour; }
368 
373  QgsComposerTableColumns* columns() { return &mColumns; }
374 
379  void setColumns( const QgsComposerTableColumns& columns );
380 
387  void setCellStyle( CellStyleGroup group, const QgsComposerTableStyle& style );
388 
394  const QgsComposerTableStyle* cellStyle( CellStyleGroup group ) const;
395 
401  virtual QMap<int, QString> headerLabels() const;
402 
408  virtual bool getTableContents( QgsComposerTableContents &contents ) = 0;
409 
413  QgsComposerTableContents* contents() { return &mTableContents; }
414 
415  //reimplemented to return fixed table width
416  virtual QSizeF fixedFrameSize( const int frameIndex = -1 ) const override;
417 
418  //reimplemented to return min frame height
419  virtual QSizeF minFrameSize( const int frameIndex = -1 ) const override;
420 
421  virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const override;
422  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false ) override;
423  virtual QSizeF totalSize() const override;
424  virtual void render( QPainter* p, const QRectF& renderExtent, const int frameIndex ) override;
425 
426  public slots:
427 
433  virtual void refreshAttributes();
434 
435  void recalculateFrameSizes() override;
436 
437  protected:
439  double mCellMargin;
440 
443 
446 
449 
452 
455 
458 
461 
464 
467 
469  bool mShowGrid;
470 
473 
476 
479 
482 
485 
488 
491 
493 
495 
497 
500  virtual bool calculateMaxColumnWidths();
501 
505  virtual bool calculateMaxRowHeights();
506 
511  //not const, as needs to call calculateMaxColumnWidths()
512  double totalWidth();
513 
518  //not const, as needs to call calculateMaxRowHeights()
519  double totalHeight();
520 
532  int rowsVisible( double frameHeight, int firstRow, bool includeHeader, bool includeEmptyRows ) const;
533 
543  int rowsVisible( int frameIndex, int firstRow, bool includeEmptyRows ) const;
544 
550  QPair<int, int> rowRange( const int frameIndex ) const;
551 
561  void drawHorizontalGridLines( QPainter* painter, int firstRow, int lastRow, bool drawHeaderLines ) const;
562 
578  void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, int firstRow, int lastRow, bool hasHeader, bool mergeCells = false ) const;
579 
582  void recalculateTableSize();
583 
589  bool contentsContainsRow( const QgsComposerTableContents &contents, const QgsComposerTableRow &row ) const;
590 
591  //deprecated methods
592 
597  Q_DECL_DEPRECATED int rowsVisible( const int frameIndex ) const;
598 
605  Q_DECL_DEPRECATED int rowsVisible( const double frameHeight, const bool includeHeader ) const;
606 
613  Q_DECL_DEPRECATED QPair<int, int> rowRange( const QRectF &extent, const int frameIndex ) const;
614 
621  Q_DECL_DEPRECATED void drawHorizontalGridLines( QPainter* painter, const int rows, const bool drawHeaderLines ) const;
622 
635  Q_DECL_DEPRECATED void drawVerticalGridLines( QPainter* painter, const QMap<int, double>& maxWidthMap, const int numberRows, const bool hasHeader, const bool mergeCells = false ) const;
636 
637  private:
638 
639  QMap< CellStyleGroup, QString > mCellStyleNames;
640 
642  void initStyles();
643 
644  bool textRequiresWrapping( const QString& text, double columnWidth , const QFont &font ) const;
645 
646  QString wrappedText( const QString &value, double columnWidth, const QFont &font ) const;
647 
653  QColor backgroundColor( int row, int column ) const;
654 
655  friend class TestQgsComposerTableV2;
656 };
657 
658 #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'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.
QMap< CellStyleGroup, QgsComposerTableStyle * > mCellStyles
QFont mHeaderFont
Header font.
virtual QSizeF totalSize() const =0
Returns the total size of the multiframe's content.
HeaderHAlignment
Controls how headers are horizontally aligned in a table.
EmptyTableMode mEmptyTableMode
Behaviour for empty tables.
QColor mHeaderFontColor
Header font color.
double mCellMargin
Margin between cell borders and cell text.
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.
CellStyleGroup
Row or column groups for cell styling.
WrapBehaviour wrapBehaviour() const
Returns the wrap behaviour for the table, which controls how text within cells is automatically wrapp...
EmptyTableMode
Controls how empty tables are displayed.
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.
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.
WrapBehaviour
Controls how long strings in the table are handled.
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.
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.
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'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.
HeaderMode
Controls where headers are shown in the table.
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.