Class: QgsMapLayerModel

class qgis.core.QgsMapLayerModel(parent: QObject = None)

Bases: PyQt5.QtCore.QAbstractItemModel

QgsMapLayerModel creates a model to display layers in widgets.

QgsMapLayerModel(layers: Iterable[QgsMapLayer], parent: QObject = None) QgsMapLayerModel creates a model to display a specific list of layers in a widget.

The QgsMapLayerModel class is a model to display layers in widgets.

See also

QgsFieldModel

New in version 2.3: Enums

Methods

addLayers

additionalItems

Returns the list of additional (non map layer) items included at the end of the model.

allowEmptyLayer

Returns true if the model allows the empty layer (“not set”) choice.

beginInsertColumns

beginInsertRows

beginMoveColumns

beginMoveRows

beginRemoveColumns

beginRemoveRows

beginResetModel

changePersistentIndex

changePersistentIndexList

checkAll

checkAll changes the checkstate for all the layers

childEvent

columnCount

connectNotify

createIndex

customEvent

data

decodeData

disconnectNotify

encodeData

endInsertColumns

endInsertRows

endMoveColumns

endMoveRows

endRemoveColumns

endRemoveRows

endResetModel

flags

iconForLayer

Returns the icon corresponding to a specified map layer.

index

indexFromLayer

indexFromLayer returns the model index for a given layer

isSignalConnected

itemsCheckable

returns if the items can be checked or not

layerFromIndex

Returns the map layer corresponding to the specified index.

layersChecked

layersChecked returns the list of layers which are checked (or unchecked)

parent

persistentIndexList

receivers

removeLayers

resetInternalData

rowCount

sender

senderSignalIndex

setAdditionalItems

Sets a list of additional (non map layer) items to include at the end of the model.

setAllowEmptyLayer

Sets whether an optional empty layer (“not set”) option is present in the model.

setData

setItemsCheckable

setItemsCheckable defines if layers should be selectable in the widget

setShowCrs

Sets whether the CRS of layers is also included in the model’s display role.

showCrs

Returns true if the model includes layer’s CRS in the display role.

timerEvent

Signals

Attributes

AdditionalRole

EmptyRole

LayerIdRole

LayerRole

AdditionalRole = 260
EmptyRole = 259
class ItemDataRole

Bases: int

LayerIdRole = 257
LayerRole = 258
addLayers(self, layers: Iterable[QgsMapLayer])
additionalItems(self) → List[str]

Returns the list of additional (non map layer) items included at the end of the model.

New in version 3.0.

allowEmptyLayer(self) → bool

Returns true if the model allows the empty layer (“not set”) choice.

New in version 3.0.

beginInsertColumns()
beginInsertRows()
beginMoveColumns()
beginMoveRows()
beginRemoveColumns()
beginRemoveRows()
beginResetModel()
changePersistentIndex()
changePersistentIndexList()
checkAll(self, checkState: Qt.CheckState)

checkAll changes the checkstate for all the layers

childEvent()
columnCount(self, parent: QModelIndex = QModelIndex()) → int
connectNotify()
createIndex()
customEvent()
data(self, index: QModelIndex, role: int = Qt.DisplayRole) → Any
decodeData()
disconnectNotify()
encodeData()
endInsertColumns()
endInsertRows()
endMoveColumns()
endMoveRows()
endRemoveColumns()
endRemoveRows()
endResetModel()
flags(self, index: QModelIndex) → Qt.ItemFlags
iconForLayer(layer: QgsMapLayer) → QIcon

Returns the icon corresponding to a specified map layer.

New in version 3.0.

index(self, row: int, column: int, parent: QModelIndex = QModelIndex()) → QModelIndex
indexFromLayer(self, layer: QgsMapLayer) → QModelIndex

indexFromLayer returns the model index for a given layer

See also

layerFromIndex()

isSignalConnected()
itemsCheckable(self) → bool

returns if the items can be checked or not

layerFromIndex(self, index: QModelIndex) → QgsMapLayer

Returns the map layer corresponding to the specified index.

See also

indexFromLayer()

New in version 3.0.

layersChecked(self, checkState: Qt.CheckState = Qt.Checked) → List[QgsMapLayer]

layersChecked returns the list of layers which are checked (or unchecked)

parent(self, child: QModelIndex) → QModelIndex
persistentIndexList()
receivers()
removeLayers(self, layerIds: Iterable[str])
resetInternalData()
rowCount(self, parent: QModelIndex = QModelIndex()) → int
sender()
senderSignalIndex()
setAdditionalItems(self, items: Iterable[str])

Sets a list of additional (non map layer) items to include at the end of the model. These may represent additional layers such as layers which are not included in the map layer registry, or paths to layers which have not yet been loaded into QGIS.

New in version 3.0.

setAllowEmptyLayer(self, allowEmpty: bool)

Sets whether an optional empty layer (“not set”) option is present in the model.

New in version 3.0.

setData(self, index: QModelIndex, value: Any, role: int = Qt.EditRole) → bool
setItemsCheckable(self, checkable: bool)

setItemsCheckable defines if layers should be selectable in the widget

setShowCrs(self, showCrs: bool)

Sets whether the CRS of layers is also included in the model’s display role.

See also

showCrs()

New in version 3.0.

showCrs(self) → bool

Returns true if the model includes layer’s CRS in the display role.

See also

setShowCrs()

New in version 3.0.

timerEvent()