Class: QgsMapLayerModel¶
- class qgis.core.QgsMapLayerModel¶
Bases:
PyQt5.QtCore.QAbstractItemModel
The
QgsMapLayerModel
class is a model to display layers in widgets.See also
See also
New in version 2.3.
QgsMapLayerModel(parent: QObject = None, project:
QgsProject
= None)QgsMapLayerModel
creates a model to display layers in widgets.If a specific
project
is not specified then theQgsProject.instance()
project will be used to populate the model.QgsMapLayerModel(layers: Iterable[QgsMapLayer], parent: QObject = None, project:
QgsProject
= None)QgsMapLayerModel
creates a model to display a specific list of layers in a widget.If a specific
project
is not specified then theQgsProject.instance()
project will be used to populate the model.Methods
- param layers:
Returns the list of additional (non map layer) items included at the end of the model.
Returns the list of additional layers added to the model.
Returns
True
if the model allows the empty layer ("not set") choice.beginInsertColumns
beginInsertRows
beginMoveColumns
beginMoveRows
beginRemoveColumns
beginRemoveRows
- param data:
changePersistentIndex
checkAll changes the checkstate for all the layers
- param parent:
createIndex
- param index:
decodeData
- param data:
- param index:
Returns the icon corresponding to a specified map
layer
.- param row:
indexFromLayer returns the model index for a given layer
- param row:
Returns
True
if items in the model can be reordered via drag and drop.returns if the items can be checked or not
Returns the map layer corresponding to the specified
index
.layersChecked returns the list of layers which are checked (or unchecked)
- param indexes:
- rtype:
List[str]
- param child:
- param layerIds:
- param row:
- param parent:
Sets a list of additional (non map layer) items to include at the end of the model.
Sets a list of additional
layers
to include in the model.Sets whether an optional empty layer ("not set") option is present in the model.
- param index:
Sets whether items in the model can be reordered via drag and drop.
setItemsCheckable defines if layers should be selectable in the widget
Sets which layers are checked in the model.
Sets the
QgsProject
from which map layers are shownSets whether the CRS of layers is also included in the model's display role.
Returns
True
if the model includes layer's CRS in the display role.- rtype:
Qt.DropActions
Attributes
- AdditionalRole = 260¶
- EmptyRole = 259¶
- class ItemDataRole¶
Bases:
int
- baseClass¶
alias of
QgsMapLayerModel
- 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.
See also
New in version 3.0.
- Return type:
List[str]
- additionalLayers(self) List[QgsMapLayer] ¶
Returns the list of additional layers added to the model.
See also
New in version 3.22.
- Return type:
List[QgsMapLayer]
- allowEmptyLayer(self) bool ¶
Returns
True
if the model allows the empty layer (“not set”) choice.See also
New in version 3.0.
- Return type:
bool
- QgsMapLayerModel.beginInsertColumns(self, QModelIndex, int, int)
- QgsMapLayerModel.beginInsertRows(self, QModelIndex, int, int)
- QgsMapLayerModel.beginMoveColumns(self, QModelIndex, int, int, QModelIndex, int) -> bool
- QgsMapLayerModel.beginMoveRows(self, QModelIndex, int, int, QModelIndex, int) -> bool
- QgsMapLayerModel.beginRemoveColumns(self, QModelIndex, int, int)
- QgsMapLayerModel.beginRemoveRows(self, QModelIndex, int, int)
- beginResetModel(self)¶
- canDropMimeData(self, data: QMimeData, action: Qt.DropAction, row: int, column: int, parent: QModelIndex) bool ¶
- Parameters:
data (QMimeData) –
action (Qt.DropAction) –
row (int) –
column (int) –
parent (QModelIndex) –
- Return type:
bool
- QgsMapLayerModel.changePersistentIndex(self, QModelIndex, QModelIndex)
- changePersistentIndexList(self, Iterable[QModelIndex], Iterable[QModelIndex])¶
- checkAll(self, checkState: Qt.CheckState)¶
checkAll changes the checkstate for all the layers
- Parameters:
checkState (Qt.CheckState) –
- childEvent(self, QChildEvent)¶
- columnCount(self, parent: QModelIndex = QModelIndex()) int ¶
- Parameters:
parent (QModelIndex = QModelIndex()) –
- Return type:
int
- connectNotify(self, QMetaMethod)¶
- QgsMapLayerModel.createIndex(self, int, int, object: object = 0) -> QModelIndex
- customEvent(self, QEvent)¶
- data(self, index: QModelIndex, role: int = Qt.DisplayRole) Any ¶
- Parameters:
index (QModelIndex) –
role (int = Qt.DisplayRole) –
- Return type:
Any
- QgsMapLayerModel.decodeData(self, int, int, QModelIndex, QDataStream) -> bool
- disconnectNotify(self, QMetaMethod)¶
- dropMimeData(self, data: QMimeData, action: Qt.DropAction, row: int, column: int, parent: QModelIndex) bool ¶
- Parameters:
data (QMimeData) –
action (Qt.DropAction) –
row (int) –
column (int) –
parent (QModelIndex) –
- Return type:
bool
- encodeData(self, Iterable[QModelIndex], QDataStream)¶
- endInsertColumns(self)¶
- endInsertRows(self)¶
- endMoveColumns(self)¶
- endMoveRows(self)¶
- endRemoveColumns(self)¶
- endRemoveRows(self)¶
- endResetModel(self)¶
- 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
- Parameters:
layer (QgsMapLayer) –
- Return type:
QModelIndex
- insertRows(self, row: int, count: int, parent: QModelIndex = QModelIndex()) bool ¶
- Parameters:
row (int) –
count (int) –
parent (QModelIndex = QModelIndex()) –
- Return type:
bool
- isSignalConnected(self, QMetaMethod) bool ¶
- itemsCanBeReordered(self) bool ¶
Returns
True
if items in the model can be reordered via drag and drop.See also
New in version 3.14.
- Return type:
bool
- 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
New in version 3.0.
- Parameters:
index (QModelIndex) –
- Return type:
- 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]
- mimeData(self, indexes: Iterable[QModelIndex]) QMimeData ¶
- Parameters:
indexes (Iterable[QModelIndex]) –
- Return type:
QMimeData
- mimeTypes(self) List[str] ¶
- Return type:
List[str]
- parent(self, child: QModelIndex) QModelIndex ¶
- Parameters:
child (QModelIndex) –
- Return type:
QModelIndex
- persistentIndexList(self) List[QModelIndex] ¶
- receivers(self, PYQT_SIGNAL) int ¶
- removeLayers(self, layerIds: Iterable[str])¶
- Parameters:
layerIds (Iterable[str]) –
- removeRows(self, row: int, count: int, parent: QModelIndex = QModelIndex()) bool ¶
- Parameters:
row (int) –
count (int) –
parent (QModelIndex = QModelIndex()) –
- Return type:
bool
- resetInternalData(self)¶
- rowCount(self, parent: QModelIndex = QModelIndex()) int ¶
- Parameters:
parent (QModelIndex = QModelIndex()) –
- Return type:
int
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- 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 active project, or paths to layers which have not yet been loaded into QGIS.
See also
New in version 3.0.
- Parameters:
items (Iterable[str]) –
- setAdditionalLayers(self, layers: Iterable[QgsMapLayer])¶
Sets a list of additional
layers
to include in the model.This method allows adding additional layers, which are not part of a project’s layers, into the model.
See also
New in version 3.22.
- Parameters:
layers (Iterable[QgsMapLayer]) –
- setAllowEmptyLayer(self, allowEmpty: bool, text: str = '', icon: QIcon = QIcon())¶
Sets whether an optional empty layer (“not set”) option is present in the model.
Since QGIS 3.20, the optional
text
andicon
arguments allows the text and icon for the empty layer item to be set.See also
New in version 3.0.
- Parameters:
allowEmpty (bool) –
text (str = '') –
icon (QIcon = QIcon()) –
- setData(self, index: QModelIndex, value: Any, role: int = Qt.EditRole) bool ¶
- Parameters:
index (QModelIndex) –
value (Any) –
role (int = Qt.EditRole) –
- Return type:
bool
- setItemsCanBeReordered(self, allow: bool)¶
Sets whether items in the model can be reordered via drag and drop.
See also
New in version 3.14.
- Parameters:
allow (bool) –
- setItemsCheckable(self, checkable: bool)¶
setItemsCheckable defines if layers should be selectable in the widget
- Parameters:
checkable (bool) –
- setLayersChecked(self, layers: Iterable[QgsMapLayer])¶
Sets which layers are checked in the model.
- Parameters:
layers (Iterable[QgsMapLayer]) –
- setProject(self, project: QgsProject)¶
Sets the
QgsProject
from which map layers are shownNew in version 3.24.
- Parameters:
project (QgsProject) –
- setShowCrs(self, showCrs: bool)¶
Sets whether the CRS of layers is also included in the model’s display role.
See also
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
New in version 3.0.
- Return type:
bool
- supportedDropActions(self) Qt.DropActions ¶
- Return type:
Qt.DropActions
- timerEvent(self, QTimerEvent)¶