QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 #include "qgsvectorlayerref.h"
24 
25 class QgsComposerMap;
26 class QgsVectorLayer;
27 
32 {
33  public:
35  bool operator()( const QgsComposerTableRow& m1, const QgsComposerTableRow& m2 );
36 
40  void setSortColumn( int col ) { mCurrentSortColumn = col; }
41 
45  void setAscending( bool asc ) { mAscending = asc; }
46 
47  private:
48  int mCurrentSortColumn;
49  bool mAscending;
50 };
51 
52 
57 {
58  Q_OBJECT
59 
60  public:
61 
65  {
66  LayerAttributes = 0,
68  RelationChildren
69  };
70 
71  QgsComposerAttributeTableV2( QgsComposition* composition, bool createUndoCommands );
73 
74  virtual QString displayName() const override;
75 
82  virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const override;
83 
90  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false ) override;
91 
92  virtual void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true ) override;
93 
98  void setSource( const ContentSource source );
99 
104  ContentSource source() const { return mSource; }
105 
112  QgsVectorLayer* sourceLayer();
113 
118  void setVectorLayer( QgsVectorLayer* layer );
119 
124  QgsVectorLayer* vectorLayer() const { return mVectorLayer.get(); }
125 
132  void setRelationId( const QString& relationId );
133 
140  QString relationId() const { return mRelationId; }
141 
145  void resetColumns();
146 
156  void setComposerMap( const QgsComposerMap* map );
157 
164  const QgsComposerMap* composerMap() const { return mComposerMap; }
165 
172  void setMaximumNumberOfFeatures( const int features );
173 
178  int maximumNumberOfFeatures() const { return mMaximumNumberOfFeatures; }
179 
185  void setUniqueRowsOnly( const bool uniqueOnly );
186 
192  bool uniqueRowsOnly() const { return mShowUniqueRowsOnly; }
193 
201  void setDisplayOnlyVisibleFeatures( const bool visibleOnly );
202 
209  bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }
210 
217  void setFilterToAtlasFeature( const bool filterToAtlas );
218 
224  bool filterToAtlasFeature() const { return mFilterToAtlasIntersection; }
225 
231  bool filterFeatures() const { return mFilterFeatures; }
232 
240  void setFilterFeatures( const bool filter );
241 
248  QString featureFilter() const { return mFeatureFilter; }
249 
258  void setFeatureFilter( const QString& expression );
259 
268  Q_DECL_DEPRECATED void setDisplayAttributes( const QSet<int>& attr, bool refresh = true );
269 
278  void setDisplayedFields( const QStringList& fields, bool refresh = true );
279 
286  QList<QPair<int, bool> > sortAttributes() const;
287 
294  void setWrapString( const QString& wrapString );
295 
302  QString wrapString() const { return mWrapString; }
303 
309  bool getTableContents( QgsComposerTableContents &contents ) override;
310 
311  virtual QgsExpressionContext* createExpressionContext() const override;
312 
313  private:
314 
316  ContentSource mSource;
318  QgsVectorLayerRef mVectorLayer;
320  QString mRelationId;
321 
323  QgsVectorLayer* mCurrentAtlasLayer;
324 
326  const QgsComposerMap* mComposerMap;
328  int mMaximumNumberOfFeatures;
329 
331  bool mShowUniqueRowsOnly;
332 
334  bool mShowOnlyVisibleFeatures;
335 
337  bool mFilterToAtlasIntersection;
338 
340  bool mFilterFeatures;
342  QString mFeatureFilter;
343 
344  QString mWrapString;
345 
349  QList<int> fieldsToDisplay() const;
350 
355  void restoreFieldAliasMap( const QMap<int, QString>& map );
356 
360  QVariant replaceWrapChar( const QVariant &variant ) const;
361 
362  private slots:
364  void removeLayer( const QString& layerId );
365 
366  void atlasLayerChanged( QgsVectorLayer* layer );
367 
368 };
369 
370 #endif // QGSCOMPOSERATTRIBUTETABLEV2_H
QString featureFilter() const
Returns the current expression used to filter features for the table.
Helper class for sorting tables, takes into account sorting column and ascending / descending...
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const override
Stores state information about multiframe in DOM element.
virtual QString displayName() const
Get multiframe display name.
A table that displays attributes from a vector layer.
virtual void addFrame(QgsComposerFrame *frame, bool recalcFrameSizes=true)=0
Adds a frame to the multiframe.
bool filterToAtlasFeature() const
Returns true if the table is set to only show features which intersect the current atlas feature...
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...
ContentSource source() const
Returns the source for attributes shown in the table body.
bool displayOnlyVisibleFeatures() const
Returns true if the table is set to show only features visible on a corresponding composer map item...
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.
Object representing map window.
Frame item for a composer multiframe item.
int maximumNumberOfFeatures() const
Returns the maximum number of features to be shown by the table.
ContentSource
Specifies the content source for the attribute table.
QgsVectorLayer * vectorLayer() const
Returns the vector layer the attribute table is currently using.
const QgsComposerMap * composerMap() const
Returns the composer map whose extents are controlling the features shown in the table.
bool filterFeatures() const
Returns true if a feature filter is active on the attribute table.
QString relationId() const
Returns the relation id which the table displays child features from.
virtual bool getTableContents(QgsComposerTableContents &contents)=0
Fetches the contents used for the cells in the table.
QString wrapString() const
Returns the string used to wrap the contents of the table cells by.
void setAscending(bool asc)
Sets sort order for column sorting.
Represents a vector layer which manages a vector based data sets.
bool uniqueRowsOnly() const
Returns true if the table is set to show only unique rows.
virtual QgsExpressionContext * createExpressionContext() const
Creates an expression context relating to the objects&#39; current state.