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,
65 explicit QgsMapLayerModel(
const QList<QgsMapLayer *> &layers, QObject *parent =
nullptr );
70 void setItemsCheckable(
bool checkable );
75 void checkAll( Qt::CheckState checkState );
82 void setAllowEmptyLayer(
bool allowEmpty );
96 void setShowCrs(
bool showCrs );
108 QList<QgsMapLayer *> layersChecked( Qt::CheckState checkState = Qt::Checked );
116 QModelIndex indexFromLayer(
QgsMapLayer *layer )
const;
123 QgsMapLayer *layerFromIndex(
const QModelIndex &index )
const;
132 void setAdditionalItems(
const QStringList &items );
142 QModelIndex index(
int row,
int column,
const QModelIndex &parent = QModelIndex() )
const override;
143 QModelIndex parent(
const QModelIndex &child )
const override;
144 int rowCount(
const QModelIndex &parent = QModelIndex() )
const override;
145 int columnCount(
const QModelIndex &parent = QModelIndex() )
const override;
146 QVariant data(
const QModelIndex &index,
int role = Qt::DisplayRole )
const override;
153 QHash<int, QByteArray> roleNames()
const override SIP_SKIP;
155 bool setData(
const QModelIndex &index,
const QVariant &value,
int role = Qt::EditRole )
override;
156 Qt::ItemFlags flags(
const QModelIndex &index )
const override;
165 void removeLayers(
const QStringList &layerIds );
166 void addLayers(
const QList<QgsMapLayer *> &layers );
171 bool mItemCheckable =
false;
175 bool mAllowEmpty =
false;
176 bool mShowCrs =
false;
177 QStringList mAdditionalItems;
180 #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.