Class: QgsLayerTreeFilterProxyModel

class qgis.core.QgsLayerTreeFilterProxyModel

Bases: PyQt5.QtCore.QSortFilterProxyModel

QgsLayerTreeFilterProxyModel is a sort filter proxy model to easily reproduce the legend/layer tree in a tree view.

Layers are checkable by default. Symbology nodes will not be shown. Layers can be filtered by their type.

For more complex use-cases, the model can be re-implemented to allow a different interaction or to add more columns.

New in version 3.14.

QgsLayerTreeFilterProxyModel(parent: QObject = None) Constructor

Methods

beginInsertColumns

beginInsertRows

beginMoveColumns

beginMoveRows

beginRemoveColumns

beginRemoveRows

beginResetModel

changePersistentIndex

changePersistentIndexList

checkedLayers

Returns the checked layers

childEvent

columnCount

param parent

connectNotify

createIndex

customEvent

data

param index

decodeData

disconnectNotify

encodeData

endInsertColumns

endInsertRows

endMoveColumns

endMoveRows

endRemoveColumns

endRemoveRows

endResetModel

filterAcceptsColumn

filterAcceptsRow

param sourceRow

flags

param idx

index

param row

invalidateFilter

isLayerChecked

Returns if the layer is checked or not

isSignalConnected

layerTreeModel

Rerturns the layer tree model

lessThan

mapLayer

Returns the map layer at a given index

parent

param child

persistentIndexList

receivers

resetInternalData

sender

senderSignalIndex

setCheckedLayers

Initialize the list of checked layers.

setData

param index

setFilterText

Sets the filter text to search for a layer in the tree

setFilters

Defines the type layers (vector, raster, etc) shown in the tree If the list is empty, all types are shown.

setLayerChecked

This will set if the layer is checked or not

setLayerTreeModel

Sets the layer tree model

sibling

param row

timerEvent

QgsLayerTreeFilterProxyModel.beginInsertColumns(self, QModelIndex, int, int)
QgsLayerTreeFilterProxyModel.beginInsertRows(self, QModelIndex, int, int)
QgsLayerTreeFilterProxyModel.beginMoveColumns(self, QModelIndex, int, int, QModelIndex, int) -> bool
QgsLayerTreeFilterProxyModel.beginMoveRows(self, QModelIndex, int, int, QModelIndex, int) -> bool
QgsLayerTreeFilterProxyModel.beginRemoveColumns(self, QModelIndex, int, int)
QgsLayerTreeFilterProxyModel.beginRemoveRows(self, QModelIndex, int, int)
beginResetModel(self)
QgsLayerTreeFilterProxyModel.changePersistentIndex(self, QModelIndex, QModelIndex)
changePersistentIndexList(self, Iterable[QModelIndex], Iterable[QModelIndex])
checkedLayers(self)List[QgsMapLayer]

Returns the checked layers

Return type

List[QgsMapLayer]

childEvent(self, QChildEvent)
columnCount(self, parent: QModelIndex)int
Parameters

parent (QModelIndex) –

Return type

int

connectNotify(self, QMetaMethod)
QgsLayerTreeFilterProxyModel.createIndex(self, int, int, object: object = 0) -> QModelIndex
customEvent(self, QEvent)
data(self, index: QModelIndex, role: int)Any
Parameters
  • index (QModelIndex) –

  • role (int) –

Return type

Any

QgsLayerTreeFilterProxyModel.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)
filterAcceptsColumn(self, int, QModelIndex)bool
filterAcceptsRow(self, sourceRow: int, sourceParent: QModelIndex)bool
Parameters
  • sourceRow (int) –

  • sourceParent (QModelIndex) –

Return type

bool

flags(self, idx: QModelIndex)Qt.ItemFlags
Parameters

idx (QModelIndex) –

Return type

Qt.ItemFlags

index(self, row: int, column: int, parent: QModelIndex = QModelIndex())QModelIndex
Parameters
  • row (int) –

  • column (int) –

  • parent (QModelIndex = QModelIndex()) –

Return type

QModelIndex

invalidateFilter(self)
isLayerChecked(self, layer: QgsMapLayer)bool

Returns if the layer is checked or not

Parameters

layer (QgsMapLayer) –

Return type

bool

isSignalConnected(self, QMetaMethod)bool
layerTreeModel(self)QgsLayerTreeModel

Rerturns the layer tree model

Return type

QgsLayerTreeModel

QgsLayerTreeFilterProxyModel.lessThan(self, QModelIndex, QModelIndex) -> bool
mapLayer(self, idx: QModelIndex)QgsMapLayer

Returns the map layer at a given index

Parameters

idx (QModelIndex) –

Return type

QgsMapLayer

parent(self, child: QModelIndex)QModelIndex
Parameters

child (QModelIndex) –

Return type

QModelIndex

persistentIndexList(self)List[QModelIndex]
receivers(self, PYQT_SIGNAL)int
resetInternalData(self)
sender(self)QObject
senderSignalIndex(self)int
setCheckedLayers(self, layers: Iterable[QgsMapLayer])

Initialize the list of checked layers.

Note

If the model is re-implemented, this method might become useless

Parameters

layers (Iterable[QgsMapLayer]) –

setData(self, index: QModelIndex, value: Any, role: int)bool
Parameters
  • index (QModelIndex) –

  • value (Any) –

  • role (int) –

Return type

bool

setFilterText(self, filterText: str = '')

Sets the filter text to search for a layer in the tree

Parameters

filterText (str = '') –

setFilters(self, filters: Union[QgsMapLayerProxyModel.Filters, QgsMapLayerProxyModel.Filter])

Defines the type layers (vector, raster, etc) shown in the tree If the list is empty, all types are shown.

Parameters

filters (Union[QgsMapLayerProxyModel.Filters) –

setLayerChecked(self, layer: QgsMapLayer, checked: bool)

This will set if the layer is checked or not

Parameters
setLayerTreeModel(self, layerTreeModel: QgsLayerTreeModel)

Sets the layer tree model

Parameters

layerTreeModel (QgsLayerTreeModel) –

sibling(self, row: int, column: int, idx: QModelIndex)QModelIndex
Parameters
  • row (int) –

  • column (int) –

  • idx (QModelIndex) –

Return type

QModelIndex

timerEvent(self, QTimerEvent)