QGIS API Documentation
3.22.4-Białowieża (ce8e65e95e)
|
The QgsMapLayerModel class is a model to display layers in widgets. More...
#include <qgsmaplayermodel.h>
Public Types | |
enum | ItemDataRole { LayerIdRole = Qt::UserRole + 1 , LayerRole , EmptyRole , AdditionalRole } |
Item data roles. More... | |
Public Member Functions | |
QgsMapLayerModel (const QList< QgsMapLayer * > &layers, QObject *parent=nullptr, QgsProject *project=nullptr) | |
QgsMapLayerModel creates a model to display a specific list of layers in a widget. More... | |
QgsMapLayerModel (QObject *parent=nullptr, QgsProject *project=nullptr) | |
QgsMapLayerModel creates a model to display layers in widgets. More... | |
QStringList | additionalItems () const |
Returns the list of additional (non map layer) items included at the end of the model. More... | |
QList< QgsMapLayer * > | additionalLayers () const |
Returns the list of additional layers added to the model. More... | |
bool | allowEmptyLayer () const |
Returns true if the model allows the empty layer ("not set") choice. More... | |
bool | canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override |
void | checkAll (Qt::CheckState checkState) |
checkAll changes the checkstate for all the layers More... | |
int | columnCount (const QModelIndex &parent=QModelIndex()) const override |
QVariant | data (const QModelIndex &index, int role=Qt::DisplayRole) const override |
bool | dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override |
Qt::ItemFlags | flags (const QModelIndex &index) const override |
QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const override |
QModelIndex | indexFromLayer (QgsMapLayer *layer) const |
indexFromLayer returns the model index for a given layer More... | |
bool | insertRows (int row, int count, const QModelIndex &parent=QModelIndex()) override |
bool | itemsCanBeReordered () const |
Returns true if items in the model can be reordered via drag and drop. More... | |
bool | itemsCheckable () const |
returns if the items can be checked or not More... | |
QgsMapLayer * | layerFromIndex (const QModelIndex &index) const |
Returns the map layer corresponding to the specified index. More... | |
QList< QgsMapLayer * > | layersChecked (Qt::CheckState checkState=Qt::Checked) |
layersChecked returns the list of layers which are checked (or unchecked) More... | |
QMimeData * | mimeData (const QModelIndexList &indexes) const override |
QStringList | mimeTypes () const override |
QModelIndex | parent (const QModelIndex &child) const override |
bool | removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) override |
QHash< int, QByteArray > | roleNames () const override |
Returns strings for all roles supported by this model. More... | |
int | rowCount (const QModelIndex &parent=QModelIndex()) const override |
void | setAdditionalItems (const QStringList &items) |
Sets a list of additional (non map layer) items to include at the end of the model. More... | |
void | setAdditionalLayers (const QList< QgsMapLayer * > &layers) |
Sets a list of additional layers to include in the model. More... | |
void | setAllowEmptyLayer (bool allowEmpty, const QString &text=QString(), const QIcon &icon=QIcon()) |
Sets whether an optional empty layer ("not set") option is present in the model. More... | |
bool | setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override |
void | setItemsCanBeReordered (bool allow) |
Sets whether items in the model can be reordered via drag and drop. More... | |
void | setItemsCheckable (bool checkable) |
setItemsCheckable defines if layers should be selectable in the widget More... | |
void | setLayersChecked (const QList< QgsMapLayer * > &layers) |
Sets which layers are checked in the model. More... | |
void | setShowCrs (bool showCrs) |
Sets whether the CRS of layers is also included in the model's display role. More... | |
bool | showCrs () const |
Returns true if the model includes layer's CRS in the display role. More... | |
Qt::DropActions | supportedDropActions () const override |
Static Public Member Functions | |
static QIcon | iconForLayer (QgsMapLayer *layer) |
Returns the icon corresponding to a specified map layer. More... | |
Protected Slots | |
void | addLayers (const QList< QgsMapLayer * > &layers) |
void | removeLayers (const QStringList &layerIds) |
Protected Attributes | |
QList< QPointer< QgsMapLayer > > | mAdditionalLayers |
bool | mCanReorder = false |
bool | mItemCheckable = false |
QList< QgsMapLayer * > | mLayers |
QMap< QString, Qt::CheckState > | mLayersChecked |
QgsProject * | mProject = nullptr |
Properties | |
QStringList | additionalItems |
bool | allowEmptyLayer |
bool | itemsCheckable |
bool | showCrs |
The QgsMapLayerModel class is a model to display layers in widgets.
Definition at line 37 of file qgsmaplayermodel.h.
Item data roles.
Definition at line 49 of file qgsmaplayermodel.h.
|
explicit |
QgsMapLayerModel creates a model to display layers in widgets.
If a specific project is not specified then the QgsProject::instance() project will be used to populate the model.
Definition at line 34 of file qgsmaplayermodel.cpp.
|
explicit |
QgsMapLayerModel creates a model to display a specific list of layers in a widget.
If a specific project is not specified then the QgsProject::instance() project will be used to populate the model.
Definition at line 26 of file qgsmaplayermodel.cpp.
|
inline |
Returns the list of additional (non map layer) items included at the end of the model.
Definition at line 171 of file qgsmaplayermodel.h.
QList< QgsMapLayer * > QgsMapLayerModel::additionalLayers | ( | ) | const |
Returns the list of additional layers added to the model.
Definition at line 190 of file qgsmaplayermodel.cpp.
|
protectedslot |
Definition at line 216 of file qgsmaplayermodel.cpp.
|
inline |
Returns true
if the model allows the empty layer ("not set") choice.
Definition at line 115 of file qgsmaplayermodel.h.
|
override |
Definition at line 479 of file qgsmaplayermodel.cpp.
void QgsMapLayerModel::checkAll | ( | Qt::CheckState | checkState | ) |
checkAll changes the checkstate for all the layers
Definition at line 58 of file qgsmaplayermodel.cpp.
|
override |
Definition at line 269 of file qgsmaplayermodel.cpp.
|
override |
Definition at line 276 of file qgsmaplayermodel.cpp.
|
override |
Definition at line 510 of file qgsmaplayermodel.cpp.
|
override |
Definition at line 401 of file qgsmaplayermodel.cpp.
|
static |
Returns the icon corresponding to a specified map layer.
Definition at line 549 of file qgsmaplayermodel.cpp.
|
override |
Definition at line 235 of file qgsmaplayermodel.cpp.
QModelIndex QgsMapLayerModel::indexFromLayer | ( | QgsMapLayer * | layer | ) | const |
indexFromLayer returns the model index for a given layer
Definition at line 126 of file qgsmaplayermodel.cpp.
|
override |
Definition at line 428 of file qgsmaplayermodel.cpp.
bool QgsMapLayerModel::itemsCanBeReordered | ( | ) | const |
Returns true
if items in the model can be reordered via drag and drop.
Definition at line 53 of file qgsmaplayermodel.cpp.
|
inline |
returns if the items can be checked or not
Definition at line 142 of file qgsmaplayermodel.h.
QgsMapLayer * QgsMapLayerModel::layerFromIndex | ( | const QModelIndex & | index | ) | const |
Returns the map layer corresponding to the specified index.
Definition at line 134 of file qgsmaplayermodel.cpp.
QList< QgsMapLayer * > QgsMapLayerModel::layersChecked | ( | Qt::CheckState | checkState = Qt::Checked | ) |
layersChecked returns the list of layers which are checked (or unchecked)
Definition at line 98 of file qgsmaplayermodel.cpp.
|
override |
Definition at line 486 of file qgsmaplayermodel.cpp.
|
override |
Definition at line 472 of file qgsmaplayermodel.cpp.
|
override |
Definition at line 254 of file qgsmaplayermodel.cpp.
|
protectedslot |
Definition at line 195 of file qgsmaplayermodel.cpp.
|
override |
Definition at line 445 of file qgsmaplayermodel.cpp.
|
override |
Returns strings for all roles supported by this model.
Definition at line 392 of file qgsmaplayermodel.cpp.
|
override |
Definition at line 261 of file qgsmaplayermodel.cpp.
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 active project, or paths to layers which have not yet been loaded into QGIS.
Definition at line 139 of file qgsmaplayermodel.cpp.
void QgsMapLayerModel::setAdditionalLayers | ( | const QList< QgsMapLayer * > & | layers | ) |
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.
Definition at line 164 of file qgsmaplayermodel.cpp.
void QgsMapLayerModel::setAllowEmptyLayer | ( | bool | allowEmpty, |
const QString & | text = QString() , |
||
const QIcon & | icon = QIcon() |
||
) |
Sets whether an optional empty layer ("not set") option is present in the model.
Since QGIS 3.20, the optional text and icon arguments allows the text and icon for the empty layer item to be set.
Definition at line 68 of file qgsmaplayermodel.cpp.
|
override |
Definition at line 554 of file qgsmaplayermodel.cpp.
void QgsMapLayerModel::setItemsCanBeReordered | ( | bool | allow | ) |
Sets whether items in the model can be reordered via drag and drop.
Definition at line 48 of file qgsmaplayermodel.cpp.
void QgsMapLayerModel::setItemsCheckable | ( | bool | checkable | ) |
setItemsCheckable defines if layers should be selectable in the widget
Definition at line 43 of file qgsmaplayermodel.cpp.
void QgsMapLayerModel::setLayersChecked | ( | const QList< QgsMapLayer * > & | layers | ) |
Sets which layers are checked in the model.
Definition at line 112 of file qgsmaplayermodel.cpp.
void QgsMapLayerModel::setShowCrs | ( | bool | showCrs | ) |
Sets whether the CRS of layers is also included in the model's display role.
Definition at line 89 of file qgsmaplayermodel.cpp.
|
inline |
Returns true
if the model includes layer's CRS in the display role.
Definition at line 129 of file qgsmaplayermodel.h.
|
override |
Definition at line 544 of file qgsmaplayermodel.cpp.
|
protected |
Definition at line 227 of file qgsmaplayermodel.h.
|
protected |
Definition at line 230 of file qgsmaplayermodel.h.
|
protected |
Definition at line 229 of file qgsmaplayermodel.h.
|
protected |
Definition at line 226 of file qgsmaplayermodel.h.
|
protected |
Definition at line 228 of file qgsmaplayermodel.h.
|
protected |
Definition at line 232 of file qgsmaplayermodel.h.
|
readwrite |
Definition at line 1 of file qgsmaplayermodel.h.
|
readwrite |
Definition at line 1 of file qgsmaplayermodel.h.
|
readwrite |
Definition at line 1 of file qgsmaplayermodel.h.
|
readwrite |
Definition at line 1 of file qgsmaplayermodel.h.