QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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 : denis.rouzaud@gmail.com
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() { return mItemCheckable; }
61 
65  QModelIndex indexFromLayer( QgsMapLayer* layer );
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;
80  QModelIndex parent( const QModelIndex &child ) const;
81  int rowCount( const QModelIndex &parent ) const;
82  int columnCount( const QModelIndex &parent ) const;
83  QVariant data( const QModelIndex &index, int role ) const;
84  bool setData( const QModelIndex &index, const QVariant &value, int role );
85  Qt::ItemFlags flags( const QModelIndex &index ) const;
86 };
87 
88 #endif // QGSMAPLAYERMODEL_H
static unsigned index
Base class for all map layer types.
Definition: qgsmaplayer.h:48
bool itemsCheckable()
returns if the items can be checked or not
QList< QgsMapLayer * > mLayers
The QgsMapLayerModel class is a model to display layers in widgets.
QMap< QString, Qt::CheckState > mLayersChecked
static const int LayerIdRole