QGIS API Documentation  2.17.0-Master (0497e4a)
qgsmaplayerproxymodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaplayerproxymodel.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 QGSMAPLAYERPROXYMODEL_H
17 #define QGSMAPLAYERPROXYMODEL_H
18 
19 #include <QSortFilterProxyModel>
20 #include <QStringList>
21 
22 class QgsMapLayerModel;
23 class QgsMapLayer;
24 
30 {
31  Q_OBJECT
32  Q_FLAGS( Filters )
33 
34  Q_PROPERTY( QgsMapLayerProxyModel::Filters filters READ filters WRITE setFilters )
35  Q_PROPERTY( QList<QgsMapLayer*> exceptedLayerList READ exceptedLayerList WRITE setExceptedLayerList )
36  Q_PROPERTY( QStringList exceptedLayerIds READ exceptedLayerIds WRITE setExceptedLayerIds )
37 
38  public:
39  enum Filter
40  {
41  RasterLayer = 1,
42  NoGeometry = 2,
43  PointLayer = 4,
44  LineLayer = 8,
45  PolygonLayer = 16,
46  HasGeometry = PointLayer | LineLayer | PolygonLayer,
47  VectorLayer = NoGeometry | HasGeometry,
48  PluginLayer = 32,
49  WritableLayer = 64,
50  All = RasterLayer | VectorLayer | PluginLayer
51  };
52  Q_DECLARE_FLAGS( Filters, Filter )
53 
54 
58  explicit QgsMapLayerProxyModel( QObject *parent = nullptr );
59 
63  QgsMapLayerModel* sourceLayerModel() const { return mModel; }
64 
70  QgsMapLayerProxyModel* setFilters( const QgsMapLayerProxyModel::Filters& filters );
71  const Filters& filters() const { return mFilters; }
72 
74  void setExceptedLayerList( const QList<QgsMapLayer*>& exceptList );
76  QList<QgsMapLayer*> exceptedLayerList() {return mExceptList;}
77 
79  void setExceptedLayerIds( const QStringList& ids );
81  QStringList exceptedLayerIds() const;
82 
83  private:
84  Filters mFilters;
85  QList<QgsMapLayer*> mExceptList;
86  QgsMapLayerModel* mModel;
87 
88  // QSortFilterProxyModel interface
89  public:
90  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
91  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
92 };
93 
94 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerProxyModel::Filters )
95 
96 #endif // QGSMAPLAYERPROXYMODEL_H
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const
QList< QgsMapLayer * > exceptedLayerList()
Get the list of maplayers which are excluded from the list.
Base class for all map layer types.
Definition: qgsmaplayer.h:49
The QgsMapLayerModel class is a model to display layers in widgets.
The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widget...
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
const Filters & filters() const