QGIS API Documentation  3.27.0-Master (597e8eebd4)
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 class QgsProject;
28 
34 class CORE_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
35 {
36  Q_OBJECT
37 
38  Q_PROPERTY( QgsMapLayerProxyModel::Filters filters READ filters WRITE setFilters )
39  Q_PROPERTY( QList<QgsMapLayer *> exceptedLayerList READ exceptedLayerList WRITE setExceptedLayerList )
40  Q_PROPERTY( QStringList exceptedLayerIds READ exceptedLayerIds WRITE setExceptedLayerIds )
41 
42  public:
43  enum Filter
44  {
46  NoGeometry = 2,
47  PointLayer = 4,
48  LineLayer = 8,
49  PolygonLayer = 16,
50  HasGeometry = PointLayer | LineLayer | PolygonLayer,
51  VectorLayer = NoGeometry | HasGeometry,
53  WritableLayer = 64,
54  MeshLayer = 128,
57  AnnotationLayer = 1024,
59  SpatialLayer = RasterLayer | HasGeometry | PluginLayer | MeshLayer | VectorTileLayer | PointCloudLayer | AnnotationLayer
60  };
61  Q_DECLARE_FLAGS( Filters, Filter )
62  Q_FLAG( Filters )
63 
64 
68  explicit QgsMapLayerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
69 
73  QgsMapLayerModel *sourceLayerModel() const { return mModel; }
74 
82  QgsMapLayerProxyModel *setFilters( QgsMapLayerProxyModel::Filters filters );
83 
91  const Filters &filters() const { return mFilters; }
92 
100  void setProject( QgsProject *project );
101 
106  static bool layerMatchesFilters( const QgsMapLayer *layer, const Filters &filters );
107 
119  Q_DECL_DEPRECATED void setLayerWhitelist( const QList<QgsMapLayer *> &layers ) SIP_DEPRECATED;
120 
132  void setLayerAllowlist( const QList<QgsMapLayer *> &layers );
133 
144  Q_DECL_DEPRECATED QList<QgsMapLayer *> layerWhitelist() SIP_DEPRECATED {return mLayerAllowlist;}
145 
156  QList<QgsMapLayer *> layerAllowlist() {return mLayerAllowlist;}
157 
164  void setExceptedLayerList( const QList<QgsMapLayer *> &exceptList );
165 
172  QList<QgsMapLayer *> exceptedLayerList() {return mExceptList;}
173 
179  void setExceptedLayerIds( const QStringList &ids );
180 
186  QStringList exceptedLayerIds() const;
187 
193  void setExcludedProviders( const QStringList &providers );
194 
200  QStringList excludedProviders() const { return mExcludedProviders; }
201 
208  QString filterString() const { return mFilterString; }
209 
215  bool acceptsLayer( QgsMapLayer *layer ) const;
216 
217  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
218  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
219 
220  public slots:
221 
229  void setFilterString( const QString &filter );
230 
231  private:
232  Filters mFilters;
233  QList<QgsMapLayer *> mExceptList;
234  QList<QgsMapLayer *> mLayerAllowlist;
235  QgsMapLayerModel *mModel = nullptr;
236  QStringList mExcludedProviders;
237  QString mFilterString;
238 };
239 
240 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerProxyModel::Filters )
241 
242 #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
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:104
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
@ VectorLayer
Vector layer.
@ RasterLayer
Raster layer.
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ PluginLayer
Plugin based layer.
#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.