QGIS API Documentation  2.18.3-Las Palmas (77b8c3d)
qgscomposerattributetablev2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerattributetablev2.h
3  ---------------------------
4  begin : September 2014
5  copyright : (C) 2014 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 QGSCOMPOSERATTRIBUTETABLEV2_H
19 #define QGSCOMPOSERATTRIBUTETABLEV2_H
20 
21 #include "qgscomposertablev2.h"
23 
24 class QgsComposerMap;
25 class QgsVectorLayer;
26 
31 {
32  public:
34  bool operator()( const QgsComposerTableRow& m1, const QgsComposerTableRow& m2 );
35 
39  void setSortColumn( int col ) { mCurrentSortColumn = col; }
40 
44  void setAscending( bool asc ) { mAscending = asc; }
45 
46  private:
47  int mCurrentSortColumn;
48  bool mAscending;
49 };
50 
51 
56 {
57  Q_OBJECT
58 
59  public:
60 
64  {
65  LayerAttributes = 0,
67  RelationChildren
68  };
69 
70  QgsComposerAttributeTableV2( QgsComposition* composition, bool createUndoCommands );
72 
73  virtual QString displayName() const override;
74 
81  virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const override;
82 
89  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false ) override;
90 
91  virtual void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true ) override;
92 
97  void setSource( const ContentSource source );
98 
103  ContentSource source() const { return mSource; }
104 
111  QgsVectorLayer* sourceLayer();
112 
117  void setVectorLayer( QgsVectorLayer* layer );
118 
123  QgsVectorLayer* vectorLayer() const { return mVectorLayer; }
124 
131  void setRelationId( const QString& relationId );
132 
139  QString relationId() const { return mRelationId; }
140 
144  void resetColumns();
145 
155  void setComposerMap( const QgsComposerMap* map );
156 
163  const QgsComposerMap* composerMap() const { return mComposerMap; }
164 
171  void setMaximumNumberOfFeatures( const int features );
172 
177  int maximumNumberOfFeatures() const { return mMaximumNumberOfFeatures; }
178 
184  void setUniqueRowsOnly( const bool uniqueOnly );
185 
191  bool uniqueRowsOnly() const { return mShowUniqueRowsOnly; }
192 
200  void setDisplayOnlyVisibleFeatures( const bool visibleOnly );
201 
208  bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }
209 
216  void setFilterToAtlasFeature( const bool filterToAtlas );
217 
223  bool filterToAtlasFeature() const { return mFilterToAtlasIntersection; }
224 
230  bool filterFeatures() const { return mFilterFeatures; }
231 
239  void setFilterFeatures( const bool filter );
240 
247  QString featureFilter() const { return mFeatureFilter; }
248 
257  void setFeatureFilter( const QString& expression );
258 
267  Q_DECL_DEPRECATED void setDisplayAttributes( const QSet<int>& attr, bool refresh = true );
268 
277  void setDisplayedFields( const QStringList& fields, bool refresh = true );
278 
285  QList<QPair<int, bool> > sortAttributes() const;
286 
293  void setWrapString( const QString& wrapString );
294 
301  QString wrapString() const { return mWrapString; }
302 
308  bool getTableContents( QgsComposerTableContents &contents ) override;
309 
310  virtual QgsExpressionContext* createExpressionContext() const override;
311 
312  private:
313 
315  ContentSource mSource;
317  QgsVectorLayer* mVectorLayer;
319  QString mRelationId;
320 
322  QgsVectorLayer* mCurrentAtlasLayer;
323 
325  const QgsComposerMap* mComposerMap;
327  int mMaximumNumberOfFeatures;
328 
330  bool mShowUniqueRowsOnly;
331 
333  bool mShowOnlyVisibleFeatures;
334 
336  bool mFilterToAtlasIntersection;
337 
339  bool mFilterFeatures;
341  QString mFeatureFilter;
342 
343  QString mWrapString;
344 
348  QList<int> fieldsToDisplay() const;
349 
354  void restoreFieldAliasMap( const QMap<int, QString>& map );
355 
359  QVariant replaceWrapChar( const QVariant &variant ) const;
360 
361  private slots:
363  void removeLayer( const QString& layerId );
364 
365  void atlasLayerChanged( QgsVectorLayer* layer );
366 
367 };
368 
369 #endif // QGSCOMPOSERATTRIBUTETABLEV2_H
bool displayOnlyVisibleFeatures() const
Returns true if the table is set to show only features visible on a corresponding composer map item...
Helper class for sorting tables, takes into account sorting column and ascending / descending...
virtual QString displayName() const
Get multiframe display name.
QgsVectorLayer * vectorLayer() const
Returns the vector layer the attribute table is currently using.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const override
Stores state information about multiframe in DOM element.
A table that displays attributes from a vector layer.
virtual QgsExpressionContext * createExpressionContext() const
Creates an expression context relating to the objects&#39; current state.
virtual void addFrame(QgsComposerFrame *frame, bool recalcFrameSizes=true)=0
Adds a frame to the multiframe.
void setSortColumn(int col)
Sets column number to sort by.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A class to display a table in the print composer, and allow the table to span over multiple frames...
bool uniqueRowsOnly() const
Returns true if the table is set to show only unique rows.
int maximumNumberOfFeatures() const
Returns the maximum number of features to be shown by the table.
QString featureFilter() const
Returns the current expression used to filter features for the table.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false) override
Reads multiframe state information from a DOM element.
Graphics scene for map printing.
const QgsComposerMap * composerMap() const
Returns the composer map whose extents are controlling the features shown in the table.
Object representing map window.
Frame item for a composer multiframe item.
ContentSource
Specifies the content source for the attribute table.
bool filterToAtlasFeature() const
Returns true if the table is set to only show features which intersect the current atlas feature...
QString relationId() const
Returns the relation id which the table displays child features from.
bool filterFeatures() const
Returns true if a feature filter is active on the attribute table.
virtual bool getTableContents(QgsComposerTableContents &contents)=0
Fetches the contents used for the cells in the table.
void setAscending(bool asc)
Sets sort order for column sorting.
Represents a vector layer which manages a vector based data sets.
QString wrapString() const
Returns the string used to wrap the contents of the table cells by.
ContentSource source() const
Returns the source for attributes shown in the table body.