QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
47
54
55 int type() const override;
56 QIcon icon() const override;
57 QString displayName() const override;
58
62 static QgsLayoutItemAttributeTable *create( QgsLayout *layout ) SIP_FACTORY;
63
68 void setSource( ContentSource source );
69
74 ContentSource source() const { return mSource; }
75
82 QgsVectorLayer *sourceLayer() const;
83
91 void setVectorLayer( QgsVectorLayer *layer );
92
101 QgsVectorLayer *vectorLayer() const { return mVectorLayer.get(); }
102
109 void setRelationId( const QString &id );
110
117 QString relationId() const { return mRelationId; }
118
123 void resetColumns();
124
134 void setMap( QgsLayoutItemMap *map );
135
142 QgsLayoutItemMap *map() const { return mMap; }
143
150 void setMaximumNumberOfFeatures( int features );
151
156 int maximumNumberOfFeatures() const { return mMaximumNumberOfFeatures; }
157
166 void setUniqueRowsOnly( bool uniqueOnly );
167
173 bool uniqueRowsOnly() const { return mShowUniqueRowsOnly; }
174
183 void setDisplayOnlyVisibleFeatures( bool visibleOnly );
184
192 bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }
193
200 void setFilterToAtlasFeature( bool filterToAtlas );
201
208 bool filterToAtlasFeature() const { return mFilterToAtlasIntersection; }
209
216 bool filterFeatures() const { return mFilterFeatures; }
217
225 void setFilterFeatures( bool filter );
226
234 QString featureFilter() const { return mFeatureFilter; }
235
245 void setFeatureFilter( const QString &expression );
246
255 void setDisplayedFields( const QStringList &fields, bool refresh = true );
256
263 void setWrapString( const QString &wrapString );
264
270 QString wrapString() const { return mWrapString; }
271
277 bool getTableContents( QgsLayoutTableContents &contents ) override;
278
279 QgsConditionalStyle conditionalCellStyle( int row, int column ) const override;
280 QgsTextFormat textFormatForCell( int row, int column ) const override;
281 QgsExpressionContextScope *scopeForCell( int row, int column ) const override SIP_FACTORY;
282
284 void finalizeRestoreFromXml() override;
285
287
295 bool useConditionalStyling() const;
296
304 void setUseConditionalStyling( bool enabled );
305
306 protected:
307 bool writePropertiesToElement( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
308 bool readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context ) override;
309
310 private slots:
311
312 void disconnectCurrentMap();
313
314 private:
316 ContentSource mSource = LayerAttributes;
318 QgsVectorLayerRef mVectorLayer = nullptr;
319
321 QPointer< QgsVectorLayer > mDataDefinedVectorLayer;
322
324 QString mRelationId;
325
327 QgsVectorLayer *mCurrentAtlasLayer = nullptr;
328
330 QPointer< QgsLayoutItemMap > mMap = nullptr;
331 QString mMapUuid;
332
334 int mMaximumNumberOfFeatures = 30;
335
337 bool mShowUniqueRowsOnly = false;
338
340 bool mShowOnlyVisibleFeatures = false;
341
343 bool mFilterToAtlasIntersection = false;
344
346 bool mFilterFeatures = false;
347
349 QString mFeatureFilter;
350
351 QString mWrapString;
352
353 bool mUseConditionalStyling = false;
354
355 QList< QList< QgsConditionalStyle > > mConditionalStyles;
356 QList< QgsFeature > mFeatures;
357 QMap<QString, QVariant> mLayerCache;
358
359 struct Cell
360 {
361 Cell() = default;
362
363 Cell( const QVariant &content, const QgsConditionalStyle &style, const QgsFeature &feature )
364 : content( content )
365 , style( style )
366 , feature( feature )
367 {}
368 QVariant content;
369 QgsConditionalStyle style;
370 QgsFeature feature;
371 };
372
377 QList<int> fieldsToDisplay() const;
378
384 void restoreFieldAliasMap( const QMap<int, QString> &map );
385
390 QVariant replaceWrapChar( const QVariant &variant ) const;
391
392#ifdef HAVE_SERVER_PYTHON_PLUGINS
393
397 QgsLayoutTableColumns filteredColumns();
398#endif
399
400 private slots:
402 void removeLayer( const QString &layerId );
403
404 void atlasLayerChanged( QgsVectorLayer *layer );
405};
406
407#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:60
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.
@ RelationChildren
Table shows attributes from related child features.
@ LayerAttributes
Table shows attributes from features in a vector layer.
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.
QgsLayoutItemAttributeTable(QgsLayout *layout)
Constructor for QgsLayoutItemAttributeTable, attached to the specified layout.
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.
QgsLayoutTable(QgsLayout *layout)
Constructor for QgsLayoutTable, belonging to the specified layout.
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:50
A container for the context for various read/write operations on objects.
Container for all settings relating to text rendering.
Represents a vector layer which manages a vector based dataset.
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:52
#define SIP_FACTORY
Definition qgis_sip.h:83
_LayerRef< QgsVectorLayer > QgsVectorLayerRef