QGIS API Documentation  2.15.0-Master (5f66276)
qgsmaplayermodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaplayermodel.h
3  --------------------------------------
4  Date : 01.04.2014
5  Copyright : (C) 2014 Denis Rouzaud
6  Email : [email protected]
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 
16 #ifndef QGSMAPLAYERMODEL_H
17 #define QGSMAPLAYERMODEL_H
18 
19 #include <QAbstractItemModel>
20 #include <QSortFilterProxyModel>
21 #include <QStringList>
22 
23 class QgsMapLayer;
24 
25 
32 // TODO QGIS3: move to core
33 class GUI_EXPORT QgsMapLayerModel : public QAbstractItemModel
34 {
35  Q_OBJECT
36  public:
37 
40  {
41  LayerIdRole = Qt::UserRole + 1,
43  };
44 
48  explicit QgsMapLayerModel( QObject *parent = nullptr );
52  explicit QgsMapLayerModel( const QList<QgsMapLayer*>& layers, QObject *parent = nullptr );
53 
57  void setItemsCheckable( bool checkable );
61  void checkAll( Qt::CheckState checkState );
65  QList<QgsMapLayer*> layersChecked( Qt::CheckState checkState = Qt::Checked );
67  bool itemsCheckable() const { return mItemCheckable; }
68 
72  QModelIndex indexFromLayer( QgsMapLayer* layer ) const;
73 
74 
75  protected slots:
76  void removeLayers( const QStringList& layerIds );
77  void addLayers( const QList<QgsMapLayer*>& layers );
78 
79  protected:
83 
84  // QAbstractItemModel interface
85  public:
86  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
87  QModelIndex parent( const QModelIndex &child ) const override;
88  int rowCount( const QModelIndex &parent ) const override;
89  int columnCount( const QModelIndex &parent ) const override;
90  QVariant data( const QModelIndex &index, int role ) const override;
91 
92 #if QT_VERSION >= 0x050000
93 
98  QHash<int, QByteArray> roleNames() const override;
99 #endif
100 
101  bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
102  Qt::ItemFlags flags( const QModelIndex &index ) const override;
103 };
104 
105 #endif // QGSMAPLAYERMODEL_H
static unsigned index
virtual int rowCount(const QModelIndex &parent) const =0
Base class for all map layer types.
Definition: qgsmaplayer.h:49
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
ItemDataRole
Item data roles.
QList< QgsMapLayer * > mLayers
const QHash< int, QByteArray > & roleNames() const
The QgsMapLayerModel class is a model to display layers in widgets.
QMap< QString, Qt::CheckState > mLayersChecked
virtual QVariant data(const QModelIndex &index, int role) const =0
bool itemsCheckable() const
returns if the items can be checked or not
virtual int columnCount(const QModelIndex &parent) const =0
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
QObject * parent() const
typedef ItemFlags