QGIS API Documentation  3.6.0-Noosa (5873452)
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 #include "qgis_core.h"
23 #include "qgis_sip.h"
24 
25 class QgsMapLayerModel;
26 class QgsMapLayer;
27 
33 class CORE_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
34 {
35  Q_OBJECT
36 
37  Q_PROPERTY( QgsMapLayerProxyModel::Filters filters READ filters WRITE setFilters )
38  Q_PROPERTY( QList<QgsMapLayer *> exceptedLayerList READ exceptedLayerList WRITE setExceptedLayerList )
39  Q_PROPERTY( QStringList exceptedLayerIds READ exceptedLayerIds WRITE setExceptedLayerIds )
40 
41  public:
42  enum Filter
43  {
44  RasterLayer = 1,
45  NoGeometry = 2,
46  PointLayer = 4,
47  LineLayer = 8,
48  PolygonLayer = 16,
49  HasGeometry = PointLayer | LineLayer | PolygonLayer,
50  VectorLayer = NoGeometry | HasGeometry,
51  PluginLayer = 32,
52  WritableLayer = 64,
53  MeshLayer = 128,
54  All = RasterLayer | VectorLayer | PluginLayer | MeshLayer
55  };
56  Q_DECLARE_FLAGS( Filters, Filter )
57  Q_FLAG( Filters )
58 
59 
63  explicit QgsMapLayerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
64 
68  QgsMapLayerModel *sourceLayerModel() const { return mModel; }
69 
77  QgsMapLayerProxyModel *setFilters( QgsMapLayerProxyModel::Filters filters );
78 
86  const Filters &filters() const { return mFilters; }
87 
99  void setLayerWhitelist( const QList<QgsMapLayer *> &layers );
100 
111  QList<QgsMapLayer *> layerWhitelist() {return mLayerWhitelist;}
112 
119  void setExceptedLayerList( const QList<QgsMapLayer *> &exceptList );
120 
127  QList<QgsMapLayer *> exceptedLayerList() {return mExceptList;}
128 
134  void setExceptedLayerIds( const QStringList &ids );
135 
141  QStringList exceptedLayerIds() const;
142 
148  void setExcludedProviders( const QStringList &providers );
149 
155  QStringList excludedProviders() const { return mExcludedProviders; }
156 
163  QString filterString() const { return mFilterString; }
164 
165  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
166  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
167 
168  public slots:
169 
177  void setFilterString( const QString &filter );
178 
179  private:
180  Filters mFilters;
181  QList<QgsMapLayer *> mExceptList;
182  QList<QgsMapLayer *> mLayerWhitelist;
183  QgsMapLayerModel *mModel = nullptr;
184  QStringList mExcludedProviders;
185  QString mFilterString;
186 };
187 
188 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerProxyModel::Filters )
189 
190 #endif // QGSMAPLAYERPROXYMODEL_H
Base class for all map layer types.
Definition: qgsmaplayer.h:64
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
QList< QgsMapLayer * > exceptedLayerList()
Returns the blacklist of layers which are excluded from the model.
QStringList excludedProviders() const
Returns the blacklist of data providers which are excluded from the model.
QList< QgsMapLayer * > layerWhitelist()
Returns the list of layers which are excluded from the model.
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...
QgsMapLayerModel * sourceLayerModel() const
layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel
QString filterString() const
Returns the current filter string, if set.
const Filters & filters() const
Returns the filter flags which affect how layers are filtered within the model.