QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgslayouttable.h"
24 #include "qgsvectorlayerref.h"
25 
26 class QgsLayoutItemMap;
27 class QgsVectorLayer;
28 
35 {
36  Q_OBJECT
37 
38  public:
39 
44  {
45  LayerAttributes = 0,
47  RelationChildren
48  };
49 
56 
57  int type() const override;
58  QIcon icon() const override;
59  QString displayName() const override;
60 
64  static QgsLayoutItemAttributeTable *create( QgsLayout *layout ) SIP_FACTORY;
65 
70  void setSource( ContentSource source );
71 
76  ContentSource source() const { return mSource; }
77 
84  QgsVectorLayer *sourceLayer() const;
85 
93  void setVectorLayer( QgsVectorLayer *layer );
94 
103  QgsVectorLayer *vectorLayer() const { return mVectorLayer.get(); }
104 
111  void setRelationId( const QString &id );
112 
119  QString relationId() const { return mRelationId; }
120 
125  void resetColumns();
126 
136  void setMap( QgsLayoutItemMap *map );
137 
144  QgsLayoutItemMap *map() const { return mMap; }
145 
152  void setMaximumNumberOfFeatures( int features );
153 
158  int maximumNumberOfFeatures() const { return mMaximumNumberOfFeatures; }
159 
168  void setUniqueRowsOnly( bool uniqueOnly );
169 
175  bool uniqueRowsOnly() const { return mShowUniqueRowsOnly; }
176 
185  void setDisplayOnlyVisibleFeatures( bool visibleOnly );
186 
194  bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }
195 
202  void setFilterToAtlasFeature( bool filterToAtlas );
203 
210  bool filterToAtlasFeature() const { return mFilterToAtlasIntersection; }
211 
218  bool filterFeatures() const { return mFilterFeatures; }
219 
227  void setFilterFeatures( bool filter );
228 
236  QString featureFilter() const { return mFeatureFilter; }
237 
247  void setFeatureFilter( const QString &expression );
248 
257  void setDisplayedFields( const QStringList &fields, bool refresh = true );
258 
265  void setWrapString( const QString &wrapString );
266 
272  QString wrapString() const { return mWrapString; }
273 
279  bool getTableContents( QgsLayoutTableContents &contents ) override;
280 
281  QgsConditionalStyle conditionalCellStyle( int row, int column ) const override;
282  QgsTextFormat textFormatForCell( int row, int column ) const override;
283  QgsExpressionContextScope *scopeForCell( int row, int column ) const override SIP_FACTORY;
284 
286  void finalizeRestoreFromXml() override;
287 
289 
297  bool useConditionalStyling() const;
298 
306  void setUseConditionalStyling( bool enabled );
307 
308  protected:
309 
310  bool writePropertiesToElement( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
311  bool readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context ) override;
312 
313  private slots:
314 
315  void disconnectCurrentMap();
316 
317  private:
318 
320  ContentSource mSource = LayerAttributes;
322  QgsVectorLayerRef mVectorLayer = nullptr;
323 
325  QPointer< QgsVectorLayer > mDataDefinedVectorLayer;
326 
328  QString mRelationId;
329 
331  QgsVectorLayer *mCurrentAtlasLayer = nullptr;
332 
334  QgsLayoutItemMap *mMap = nullptr;
335  QString mMapUuid;
336 
338  int mMaximumNumberOfFeatures = 30;
339 
341  bool mShowUniqueRowsOnly = false;
342 
344  bool mShowOnlyVisibleFeatures = false;
345 
347  bool mFilterToAtlasIntersection = false;
348 
350  bool mFilterFeatures = false;
351 
353  QString mFeatureFilter;
354 
355  QString mWrapString;
356 
357  bool mUseConditionalStyling = false;
358 
359  QList< QList< QgsConditionalStyle > > mConditionalStyles;
360  QList< QgsFeature > mFeatures;
361  QMap<QString, QVariant> mLayerCache;
362 
363  struct Cell
364  {
365  Cell() = default;
366 
367  Cell( const QVariant &content, const QgsConditionalStyle &style, const QgsFeature &feature )
368  : content( content )
369  , style( style )
370  , feature( feature ) {}
371  QVariant content;
372  QgsConditionalStyle style;
373  QgsFeature feature;
374  };
375 
380  QList<int> fieldsToDisplay() const;
381 
387  void restoreFieldAliasMap( const QMap<int, QString> &map );
388 
393  QVariant replaceWrapChar( const QVariant &variant ) const;
394 
395 #ifdef HAVE_SERVER_PYTHON_PLUGINS
396 
400  QgsLayoutTableColumns filteredColumns( );
401 #endif
402 
403  private slots:
405  void removeLayer( const QString &layerId );
406 
407  void atlasLayerChanged( QgsVectorLayer *layer );
408 
409 };
410 
411 #endif // QGSLAYOUTITEMATTRIBUTETABLE_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsLayoutMultiFrame::createExpressionContext
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgslayoutmultiframe.cpp:283
QgsLayoutTableColumns
QVector< QgsLayoutTableColumn > QgsLayoutTableColumns
List of column definitions for a QgsLayoutTable.
Definition: qgslayouttable.h:58
QgsLayoutTableContents
QVector< QgsLayoutTableRow > QgsLayoutTableContents
List of QgsLayoutTableRows, representing rows and column cell contents for a QgsLayoutTable.
Definition: qgslayouttable.h:47
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsLayoutMultiFrame::refreshDataDefinedProperty
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
Refreshes a data defined property for the multi frame by reevaluating the property's value and redraw...
Definition: qgslayoutmultiframe.cpp:242
QgsLayoutItemAttributeTable::featureFilter
QString featureFilter() const
Returns the current expression used to filter features for the table.
Definition: qgslayoutitemattributetable.h:236
QgsLayoutMultiFrame::finalizeRestoreFromXml
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
Definition: qgslayoutmultiframe.cpp:310
QgsLayoutItemAttributeTable::relationId
QString relationId() const
Returns the relation id which the table displays child features from.
Definition: qgslayoutitemattributetable.h:119
QgsLayoutTable::writePropertiesToElement
bool writePropertiesToElement(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores multiframe state within an XML DOM element.
Definition: qgslayouttable.cpp:70
QgsLayoutMultiFrame::icon
virtual QIcon icon() const
Returns the item's icon.
Definition: qgslayoutmultiframe.h:154
QgsConditionalStyle
Conditional styling for a rule.
Definition: qgsconditionalstyle.h:120
QgsLayoutItemAttributeTable::maximumNumberOfFeatures
int maximumNumberOfFeatures() const
Returns the maximum number of features to be shown by the table.
Definition: qgslayoutitemattributetable.h:158
QgsLayoutItemAttributeTable::uniqueRowsOnly
bool uniqueRowsOnly() const
Returns true if the table is set to show only unique rows.
Definition: qgslayoutitemattributetable.h:175
QgsLayoutTable::textFormatForCell
virtual QgsTextFormat textFormatForCell(int row, int column) const
Returns the text format to use for the cell at the specified row and column.
Definition: qgslayouttable.cpp:1467
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsLayoutTable::readPropertiesFromElement
bool readPropertiesFromElement(const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets multiframe state from a DOM element.
Definition: qgslayouttable.cpp:134
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
QgsLayoutObject::AllProperties
@ AllProperties
All properties for item.
Definition: qgslayoutobject.h:135
QgsLayoutMultiFrame::type
virtual int type() const =0
Returns unique multiframe type id.
qgslayouttable.h
QgsLayoutTable::scopeForCell
virtual QgsExpressionContextScope * scopeForCell(int row, int column) const
Creates a new QgsExpressionContextScope for the cell at row, column.
Definition: qgslayouttable.cpp:986
qgis_sip.h
QgsLayoutTable::getTableContents
virtual bool getTableContents(QgsLayoutTableContents &contents)=0
Fetches the contents used for the cells in the table.
QgsLayoutItemAttributeTable::ContentSource
ContentSource
Specifies the content source for the attribute table.
Definition: qgslayoutitemattributetable.h:43
QgsLayoutItemAttributeTable
A layout table subclass that displays attributes from a vector layer.
Definition: qgslayoutitemattributetable.h:34
QgsLayoutTable
A class to display a table in the print layout, and allow the table to span over multiple frames.
Definition: qgslayouttable.h:112
QgsLayoutItemAttributeTable::wrapString
QString wrapString() const
Returns the string used to wrap the contents of the table cells by.
Definition: qgslayoutitemattributetable.h:272
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:113
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:317
QgsLayoutItemAttributeTable::displayOnlyVisibleFeatures
bool displayOnlyVisibleFeatures() const
Returns true if the table is set to show only features visible on a corresponding map item.
Definition: qgslayoutitemattributetable.h:194
qgsvectorlayerref.h
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsLayoutItemAttributeTable::filterToAtlasFeature
bool filterToAtlasFeature() const
Returns true if the table is set to only show features which intersect the current atlas feature.
Definition: qgslayoutitemattributetable.h:210
QgsLayoutItemAttributeTable::AtlasFeature
@ AtlasFeature
Table shows attributes from the current atlas feature.
Definition: qgslayoutitemattributetable.h:46
QgsLayoutItemAttributeTable::filterFeatures
bool filterFeatures() const
Returns true if a feature filter is active on the attribute table.
Definition: qgslayoutitemattributetable.h:218
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
_LayerRef< QgsVectorLayer >
QgsLayoutTable::conditionalCellStyle
virtual QgsConditionalStyle conditionalCellStyle(int row, int column) const
Returns the conditional style to use for the cell at row, column.
Definition: qgslayouttable.cpp:994
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsLayoutMultiFrame::displayName
virtual QString displayName() const
Returns the multiframe display name.
Definition: qgslayoutmultiframe.cpp:273
QgsLayoutItemAttributeTable::source
ContentSource source() const
Returns the source for attributes shown in the table body.
Definition: qgslayoutitemattributetable.h:76
QgsLayoutItemAttributeTable::map
QgsLayoutItemMap * map() const
Returns the layout map whose extents are controlling the features shown in the table.
Definition: qgslayoutitemattributetable.h:144
QgsLayoutItemAttributeTable::vectorLayer
QgsVectorLayer * vectorLayer() const
Returns the vector layer the attribute table is currently using.
Definition: qgslayoutitemattributetable.h:103
QgsLayoutObject::DataDefinedProperty
DataDefinedProperty
Data defined properties for different item types.
Definition: qgslayoutobject.h:132