QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 class GUI_EXPORT QgsMapLayerModel : public QAbstractItemModel
33 {
34  Q_OBJECT
35  public:
36  static const int LayerIdRole;
37 
41  explicit QgsMapLayerModel( QObject *parent = 0 );
45  explicit QgsMapLayerModel( QList<QgsMapLayer*> layers, QObject *parent = 0 );
46 
50  void setItemsCheckable( bool checkable );
54  void checkAll( Qt::CheckState checkState );
58  QList<QgsMapLayer*> layersChecked( Qt::CheckState checkState = Qt::Checked );
60  bool itemsCheckable() const { return mItemCheckable; }
61 
65  QModelIndex indexFromLayer( QgsMapLayer* layer ) const;
66 
67 
68  protected slots:
69  void removeLayers( const QStringList layerIds );
70  void addLayers( QList<QgsMapLayer*> layers );
71 
72  protected:
73  QList<QgsMapLayer*> mLayers;
74  QMap<QString, Qt::CheckState> mLayersChecked;
76 
77  // QAbstractItemModel interface
78  public:
79  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
80  QModelIndex parent( const QModelIndex &child ) const override;
81  int rowCount( const QModelIndex &parent ) const override;
82  int columnCount( const QModelIndex &parent ) const override;
83  QVariant data( const QModelIndex &index, int role ) const override;
84  bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
85  Qt::ItemFlags flags( const QModelIndex &index ) const override;
86 };
87 
88 #endif // QGSMAPLAYERMODEL_H