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.

Parameters

parent

AdditionalRole = 260
EmptyRole = 259
class ItemDataRole

Bases: int

LayerIdRole = 257
LayerRole = 258
addLayers(self, layers: Iterable[QgsMapLayer])
Parameters

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.

Return type

List[str]

allowEmptyLayer(self) → bool

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

New in version 3.0.

Return type

bool

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

checkAll changes the checkstate for all the layers

Parameters

checkState (Qt.CheckState) –

childEvent()
columnCount(self, parent: QModelIndex = QModelIndex()) → int
Parameters

parent (QModelIndex = QModelIndex()) –

Return type

int

connectNotify()
createIndex()
customEvent()
data(self, index: QModelIndex, role: int = Qt.DisplayRole) → Any
Parameters
  • index (QModelIndex) –

  • role (int = Qt.DisplayRole) –

Return type

Any

decodeData()
disconnectNotify()
encodeData()
endInsertColumns()
endInsertRows()
endMoveColumns()
endMoveRows()
endRemoveColumns()
endRemoveRows()
endResetModel()
flags(self, index: QModelIndex) → Qt.ItemFlags
Parameters

index (QModelIndex) –

Return type

Qt.ItemFlags

iconForLayer(layer: QgsMapLayer) → QIcon

Returns the icon corresponding to a specified map layer.

New in version 3.0.

Parameters

layer (QgsMapLayer) –

Return type

QIcon

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

  • column (int) –

  • parent (QModelIndex = QModelIndex()) –

Return type

QModelIndex

indexFromLayer(self, layer: QgsMapLayer) → QModelIndex

indexFromLayer returns the model index for a given layer

See also

layerFromIndex()

Parameters

layer (QgsMapLayer) –

Return type

QModelIndex

isSignalConnected()
itemsCheckable(self) → bool

returns if the items can be checked or not

Return type

bool

layerFromIndex(self, index: QModelIndex) → QgsMapLayer

Returns the map layer corresponding to the specified index.

See also

indexFromLayer()

New in version 3.0.

Parameters

index (QModelIndex) –

Return type

QgsMapLayer

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

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

Parameters

checkState (Qt.CheckState = Qt.Checked) –

Return type

List[QgsMapLayer]

parent(self, child: QModelIndex) → QModelIndex
Parameters

child (QModelIndex) –

Return type

QModelIndex

persistentIndexList()
receivers()
removeLayers(self, layerIds: Iterable[str])
Parameters

layerIds (Iterable[str]) –

resetInternalData()
rowCount(self, parent: QModelIndex = QModelIndex()) → int
Parameters

parent (QModelIndex = QModelIndex()) –

Return type

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.

Parameters

items (Iterable[str]) –

setAllowEmptyLayer(self, allowEmpty: bool)

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

New in version 3.0.

Parameters

allowEmpty (bool) –

setData(self, index: QModelIndex, value: Any, role: int = Qt.EditRole) → bool
Parameters
  • index (QModelIndex) –

  • value (Any) –

  • role (int = Qt.EditRole) –

Return type

bool

setItemsCheckable(self, checkable: bool)

setItemsCheckable defines if layers should be selectable in the widget

Parameters

checkable (bool) –

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.

Parameters

showCrs (bool) –

showCrs(self) → bool

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

See also

setShowCrs()

New in version 3.0.

Return type

bool

timerEvent()