QgsMapLayerModel class
The QgsMapLayerModel class is a model to display layers in widgets.
Contents
Public types
- enum ItemDataRole { LayerIdRole = Qt::UserRole + 1, LayerRole, EmptyRole, AdditionalRole }
- Item data roles.
Public static functions
- static auto iconForLayer(QgsMapLayer* layer) -> QIcon
- Returns the icon corresponding to a specified map layer.
Constructors, destructors, conversion operators
- QgsMapLayerModel(QObject* parent = nullptr) explicit
- QgsMapLayerModel creates a model to display layers in widgets.
- QgsMapLayerModel(const QList<QgsMapLayer*>& layers, QObject* parent = nullptr) explicit
- QgsMapLayerModel creates a model to display a specific list of layers in a widget.
Public functions
- auto additionalItems() const -> QStringList
- Returns the list of additional (non map layer) items included at the end of the model.
- auto allowEmptyLayer() const -> bool
- Returns true if the model allows the empty layer ("not set") choice.
- void checkAll(Qt::CheckState checkState)
- checkAll changes the checkstate for all the layers
- auto indexFromLayer(QgsMapLayer* layer) const -> QModelIndex
- indexFromLayer returns the model index for a given layer
- auto itemsCheckable() const -> bool
- returns if the items can be checked or not
- auto layerFromIndex(const QModelIndex& index) const -> QgsMapLayer*
- Returns the map layer corresponding to the specified index.
- auto layersChecked(Qt::CheckState checkState = Qt::Checked) -> QList<QgsMapLayer*>
- layersChecked returns the list of layers which are checked (or unchecked)
- auto roleNames() const -> QHash<int, QByteArray> override
- Returns strings for all roles supported by this model.
- void setAdditionalItems(const QStringList& items)
- Sets a list of additional (non map layer) items to include at the end of the model.
- void setAllowEmptyLayer(bool allowEmpty)
- Sets whether an optional empty layer ("not set") option is present in the model.
- void setItemsCheckable(bool checkable)
- setItemsCheckable defines if layers should be selectable in the widget
- void setShowCrs(bool showCrs)
- Sets whether the CRS of layers is also included in the model's display role.
- auto showCrs() const -> bool
- Returns true if the model includes layer's CRS in the display role.
Enum documentation
enum QgsMapLayerModel:: ItemDataRole
Item data roles.
| Enumerators | |
|---|---|
| LayerIdRole |
Stores the map layer ID. |
| LayerRole |
Stores pointer to the map layer itself. |
| EmptyRole |
True if index corresponds to the empty (not set) value. |
| AdditionalRole |
True if index corresponds to an additional (non map layer) item. |
Function documentation
static QIcon QgsMapLayerModel:: iconForLayer(QgsMapLayer* layer)
Returns the icon corresponding to a specified map layer.
QStringList QgsMapLayerModel:: additionalItems() const
Returns the list of additional (non map layer) items included at the end of the model.
bool QgsMapLayerModel:: allowEmptyLayer() const
Returns true if the model allows the empty layer ("not set") choice.
QModelIndex QgsMapLayerModel:: indexFromLayer(QgsMapLayer* layer) const
indexFromLayer returns the model index for a given layer
QgsMapLayer* QgsMapLayerModel:: layerFromIndex(const QModelIndex& index) const
Returns the map layer corresponding to the specified index.
QHash<int, QByteArray> QgsMapLayerModel:: roleNames() const override
Returns strings for all roles supported by this model.
void QgsMapLayerModel:: setAdditionalItems(const QStringList& items)
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.
void QgsMapLayerModel:: setAllowEmptyLayer(bool allowEmpty)
Sets whether an optional empty layer ("not set") option is present in the model.
void QgsMapLayerModel:: setShowCrs(bool showCrs)
Sets whether the CRS of layers is also included in the model's display role.
bool QgsMapLayerModel:: showCrs() const
Returns true if the model includes layer's CRS in the display role.