Class: QgsLayerTreeFilterSettings

class qgis.core.QgsLayerTreeFilterSettings

Bases: sip.wrapper

Contains settings relating to filtering the contents of QgsLayerTreeModel and views.

New in version 3.32.

QgsLayerTreeFilterSettings(settings: QgsMapSettings) Constructor for QgsLayerTreeFilterSettings, using the specified map settings.

QgsLayerTreeFilterSettings(other: QgsLayerTreeFilterSettings) Copy constructor.

Methods

addVisibleExtentForLayer

Adds a visible extent polygon for a map layer.

combinedVisibleExtentForLayer

Returns the combined visible extent for a layer.

filterPolygon

Returns the optional filter polygon, used when testing for symbols to show in the legend.

flags

Returns the filter flags.

layerFilterExpression

Returns the filter expression to use for the layer with the specified layerId, or an empty string if no expression is set for the layer.

layerFilterExpressions

Returns the map of layer IDs to legend filter expression.

layers

Returns the layers which should be shown in the legend.

mapSettings

Returns the map settings used to filter the legend content.

setFilterPolygon

Sets the optional filter polygon, used when testing for symbols to show in the legend.

setFlags

Sets the filter flags.

setLayerFilterExpressions

Sets the map of layer IDs to legend filter expression.

setLayerFilterExpressionsFromLayerTree

Sets layer filter expressions using a layer tree.

addVisibleExtentForLayer(self, layer: QgsMapLayer, polygon: QgsReferencedGeometry)

Adds a visible extent polygon for a map layer.

If layer is already included in the layers contained within mapSettings() (or previously added by calling this method) then this polygon extent will be unioned with the existing extent.

The layer will be appended to the list of layers to use during the legend hit test. (See layers()).

Parameters:
combinedVisibleExtentForLayer(self, layer: QgsMapLayer) QgsGeometry

Returns the combined visible extent for a layer.

The combined visible extent includes:

The returned geometry will always be in the layer’s CRS.

Parameters:

layer (QgsMapLayer) –

Return type:

QgsGeometry

filterPolygon(self) QgsGeometry

Returns the optional filter polygon, used when testing for symbols to show in the legend.

The CRS of the polygon will match the destination CRS of mapSettings().

If not set then the filter visibility extent will use the extent of mapSettings().

Return type:

QgsGeometry

flags(self) Qgis.LayerTreeFilterFlags

Returns the filter flags.

See also

setFlags()

Return type:

Qgis.LayerTreeFilterFlags

layerFilterExpression(self, layerId: str) str

Returns the filter expression to use for the layer with the specified layerId, or an empty string if no expression is set for the layer.

Parameters:

layerId (str) –

Return type:

str

layerFilterExpressions(self) Dict[str, str]

Returns the map of layer IDs to legend filter expression.

Return type:

Dict[str, str]

layers(self) List[QgsMapLayer]

Returns the layers which should be shown in the legend.

This includes all layers from the mapSettings() and any additional layers added by calls to addVisibleExtentForLayer().

Return type:

List[QgsMapLayer]

mapSettings(self) QgsMapSettings

Returns the map settings used to filter the legend content.

Return type:

QgsMapSettings

setFilterPolygon(self, polygon: QgsGeometry)

Sets the optional filter polygon, used when testing for symbols to show in the legend.

The CRS of the polygon must match the destination CRS of mapSettings().

If not set then the filter visibility extent will use the extent of mapSettings().

See also

filterPolygon()

Parameters:

polygon (QgsGeometry) –

setFlags(self, flags: Qgis.LayerTreeFilterFlags | Qgis.LayerTreeFilterFlag)

Sets the filter flags.

See also

flags()

Parameters:

flags (Union[Qgis.LayerTreeFilterFlags) –

setLayerFilterExpressions(self, expressions: Dict[str, str])

Sets the map of layer IDs to legend filter expression.

Parameters:

expressions (Dict[str) –

setLayerFilterExpressionsFromLayerTree(self, tree: QgsLayerTree)

Sets layer filter expressions using a layer tree.

Parameters:

tree (QgsLayerTree) –