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
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.Enums
Bases:
enum.IntEnum
alias of
CustomRole
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.- param data:
checkAll changes the checkstate for all the layers
- param parent:
- param index:
- 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
- class CustomRole(value)¶
Bases:
enum.IntEnum
Custom model roles.
Note
Prior to QGIS 3.36 this was available as QgsMapLayerModel.ItemDataRole
New in version 3.36.
LayerIdRole
: Stores the map layer IDLayerRole
: Stores pointer to the map layer itselfEmptyRole
: True if index corresponds to the empty (not set) valueAdditionalRole
: True if index corresponds to an additional (non map layer) item
- baseClass¶
alias of
QgsMapLayerModel
- ItemDataRole¶
alias of
CustomRole
- 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
- 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
- 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)¶
- 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
- 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)¶
- 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
- 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
.- 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
- 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
- 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
- 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
- Parameters:
showCrs (bool) –
- showCrs(self) bool ¶
Returns
True
if the model includes layer’s CRS in the display role.See also
- Return type:
bool
- supportedDropActions(self) Qt.DropActions ¶
- Return type:
Qt.DropActions
- timerEvent(self, QTimerEvent)¶