QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgslayoutitemattributetable.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitemattributetable.h
3  ---------------------------
4  begin : November 2017
5  copyright : (C) 2017 by Nyall Dawson
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 QGSLAYOUTITEMATTRIBUTETABLE_H
19 #define QGSLAYOUTITEMATTRIBUTETABLE_H
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include "qgis.h"
24 #include "qgslayouttable.h"
25 #include "qgsvectorlayerref.h"
26 
27 class QgsLayoutItemMap;
28 class QgsVectorLayer;
29 
36 {
37  Q_OBJECT
38 
39  public:
40 
45  {
46  LayerAttributes = 0,
48  RelationChildren
49  };
50 
57 
58  int type() const override;
59  QIcon icon() const override;
60  QString displayName() const override;
61 
65  static QgsLayoutItemAttributeTable *create( QgsLayout *layout ) SIP_FACTORY;
66 
71  void setSource( ContentSource source );
72 
77  ContentSource source() const { return mSource; }
78 
85  QgsVectorLayer *sourceLayer() const;
86 
94  void setVectorLayer( QgsVectorLayer *layer );
95 
104  QgsVectorLayer *vectorLayer() const { return mVectorLayer.get(); }
105 
112  void setRelationId( const QString &id );
113 
120  QString relationId() const { return mRelationId; }
121 
126  void resetColumns();
127 
137  void setMap( QgsLayoutItemMap *map );
138 
145  QgsLayoutItemMap *map() const { return mMap; }
146 
153  void setMaximumNumberOfFeatures( int features );
154 
159  int maximumNumberOfFeatures() const { return mMaximumNumberOfFeatures; }
160 
169  void setUniqueRowsOnly( bool uniqueOnly );
170 
176  bool uniqueRowsOnly() const { return mShowUniqueRowsOnly; }
177 
186  void setDisplayOnlyVisibleFeatures( bool visibleOnly );
187 
195  bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }
196 
203  void setFilterToAtlasFeature( bool filterToAtlas );
204 
211  bool filterToAtlasFeature() const { return mFilterToAtlasIntersection; }
212 
219  bool filterFeatures() const { return mFilterFeatures; }
220 
228  void setFilterFeatures( bool filter );
229 
237  QString featureFilter() const { return mFeatureFilter; }
238 
248  void setFeatureFilter( const QString &expression );
249 
258  void setDisplayedFields( const QStringList &fields, bool refresh = true );
259 
267  QVector< QPair<int, bool> > sortAttributes() const SIP_SKIP;
268 
275  void setWrapString( const QString &wrapString );
276 
282  QString wrapString() const { return mWrapString; }
283 
290  bool getTableContents( QgsLayoutTableContents &contents ) override SIP_SKIP;
291 
293  void finalizeRestoreFromXml() override;
294 
296 
297  protected:
298 
299  bool writePropertiesToElement( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
300  bool readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context ) override;
301 
302  private slots:
303 
304  void disconnectCurrentMap();
305 
306  private:
307 
309  ContentSource mSource = LayerAttributes;
311  QgsVectorLayerRef mVectorLayer;
312 
314  QPointer< QgsVectorLayer > mDataDefinedVectorLayer;
315 
317  QString mRelationId;
318 
320  QgsVectorLayer *mCurrentAtlasLayer = nullptr;
321 
323  QgsLayoutItemMap *mMap = nullptr;
324  QString mMapUuid;
325 
327  int mMaximumNumberOfFeatures = 30;
328 
330  bool mShowUniqueRowsOnly = false;
331 
333  bool mShowOnlyVisibleFeatures = false;
334 
336  bool mFilterToAtlasIntersection = false;
337 
339  bool mFilterFeatures = false;
340 
342  QString mFeatureFilter;
343 
344  QString mWrapString;
345 
350  QList<int> fieldsToDisplay() const;
351 
357  void restoreFieldAliasMap( const QMap<int, QString> &map );
358 
363  QVariant replaceWrapChar( const QVariant &variant ) const;
364 
365  private slots:
367  void removeLayer( const QString &layerId );
368 
369  void atlasLayerChanged( QgsVectorLayer *layer );
370 
371 };
372 
373 #endif // QGSLAYOUTITEMATTRIBUTETABLE_H
The class is used as a container of context for various read/write operations on other objects...
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects&#39; current state.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A class to display a table in the print layout, and allow the table to span over multiple frames...
bool filterToAtlasFeature() const
Returns true if the table is set to only show features which intersect the current atlas feature...
bool writePropertiesToElement(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores multiframe state within an XML DOM element.
ContentSource source() const
Returns the source for attributes shown in the table body.
QgsVectorLayer * vectorLayer() const
Returns the vector layer the attribute table is currently using.
Layout graphical items for displaying a map.
#define SIP_SKIP
Definition: qgis_sip.h:119
virtual QIcon icon() const
Returns the item&#39;s icon.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
A layout table subclass that displays attributes from a vector layer.
Table shows attributes from the current atlas feature.
#define SIP_FACTORY
Definition: qgis_sip.h:69
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
virtual bool getTableContents(QgsLayoutTableContents &contents)=0
Fetches the contents used for the cells in the table.
bool displayOnlyVisibleFeatures() const
Returns true if the table is set to show only features visible on a corresponding map item...
virtual int type() const =0
Returns unique multiframe type id.
QgsLayoutItemMap * map() const
Returns the layout map whose extents are controlling the features shown in the table.
QString relationId() const
Returns the relation id which the table displays child features from.
ContentSource
Specifies the content source for the attribute table.
bool filterFeatures() const
Returns true if a feature filter is active on the attribute table.
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.
virtual QString displayName() const
Returns the multiframe display name.
DataDefinedProperty
Data defined properties for different item types.
QVector< QgsLayoutTableRow > QgsLayoutTableContents
List of QgsLayoutTableRows, representing rows and column cell contents for a QgsLayoutTable.
bool uniqueRowsOnly() const
Returns true if the table is set to show only unique rows.
bool readPropertiesFromElement(const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets multiframe state from a DOM element.
All properties for item.
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
Refreshes a data defined property for the multi frame by reevaluating the property&#39;s value and redraw...