Class: QgsMapLayerProxyModel

class qgis.core.QgsMapLayerProxyModel

Bases: PyQt5.QtCore.QSortFilterProxyModel

The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widgets.

QgsMapLayerProxyModel(parent: QObject = None) QgsMapLayerProxModel creates a proxy model with a QgsMapLayerModel as source model. It can be used to filter the layers list in a widget.

Enums

Filter

alias of LayerFilter

Methods

acceptsLayer

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

beginInsertColumns

beginInsertRows

beginMoveColumns

beginMoveRows

beginRemoveColumns

beginRemoveRows

beginResetModel

changePersistentIndex

changePersistentIndexList

childEvent

connectNotify

createIndex

customEvent

decodeData

disconnectNotify

encodeData

endInsertColumns

endInsertRows

endMoveColumns

endMoveRows

endRemoveColumns

endRemoveRows

endResetModel

exceptedLayerIds

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

exceptedLayerList

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

excludedProviders

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

filterAcceptsColumn

filterAcceptsRow

param source_row:

filterString

Returns the current filter string, if set.

filters

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

invalidateFilter

isSignalConnected

layerAllowlist

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

layerMatchesFilters

Returns if the layer matches the given filters

layerWhitelist

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

lessThan

param left:

persistentIndexList

receivers

resetInternalData

sender

senderSignalIndex

setExceptedLayerIds

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

setExceptedLayerList

Sets a blocklist of layers to exclude from the model.

setExcludedProviders

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

setFilterString

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

setFilters

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

setLayerAllowlist

Sets an allowlist of layers to include within the model.

setLayerWhitelist

Sets an allowlist of layers to include within the model.

setProject

Sets the project from which map layers are shown.

sourceLayerModel

layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel

timerEvent

Filter

alias of LayerFilter

acceptsLayer(self, layer: QgsMapLayer) bool

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

New in version 3.8.

Parameters:

layer (QgsMapLayer) –

Return type:

bool

beginInsertColumns(self, QModelIndex, int, int)
beginInsertRows(self, QModelIndex, int, int)
beginMoveColumns(self, QModelIndex, int, int, QModelIndex, int) bool
beginMoveRows(self, QModelIndex, int, int, QModelIndex, int) bool
beginRemoveColumns(self, QModelIndex, int, int)
beginRemoveRows(self, QModelIndex, int, int)
beginResetModel(self)
changePersistentIndex(self, QModelIndex, QModelIndex)
changePersistentIndexList(self, Iterable[QModelIndex], Iterable[QModelIndex])
childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
createIndex(self, int, int, object: object = 0) QModelIndex
customEvent(self, QEvent)
decodeData(self, int, int, QModelIndex, QDataStream) bool
disconnectNotify(self, QMetaMethod)
encodeData(self, Iterable[QModelIndex], QDataStream)
endInsertColumns(self)
endInsertRows(self)
endMoveColumns(self)
endMoveRows(self)
endRemoveColumns(self)
endRemoveRows(self)
endResetModel(self)
exceptedLayerIds(self) List[str]

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]

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

Return type:

List[str]

filterAcceptsColumn(self, int, QModelIndex) bool
filterAcceptsRow(self, source_row: int, source_parent: QModelIndex) bool
Parameters:
  • source_row (int) –

  • source_parent (QModelIndex) –

Return type:

bool

filterString(self) str

Returns the current filter string, if set.

New 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

invalidateFilter(self)
isSignalConnected(self, QMetaMethod) bool
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.

New in version 3.14.

Return type:

List[QgsMapLayer]

layerMatchesFilters(layer: QgsMapLayer, filters: Qgis.LayerFilters | Qgis.LayerFilter) bool

Returns if the layer matches the given filters

New 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 use: layerAllowlist() instead

Return type:

List[QgsMapLayer]

lessThan(self, left: QModelIndex, right: QModelIndex) bool
Parameters:
  • left (QModelIndex) –

  • right (QModelIndex) –

Return type:

bool

persistentIndexList(self) List[QModelIndex]
receivers(self, PYQT_SIGNAL) int
resetInternalData(self)
sender(self) QObject
senderSignalIndex(self) int
setExceptedLayerIds(self, ids: Iterable[str])

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

Parameters:

ids (Iterable[str]) –

setExceptedLayerList(self, exceptList: Iterable[QgsMapLayer])

Sets a blocklist of layers to exclude from the model.

Parameters:

exceptList (Iterable[QgsMapLayer]) –

setExcludedProviders(self, providers: Iterable[str])

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

Parameters:

providers (Iterable[str]) –

setFilterString(self, filter: str)

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

See also

filterString()

New in version 3.4.

Parameters:

filter (str) –

setFilters(self, filters: Qgis.LayerFilters | Qgis.LayerFilter) QgsMapLayerProxyModel

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

New in version 3.34.

Deprecated since version QGIS: 3.34 use the flag signature instead

Parameters:

filters (Union[Qgis.LayerFilters) –

Return type:

QgsMapLayerProxyModel

setLayerAllowlist(self, layers: Iterable[QgsMapLayer])

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()

New in version 3.14.

Parameters:

layers (Iterable[QgsMapLayer]) –

setLayerWhitelist(self, layers: Iterable[QgsMapLayer])

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 use: setLayerAllowList()

Parameters:

layers (Iterable[QgsMapLayer]) –

setProject(self, project: QgsProject)

Sets the project from which map layers are shown.

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

New in version 3.24.

Parameters:

project (QgsProject) –

sourceLayerModel(self) QgsMapLayerModel

layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel

Return type:

QgsMapLayerModel

timerEvent(self, QTimerEvent)