QGIS API Documentation  2.12.0-Lyon
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 
29 {
30  public:
32  bool operator()( const QgsComposerTableRow& m1, const QgsComposerTableRow& m2 );
33 
37  void setSortColumn( int col ) { mCurrentSortColumn = col; }
38 
42  void setAscending( bool asc ) { mAscending = asc; }
43 
44  private:
45  int mCurrentSortColumn;
46  bool mAscending;
47 };
48 
49 
52 {
53  Q_OBJECT
54 
55  public:
56 
60  {
61  LayerAttributes = 0,
63  RelationChildren
64  };
65 
66  QgsComposerAttributeTableV2( QgsComposition* composition, bool createUndoCommands );
68 
69  virtual QString displayName() const override;
70 
77  virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const override;
78 
85  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false ) override;
86 
87  virtual void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true ) override;
88 
93  void setSource( const ContentSource source );
94 
99  ContentSource source() const { return mSource; }
100 
107  QgsVectorLayer* sourceLayer();
108 
113  void setVectorLayer( QgsVectorLayer* layer );
114 
119  QgsVectorLayer* vectorLayer() const { return mVectorLayer; }
120 
127  void setRelationId( const QString& relationId );
128 
135  QString relationId() const { return mRelationId; }
136 
140  void resetColumns();
141 
151  void setComposerMap( const QgsComposerMap* map );
152 
159  const QgsComposerMap* composerMap() const { return mComposerMap; }
160 
167  void setMaximumNumberOfFeatures( const int features );
168 
173  int maximumNumberOfFeatures() const { return mMaximumNumberOfFeatures; }
174 
180  void setUniqueRowsOnly( const bool uniqueOnly );
181 
187  bool uniqueRowsOnly() const { return mShowUniqueRowsOnly; }
188 
196  void setDisplayOnlyVisibleFeatures( const bool visibleOnly );
197 
204  bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }
205 
212  void setFilterToAtlasFeature( const bool filterToAtlas );
213 
219  bool filterToAtlasFeature() const { return mFilterToAtlasIntersection; }
220 
226  bool filterFeatures() const { return mFilterFeatures; }
227 
235  void setFilterFeatures( const bool filter );
236 
243  QString featureFilter() const { return mFeatureFilter; }
244 
253  void setFeatureFilter( const QString& expression );
254 
263  void setDisplayAttributes( const QSet<int>& attr, bool refresh = true );
264 
271  QList<QPair<int, bool> > sortAttributes() const;
272 
279  void setWrapString( const QString& wrapString );
280 
287  QString wrapString() const { return mWrapString; }
288 
294  bool getTableContents( QgsComposerTableContents &contents ) override;
295 
296  virtual QgsExpressionContext* createExpressionContext() const override;
297 
298  private:
299 
301  ContentSource mSource;
303  QgsVectorLayer* mVectorLayer;
305  QString mRelationId;
306 
308  QgsVectorLayer* mCurrentAtlasLayer;
309 
311  const QgsComposerMap* mComposerMap;
313  int mMaximumNumberOfFeatures;
314 
316  bool mShowUniqueRowsOnly;
317 
319  bool mShowOnlyVisibleFeatures;
320 
322  bool mFilterToAtlasIntersection;
323 
325  bool mFilterFeatures;
327  QString mFeatureFilter;
328 
329  QString mWrapString;
330 
334  QList<int> fieldsToDisplay() const;
335 
340  void restoreFieldAliasMap( const QMap<int, QString>& map );
341 
345  QVariant replaceWrapChar( const QVariant &variant ) const;
346 
347  private slots:
349  void removeLayer( const QString& layerId );
350 
351  void atlasLayerChanged( QgsVectorLayer* layer );
352 
353 };
354 
355 #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's 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.