QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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 "qgslayoutitemmap.h"
24#include "qgslayouttable.h"
25#include "qgsvectorlayerref.h"
26
27class QgsVectorLayer;
28
34{
35 Q_OBJECT
36
37 public:
38
43 {
44 LayerAttributes = 0,
46 RelationChildren
47 };
48
55
56 int type() const override;
57 QIcon icon() const override;
58 QString displayName() const override;
59
63 static QgsLayoutItemAttributeTable *create( QgsLayout *layout ) SIP_FACTORY;
64
69 void setSource( ContentSource source );
70
75 ContentSource source() const { return mSource; }
76
83 QgsVectorLayer *sourceLayer() const;
84
92 void setVectorLayer( QgsVectorLayer *layer );
93
102 QgsVectorLayer *vectorLayer() const { return mVectorLayer.get(); }
103
110 void setRelationId( const QString &id );
111
118 QString relationId() const { return mRelationId; }
119
124 void resetColumns();
125
135 void setMap( QgsLayoutItemMap *map );
136
143 QgsLayoutItemMap *map() const { return mMap; }
144
151 void setMaximumNumberOfFeatures( int features );
152
157 int maximumNumberOfFeatures() const { return mMaximumNumberOfFeatures; }
158
167 void setUniqueRowsOnly( bool uniqueOnly );
168
174 bool uniqueRowsOnly() const { return mShowUniqueRowsOnly; }
175
184 void setDisplayOnlyVisibleFeatures( bool visibleOnly );
185
193 bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }
194
201 void setFilterToAtlasFeature( bool filterToAtlas );
202
209 bool filterToAtlasFeature() const { return mFilterToAtlasIntersection; }
210
217 bool filterFeatures() const { return mFilterFeatures; }
218
226 void setFilterFeatures( bool filter );
227
235 QString featureFilter() const { return mFeatureFilter; }
236
246 void setFeatureFilter( const QString &expression );
247
256 void setDisplayedFields( const QStringList &fields, bool refresh = true );
257
264 void setWrapString( const QString &wrapString );
265
271 QString wrapString() const { return mWrapString; }
272
278 bool getTableContents( QgsLayoutTableContents &contents ) override;
279
280 QgsConditionalStyle conditionalCellStyle( int row, int column ) const override;
281 QgsTextFormat textFormatForCell( int row, int column ) const override;
282 QgsExpressionContextScope *scopeForCell( int row, int column ) const override SIP_FACTORY;
283
285 void finalizeRestoreFromXml() override;
286
288
296 bool useConditionalStyling() const;
297
305 void setUseConditionalStyling( bool enabled );
306
307 protected:
308
309 bool writePropertiesToElement( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
310 bool readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context ) override;
311
312 private slots:
313
314 void disconnectCurrentMap();
315
316 private:
317
319 ContentSource mSource = LayerAttributes;
321 QgsVectorLayerRef mVectorLayer = nullptr;
322
324 QPointer< QgsVectorLayer > mDataDefinedVectorLayer;
325
327 QString mRelationId;
328
330 QgsVectorLayer *mCurrentAtlasLayer = nullptr;
331
333 QPointer< QgsLayoutItemMap > mMap = nullptr;
334 QString mMapUuid;
335
337 int mMaximumNumberOfFeatures = 30;
338
340 bool mShowUniqueRowsOnly = false;
341
343 bool mShowOnlyVisibleFeatures = false;
344
346 bool mFilterToAtlasIntersection = false;
347
349 bool mFilterFeatures = false;
350
352 QString mFeatureFilter;
353
354 QString mWrapString;
355
356 bool mUseConditionalStyling = false;
357
358 QList< QList< QgsConditionalStyle > > mConditionalStyles;
359 QList< QgsFeature > mFeatures;
360 QMap<QString, QVariant> mLayerCache;
361
362 struct Cell
363 {
364 Cell() = default;
365
366 Cell( const QVariant &content, const QgsConditionalStyle &style, const QgsFeature &feature )
367 : content( content )
368 , style( style )
369 , feature( feature ) {}
370 QVariant content;
372 QgsFeature feature;
373 };
374
379 QList<int> fieldsToDisplay() const;
380
386 void restoreFieldAliasMap( const QMap<int, QString> &map );
387
392 QVariant replaceWrapChar( const QVariant &variant ) const;
393
394#ifdef HAVE_SERVER_PYTHON_PLUGINS
395
399 QgsLayoutTableColumns filteredColumns( );
400#endif
401
402 private slots:
404 void removeLayer( const QString &layerId );
405
406 void atlasLayerChanged( QgsVectorLayer *layer );
407
408};
409
410#endif // QGSLAYOUTITEMATTRIBUTETABLE_H
Conditional styling for a rule.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
A layout table subclass that displays attributes from a vector layer.
QString wrapString() const
Returns the string used to wrap the contents of the table cells by.
ContentSource
Specifies the content source for the attribute table.
@ AtlasFeature
Table shows attributes from the current atlas feature.
QgsVectorLayer * vectorLayer() const
Returns the vector layer the attribute table is currently using.
QString featureFilter() const
Returns the current expression used to filter features for the table.
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 map item.
bool filterToAtlasFeature() const
Returns true if the table is set to only show features which intersect the current atlas feature.
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.
bool filterFeatures() const
Returns true if a feature filter is active on the attribute table.
int maximumNumberOfFeatures() const
Returns the maximum number of features to be shown by the table.
bool uniqueRowsOnly() const
Returns true if the table is set to show only unique rows.
Layout graphical items for displaying a map.
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
virtual int type() const =0
Returns unique multiframe type id.
virtual QIcon icon() const
Returns the item's icon.
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties)
Refreshes a data defined property for the multi frame by reevaluating the property's value and redraw...
virtual QString displayName() const
Returns the multiframe display name.
DataDefinedProperty
Data defined properties for different item types.
@ AllProperties
All properties for item.
A class to display a table in the print layout, and allow the table to span over multiple frames.
virtual QgsConditionalStyle conditionalCellStyle(int row, int column) const
Returns the conditional style to use for the cell at row, column.
virtual QgsExpressionContextScope * scopeForCell(int row, int column) const
Creates a new QgsExpressionContextScope for the cell at row, column.
virtual bool getTableContents(QgsLayoutTableContents &contents)=0
Fetches the contents used for the cells in the table.
bool writePropertiesToElement(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores multiframe state within an XML DOM element.
virtual QgsTextFormat textFormatForCell(int row, int column) const
Returns the text format to use for the cell at the specified row and column.
bool readPropertiesFromElement(const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets multiframe state from a DOM element.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
The class is used as a container of context for various read/write operations on other objects.
Container for all settings relating to text rendering.
Represents a vector layer which manages a vector based data sets.
QVector< QgsLayoutTableColumn > QgsLayoutTableColumns
List of column definitions for a QgsLayoutTable.
QVector< QgsLayoutTableRow > QgsLayoutTableContents
List of QgsLayoutTableRows, representing rows and column cell contents for a QgsLayoutTable.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_FACTORY
Definition qgis_sip.h:76