28using namespace Qt::StringLiterals;
33 mLayers = _qgis_listRawToQPointer( mMapSettings->layers(
true ) );
39 : mLayerFilterExpressions( other.mLayerFilterExpressions )
40 , mMapSettings( other.mMapSettings ? new
QgsMapSettings( *other.mMapSettings ) : nullptr )
41 , mFilterPolygon( other.mFilterPolygon )
42 , mFlags( other.mFlags )
43 , mLayers( other.mLayers )
44 , mLayerExtents( other.mLayerExtents )
54 mLayerFilterExpressions = other.mLayerFilterExpressions;
55 mMapSettings.reset( other.mMapSettings ?
new QgsMapSettings( *other.mMapSettings ) :
nullptr );
56 mFilterPolygon = other.mFilterPolygon;
57 mFlags = other.mFlags;
58 mLayers = other.mLayers;
59 mLayerExtents = other.mLayerExtents;
65 return *mMapSettings.get();
70 return mLayerFilterExpressions;
75 mLayerFilterExpressions = expressions;
80 QMap<QString, QString> legendFilterExpressions;
86 if ( enabled && !legendFilterExpression.isEmpty() )
88 legendFilterExpressions[nodeLayer->layerId()] = legendFilterExpression;
91 mLayerFilterExpressions = legendFilterExpressions;
96 return mLayerFilterExpressions.value( layerId );
101 return mFilterPolygon;
106 mFilterPolygon = newFilterPolygon;
125 transformedPoly.
transform( polygonToLayerTransform );
126 mLayerExtents[ layer->
id() ].append( transformedPoly );
130 QgsDebugError( u
"Error transforming polygon to layer CRS for legend filtering"_s );
132 if ( !mLayers.contains( layer ) )
138 QVector< QgsGeometry > parts;
140 if ( mMapSettings->layerIds(
true ).contains( layer->
id() ) )
157 QgsDebugError( u
"Error transforming map extent to layer CRS for legend filtering"_s );
161 auto additionalIt = mLayerExtents.constFind( layer->
id() );
162 if ( additionalIt != mLayerExtents.constEnd() )
164 parts.append( additionalIt.value() );
167 if ( !parts.empty() )
175 return _qgis_listQPointerToRaw( mLayers );
QFlags< LayerTreeFilterFlag > LayerTreeFilterFlags
Layer tree filter flags.
@ Reverse
Reverse/inverse transform (from destination to source).
Custom exception class for Coordinate Reference System related exceptions.
A geometry is the spatial representation of a feature.
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries, const QgsGeometryParameters ¶meters=QgsGeometryParameters())
Compute the unary union on a list of geometries.
QgsMapSettings & mapSettings()
Returns the map settings used to filter the legend content.
QgsGeometry filterPolygon() const
Returns the optional filter polygon, used when testing for symbols to show in the legend.
void addVisibleExtentForLayer(QgsMapLayer *layer, const QgsReferencedGeometry &polygon)
Adds a visible extent polygon for a map layer.
QString layerFilterExpression(const QString &layerId) const
Returns the filter expression to use for the layer with the specified layerId, or an empty string if ...
QList< QgsMapLayer * > layers() const
Returns the layers which should be shown in the legend.
Qgis::LayerTreeFilterFlags flags() const
Returns the filter flags.
QMap< QString, QString > layerFilterExpressions() const
Returns the map of layer IDs to legend filter expression.
~QgsLayerTreeFilterSettings()
void setFilterPolygon(const QgsGeometry &polygon)
Sets the optional filter polygon, used when testing for symbols to show in the legend.
void setLayerFilterExpressionsFromLayerTree(QgsLayerTree *tree)
Sets layer filter expressions using a layer tree.
QgsLayerTreeFilterSettings(const QgsMapSettings &settings)
Constructor for QgsLayerTreeFilterSettings, using the specified map settings.
void setFlags(Qgis::LayerTreeFilterFlags flags)
Sets the filter flags.
void setLayerFilterExpressions(const QMap< QString, QString > &expressions)
Sets the map of layer IDs to legend filter expression.
QgsLayerTreeFilterSettings & operator=(const QgsLayerTreeFilterSettings &other)
QgsGeometry combinedVisibleExtentForLayer(const QgsMapLayer *layer)
Returns the combined visible extent for a layer.
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes.
Layer tree node points to a map layer.
static QString legendFilterByExpression(const QgsLayerTreeLayer &layer, bool *enabled=nullptr)
Returns the expression filter of a legend layer.
Namespace with helper functions for layer tree operations.
Base class for all map layer types.
QgsCoordinateReferenceSystem crs
Contains configuration for rendering maps.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsGeometry with associated coordinate reference system.
#define QgsDebugError(str)