16 #ifndef QGSMAPLAYERMODEL_H 17 #define QGSMAPLAYERMODEL_H 19 #include <QAbstractItemModel> 20 #include <QSortFilterProxyModel> 21 #include <QStringList> 23 #include "qgis_core.h" 40 Q_PROPERTY(
bool allowEmptyLayer READ allowEmptyLayer WRITE setAllowEmptyLayer )
41 Q_PROPERTY(
bool showCrs READ showCrs WRITE setShowCrs )
42 Q_PROPERTY(
bool itemsCheckable READ itemsCheckable WRITE setItemsCheckable )
43 Q_PROPERTY( QStringList additionalItems READ additionalItems WRITE setAdditionalItems )
50 LayerIdRole = Qt::UserRole + 1,
64 explicit QgsMapLayerModel(
const QList<QgsMapLayer *> &layers, QObject *parent =
nullptr );
69 void setItemsCheckable(
bool checkable );
74 void checkAll( Qt::CheckState checkState );
81 void setAllowEmptyLayer(
bool allowEmpty );
95 void setShowCrs(
bool showCrs );
107 QList<QgsMapLayer *> layersChecked( Qt::CheckState checkState = Qt::Checked );
115 QModelIndex indexFromLayer(
QgsMapLayer *layer )
const;
122 QgsMapLayer *layerFromIndex(
const QModelIndex &index )
const;
131 void setAdditionalItems(
const QStringList &items );
141 QModelIndex index(
int row,
int column,
const QModelIndex &parent = QModelIndex() )
const override;
142 QModelIndex parent(
const QModelIndex &child )
const override;
143 int rowCount(
const QModelIndex &parent = QModelIndex() )
const override;
144 int columnCount(
const QModelIndex &parent = QModelIndex() )
const override;
145 QVariant data(
const QModelIndex &index,
int role = Qt::DisplayRole )
const override;
152 QHash<int, QByteArray> roleNames()
const override SIP_SKIP;
154 bool setData(
const QModelIndex &index,
const QVariant &value,
int role = Qt::EditRole )
override;
155 Qt::ItemFlags flags(
const QModelIndex &index )
const override;
164 void removeLayers(
const QStringList &layerIds );
165 void addLayers(
const QList<QgsMapLayer *> &layers );
170 bool mItemCheckable =
false;
174 bool mAllowEmpty =
false;
175 bool mShowCrs =
false;
176 QStringList mAdditionalItems;
179 #endif // QGSMAPLAYERMODEL_H Base class for all map layer types.
ItemDataRole
Item data roles.
Stores pointer to the map layer itself.
bool allowEmptyLayer() const
Returns true if the model allows the empty layer ("not set") choice.
True if index corresponds to an additional (non map layer) item.
QStringList additionalItems() const
Returns the list of additional (non map layer) items included at the end of the model.
The QgsMapLayerModel class is a model to display layers in widgets.
QMap< QString, Qt::CheckState > mLayersChecked
QList< QgsMapLayer * > mLayers
bool showCrs() const
Returns true if the model includes layer's CRS in the display role.
bool itemsCheckable() const
returns if the items can be checked or not
True if index corresponds to the empty (not set) value.