QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  VectorTileLayer = 256,
55  All = RasterLayer | VectorLayer | PluginLayer | MeshLayer | VectorTileLayer
56  };
57  Q_DECLARE_FLAGS( Filters, Filter )
58  Q_FLAG( Filters )
59 
60 
64  explicit QgsMapLayerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
65 
69  QgsMapLayerModel *sourceLayerModel() const { return mModel; }
70 
78  QgsMapLayerProxyModel *setFilters( QgsMapLayerProxyModel::Filters filters );
79 
87  const Filters &filters() const { return mFilters; }
88 
93  static bool layerMatchesFilters( const QgsMapLayer *layer, const Filters &filters );
94 
106  Q_DECL_DEPRECATED void setLayerWhitelist( const QList<QgsMapLayer *> &layers ) SIP_DEPRECATED;
107 
119  void setLayerAllowlist( const QList<QgsMapLayer *> &layers );
120 
131  Q_DECL_DEPRECATED QList<QgsMapLayer *> layerWhitelist() SIP_DEPRECATED {return mLayerAllowlist;}
132 
143  QList<QgsMapLayer *> layerAllowlist() {return mLayerAllowlist;}
144 
151  void setExceptedLayerList( const QList<QgsMapLayer *> &exceptList );
152 
159  QList<QgsMapLayer *> exceptedLayerList() {return mExceptList;}
160 
166  void setExceptedLayerIds( const QStringList &ids );
167 
173  QStringList exceptedLayerIds() const;
174 
180  void setExcludedProviders( const QStringList &providers );
181 
187  QStringList excludedProviders() const { return mExcludedProviders; }
188 
195  QString filterString() const { return mFilterString; }
196 
202  bool acceptsLayer( QgsMapLayer *layer ) const;
203 
204  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
205  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
206 
207  public slots:
208 
216  void setFilterString( const QString &filter );
217 
218  private:
219  Filters mFilters;
220  QList<QgsMapLayer *> mExceptList;
221  QList<QgsMapLayer *> mLayerAllowlist;
222  QgsMapLayerModel *mModel = nullptr;
223  QStringList mExcludedProviders;
224  QString mFilterString;
225 };
226 
227 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerProxyModel::Filters )
228 
229 #endif // QGSMAPLAYERPROXYMODEL_H
QgsMapLayerProxyModel::filters
const Filters & filters() const
Returns the filter flags which affect how layers are filtered within the model.
Definition: qgsmaplayerproxymodel.h:87
QgsMapLayerProxyModel::filterString
QString filterString() const
Returns the current filter string, if set.
Definition: qgsmaplayerproxymodel.h:195
QgsMapLayerProxyModel::sourceLayerModel
QgsMapLayerModel * sourceLayerModel() const
layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel
Definition: qgsmaplayerproxymodel.h:69
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsMapLayerProxyModel::excludedProviders
QStringList excludedProviders() const
Returns the blocklist of data providers which are excluded from the model.
Definition: qgsmaplayerproxymodel.h:187
QgsMapLayerProxyModel::Filter
Filter
Definition: qgsmaplayerproxymodel.h:43
QgsMapLayerProxyModel
The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widget...
Definition: qgsmaplayerproxymodel.h:34
qgis_sip.h
Q_DECLARE_OPERATORS_FOR_FLAGS
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
QgsMapLayerProxyModel::layerAllowlist
QList< QgsMapLayer * > layerAllowlist()
Returns the list of layers which are excluded from the model.
Definition: qgsmaplayerproxymodel.h:143
QgsMapLayerProxyModel::exceptedLayerList
QList< QgsMapLayer * > exceptedLayerList()
Returns the blocklist of layers which are excluded from the model.
Definition: qgsmaplayerproxymodel.h:159
QgsMapLayerProxyModel::layerWhitelist
Q_DECL_DEPRECATED QList< QgsMapLayer * > layerWhitelist()
Returns the list of layers which are excluded from the model.
Definition: qgsmaplayerproxymodel.h:131
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsMapLayerModel
The QgsMapLayerModel class is a model to display layers in widgets.
Definition: qgsmaplayermodel.h:37