Class: QgsMapLayerProxyModel

A proxy model which provides an easy to use model to display the list of layers in widgets.

Class Hierarchy

Inheritance diagram of qgis.core.QgsMapLayerProxyModel

Base classes

QSortFilterProxyModel

QAbstractProxyModel

QAbstractItemModel

QObject

class qgis.core.QgsMapLayerProxyModel[source]

Bases: QSortFilterProxyModel

__init__(parent: QObject | None = None)

QgsMapLayerProxModel creates a proxy model with a QgsMapLayerModel as source model. It can be used to filter the layers list in a widget.

Parameters:

parent (Optional[QObject] = None)

Filter

alias of LayerFilter

acceptsLayer(self, layer: QgsMapLayer | None) bool[source]

Returns True if the proxy model accepts the specified map layer.

Added in version 3.8.

Parameters:

layer (Optional[QgsMapLayer])

Return type:

bool

exceptedLayerIds(self) List[str][source]

Returns the blocklist of layer IDs which are excluded from the model.

Return type:

List[str]

exceptedLayerList(self) List[QgsMapLayer]

Returns the blocklist of layers which are excluded from the model.

See also

layerAllowlist()

Return type:

List[QgsMapLayer]

excludedProviders(self) List[str][source]

Returns the blocklist of data providers which are excluded from the model.

Return type:

List[str]

filterString(self) str[source]

Returns the current filter string, if set.

Added in version 3.4.

Return type:

str

filters(self) Qgis.LayerFilters

Returns the filter flags which affect how layers are filtered within the model.

See also

setFilters()

Return type:

Qgis.LayerFilters

layerAllowlist(self) List[QgsMapLayer]

Returns the list of layers which are excluded from the model.

An empty list indicates that no filtering by allowlist should be performed.

Added in version 3.14.

Return type:

List[QgsMapLayer]

static layerMatchesFilters(layer: QgsMapLayer | None, filters: Qgis.LayerFilters | Qgis.LayerFilter) bool[source]

Returns if the layer matches the given filters

Added in version 3.14.

Parameters:
Return type:

bool

layerWhitelist(self) List[QgsMapLayer]

Returns the list of layers which are excluded from the model.

An empty list indicates that no filtering by allowlist should be performed.

Deprecated since version 3.40: Use layerAllowlist() instead.

Return type:

List[QgsMapLayer]

setExceptedLayerIds(self, ids: Iterable[str | None])[source]

Sets a blocklist of layers (by layer ID) to exclude from the model.

Parameters:

ids (Iterable[Optional[str]])

setExceptedLayerList(self, exceptList: Iterable[QgsMapLayer])[source]

Sets a blocklist of layers to exclude from the model.

Parameters:

exceptList (Iterable[QgsMapLayer])

setExcludedProviders(self, providers: Iterable[str | None])[source]

Sets a blocklist of data providers which should be excluded from the model.

Parameters:

providers (Iterable[Optional[str]])

setFilterString(self, filter: str | None)[source]

Sets a filter string, such that only layers with names matching the specified string will be shown.

See also

filterString()

Added in version 3.4.

Parameters:

filter (Optional[str])

setFilters(self, filters: Qgis.LayerFilters | Qgis.LayerFilter) QgsMapLayerProxyModel | None[source]

Sets filter flags which affect how layers are filtered within the model.

See also

filters()

setFilters(self, filters: int) Filters according to layer type and/or geometry type.

Note

for API compatibility

Added in version 3.34.

Deprecated since version 3.34: Use the flag signature instead.

Parameters:

filters (Union[Qgis.LayerFilters, Qgis.LayerFilter])

Return type:

Optional[QgsMapLayerProxyModel]

setLayerAllowlist(self, layers: Iterable[QgsMapLayer])[source]

Sets an allowlist of layers to include within the model. Only layers from this list will be shown.

An empty list indicates that no filter by allowlist should be performed.

See also

layerAllowlist()

Added in version 3.14.

Parameters:

layers (Iterable[QgsMapLayer])

setLayerWhitelist(self, layers: Iterable[QgsMapLayer])[source]

Sets an allowlist of layers to include within the model. Only layers from this list will be shown.

An empty list indicates that no filter by allowlist should be performed.

See also

layerAllowlist()

Deprecated since version 3.40: Use setLayerAllowList().

Parameters:

layers (Iterable[QgsMapLayer])

setProject(self, project: QgsProject | None)[source]

Sets the project from which map layers are shown.

If project is None then QgsProject.instance() will be used.

Added in version 3.24.

Parameters:

project (Optional[QgsProject])

sourceLayerModel(self) QgsMapLayerModel | None[source]

layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel

Return type:

Optional[QgsMapLayerModel]