QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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  {
45  NoGeometry = 2,
46  PointLayer = 4,
47  LineLayer = 8,
48  PolygonLayer = 16,
49  HasGeometry = PointLayer | LineLayer | PolygonLayer,
50  VectorLayer = NoGeometry | HasGeometry,
52  WritableLayer = 64,
53  MeshLayer = 128,
56  AnnotationLayer = 1024,
58  };
59  Q_DECLARE_FLAGS( Filters, Filter )
60  Q_FLAG( Filters )
61 
62 
66  explicit QgsMapLayerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
67 
71  QgsMapLayerModel *sourceLayerModel() const { return mModel; }
72 
80  QgsMapLayerProxyModel *setFilters( QgsMapLayerProxyModel::Filters filters );
81 
89  const Filters &filters() const { return mFilters; }
90 
95  static bool layerMatchesFilters( const QgsMapLayer *layer, const Filters &filters );
96 
108  Q_DECL_DEPRECATED void setLayerWhitelist( const QList<QgsMapLayer *> &layers ) SIP_DEPRECATED;
109 
121  void setLayerAllowlist( const QList<QgsMapLayer *> &layers );
122 
133  Q_DECL_DEPRECATED QList<QgsMapLayer *> layerWhitelist() SIP_DEPRECATED {return mLayerAllowlist;}
134 
145  QList<QgsMapLayer *> layerAllowlist() {return mLayerAllowlist;}
146 
153  void setExceptedLayerList( const QList<QgsMapLayer *> &exceptList );
154 
161  QList<QgsMapLayer *> exceptedLayerList() {return mExceptList;}
162 
168  void setExceptedLayerIds( const QStringList &ids );
169 
175  QStringList exceptedLayerIds() const;
176 
182  void setExcludedProviders( const QStringList &providers );
183 
189  QStringList excludedProviders() const { return mExcludedProviders; }
190 
197  QString filterString() const { return mFilterString; }
198 
204  bool acceptsLayer( QgsMapLayer *layer ) const;
205 
206  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
207  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
208 
209  public slots:
210 
218  void setFilterString( const QString &filter );
219 
220  private:
221  Filters mFilters;
222  QList<QgsMapLayer *> mExceptList;
223  QList<QgsMapLayer *> mLayerAllowlist;
224  QgsMapLayerModel *mModel = nullptr;
225  QStringList mExcludedProviders;
226  QString mFilterString;
227 };
228 
229 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerProxyModel::Filters )
230 
231 #endif // QGSMAPLAYERPROXYMODEL_H
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...
Q_DECL_DEPRECATED QList< QgsMapLayer * > layerWhitelist()
Returns the list of layers which are excluded from the model.
QgsMapLayerModel * sourceLayerModel() const
layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel
QList< QgsMapLayer * > layerAllowlist()
Returns the list of layers which are excluded from the model.
const Filters & filters() const
Returns the filter flags which affect how layers are filtered within the model.
QList< QgsMapLayer * > exceptedLayerList()
Returns the blocklist of layers which are excluded from the model.
QStringList excludedProviders() const
Returns the blocklist of data providers which are excluded from the model.
QString filterString() const
Returns the current filter string, if set.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
@ PointCloudLayer
Added in 3.18.
@ MeshLayer
Added in 3.2.
@ VectorTileLayer
Added in 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
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.