QGIS API Documentation  2.99.0-Master (8ec3eaf)
Public Types | Public Member Functions | Protected Slots | Protected Attributes | Properties | List of all members
QgsMapLayerModel Class Reference

The QgsMapLayerModel class is a model to display layers in widgets. More...

#include <qgsmaplayermodel.h>

Inheritance diagram for QgsMapLayerModel:
Inheritance graph
[legend]

Public Types

enum  ItemDataRole { LayerIdRole = Qt::UserRole + 1, LayerRole, EmptyRole, AdditionalRole }
 Item data roles. More...
 

Public Member Functions

 QgsMapLayerModel (QObject *parent=nullptr)
 QgsMapLayerModel creates a model to display layers in widgets. More...
 
 QgsMapLayerModel (const QList< QgsMapLayer *> &layers, QObject *parent=nullptr)
 QgsMapLayerModel creates a model to display a specific list of layers in a widget. More...
 
QStringList additionalItems () const
 Return the list of additional (non map layer) items included at the end of the model. More...
 
bool allowEmptyLayer () const
 Returns true if the model allows the empty layer ("not set") choice. More...
 
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
 
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 itemsCheckable () const
 returns if the items can be checked or not More...
 
QList< QgsMapLayer * > layersChecked (Qt::CheckState checkState=Qt::Checked)
 layersChecked returns the list of layers which are checked (or unchecked) More...
 
QModelIndex parent (const QModelIndex &child) const 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 setAllowEmptyLayer (bool allowEmpty)
 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 setItemsCheckable (bool checkable)
 setItemsCheckable defines if layers should be selectable in the widget 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...
 

Protected Slots

void addLayers (const QList< QgsMapLayer *> &layers)
 
void removeLayers (const QStringList &layerIds)
 

Protected Attributes

bool mItemCheckable
 
QList< QgsMapLayer * > mLayers
 
QMap< QString, Qt::CheckState > mLayersChecked
 

Properties

QStringList additionalItems
 
bool allowEmptyLayer
 
bool itemsCheckable
 
bool showCrs
 

Detailed Description

The QgsMapLayerModel class is a model to display layers in widgets.

See also
QgsMapLayerProxyModel to sort and/filter the layers
QgsFieldModel to combine in with a field selector.
Note
added in 2.3

Definition at line 32 of file qgsmaplayermodel.h.

Member Enumeration Documentation

§ ItemDataRole

Item data roles.

Enumerator
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.

Definition at line 44 of file qgsmaplayermodel.h.

Constructor & Destructor Documentation

§ QgsMapLayerModel() [1/2]

QgsMapLayerModel::QgsMapLayerModel ( QObject *  parent = nullptr)
explicit

QgsMapLayerModel creates a model to display layers in widgets.

Definition at line 36 of file qgsmaplayermodel.cpp.

§ QgsMapLayerModel() [2/2]

QgsMapLayerModel::QgsMapLayerModel ( const QList< QgsMapLayer *> &  layers,
QObject *  parent = nullptr 
)
explicit

QgsMapLayerModel creates a model to display a specific list of layers in a widget.

Definition at line 25 of file qgsmaplayermodel.cpp.

Member Function Documentation

§ additionalItems()

QStringList QgsMapLayerModel::additionalItems ( ) const
inline

Return the list of additional (non map layer) items included at the end of the model.

See also
setAdditionalItems()
Note
added in QGIS 3.0

Definition at line 126 of file qgsmaplayermodel.h.

§ addLayers

void QgsMapLayerModel::addLayers ( const QList< QgsMapLayer *> &  layers)
protectedslot

Definition at line 157 of file qgsmaplayermodel.cpp.

§ allowEmptyLayer()

bool QgsMapLayerModel::allowEmptyLayer ( ) const
inline

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

See also
setAllowEmptyLayer()
Note
added in QGIS 3.0

Definition at line 84 of file qgsmaplayermodel.h.

§ checkAll()

void QgsMapLayerModel::checkAll ( Qt::CheckState  checkState)

checkAll changes the checkstate for all the layers

Definition at line 53 of file qgsmaplayermodel.cpp.

§ columnCount()

int QgsMapLayerModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 206 of file qgsmaplayermodel.cpp.

§ data()

QVariant QgsMapLayerModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Definition at line 213 of file qgsmaplayermodel.cpp.

§ flags()

Qt::ItemFlags QgsMapLayerModel::flags ( const QModelIndex &  index) const
override

Definition at line 369 of file qgsmaplayermodel.cpp.

§ index()

QModelIndex QgsMapLayerModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
override

Definition at line 172 of file qgsmaplayermodel.cpp.

§ indexFromLayer()

QModelIndex QgsMapLayerModel::indexFromLayer ( QgsMapLayer layer) const

indexFromLayer returns the model index for a given layer

Definition at line 103 of file qgsmaplayermodel.cpp.

§ itemsCheckable()

bool QgsMapLayerModel::itemsCheckable ( ) const
inline

returns if the items can be checked or not

Definition at line 105 of file qgsmaplayermodel.h.

§ layersChecked()

QList< QgsMapLayer * > QgsMapLayerModel::layersChecked ( Qt::CheckState  checkState = Qt::Checked)

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

Definition at line 90 of file qgsmaplayermodel.cpp.

§ parent()

QModelIndex QgsMapLayerModel::parent ( const QModelIndex &  child) const
override

Definition at line 191 of file qgsmaplayermodel.cpp.

§ removeLayers

void QgsMapLayerModel::removeLayers ( const QStringList &  layerIds)
protectedslot

Definition at line 136 of file qgsmaplayermodel.cpp.

§ roleNames()

QHash< int, QByteArray > QgsMapLayerModel::roleNames ( ) const
override

Returns strings for all roles supported by this model.

Note
Available only with Qt5 (python and c++)

Definition at line 360 of file qgsmaplayermodel.cpp.

§ rowCount()

int QgsMapLayerModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 198 of file qgsmaplayermodel.cpp.

§ setAdditionalItems()

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.

See also
additionalItems()
Note
added in QGIS 3.0

Definition at line 111 of file qgsmaplayermodel.cpp.

§ setAllowEmptyLayer()

void QgsMapLayerModel::setAllowEmptyLayer ( bool  allowEmpty)

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

See also
allowEmptyLayer()
Note
added in QGIS 3.0

Definition at line 62 of file qgsmaplayermodel.cpp.

§ setData()

bool QgsMapLayerModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
override

Definition at line 388 of file qgsmaplayermodel.cpp.

§ setItemsCheckable()

void QgsMapLayerModel::setItemsCheckable ( bool  checkable)

setItemsCheckable defines if layers should be selectable in the widget

Definition at line 48 of file qgsmaplayermodel.cpp.

§ setShowCrs()

void QgsMapLayerModel::setShowCrs ( bool  showCrs)

Sets whether the CRS of layers is also included in the model's display role.

See also
showCrs()
Note
added in QGIS 3.0

Definition at line 81 of file qgsmaplayermodel.cpp.

§ showCrs()

bool QgsMapLayerModel::showCrs ( ) const
inline

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

See also
setShowCrs()
Note
added in QGIS 3.0

Definition at line 98 of file qgsmaplayermodel.h.

Member Data Documentation

§ mItemCheckable

bool QgsMapLayerModel::mItemCheckable
protected

Definition at line 135 of file qgsmaplayermodel.h.

§ mLayers

QList<QgsMapLayer*> QgsMapLayerModel::mLayers
protected

Definition at line 133 of file qgsmaplayermodel.h.

§ mLayersChecked

QMap<QString, Qt::CheckState> QgsMapLayerModel::mLayersChecked
protected

Definition at line 134 of file qgsmaplayermodel.h.

Property Documentation

§ additionalItems

QStringList QgsMapLayerModel::additionalItems
readwrite

Definition at line 39 of file qgsmaplayermodel.h.

§ allowEmptyLayer

bool QgsMapLayerModel::allowEmptyLayer
readwrite

Definition at line 36 of file qgsmaplayermodel.h.

§ itemsCheckable

bool QgsMapLayerModel::itemsCheckable
readwrite

Definition at line 38 of file qgsmaplayermodel.h.

§ showCrs

bool QgsMapLayerModel::showCrs
readwrite

Definition at line 37 of file qgsmaplayermodel.h.


The documentation for this class was generated from the following files: