QGIS API Documentation 3.33.0-Master (bf22a165b3)
Loading...
Searching...
No Matches
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
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
26class QgsMapLayer;
27class QgsProject;
28
34class 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 {
45 RasterLayer = 1,
46 NoGeometry = 2,
47 PointLayer = 4,
48 LineLayer = 8,
49 PolygonLayer = 16,
50 HasGeometry = PointLayer | LineLayer | PolygonLayer,
51 VectorLayer = NoGeometry | HasGeometry,
52 PluginLayer = 32,
53 WritableLayer = 64,
54 MeshLayer = 128,
55 VectorTileLayer = 256,
56 PointCloudLayer = 512,
57 AnnotationLayer = 1024,
58 TiledSceneLayer = 2048,
59 All = RasterLayer | VectorLayer | PluginLayer | MeshLayer | VectorTileLayer | PointCloudLayer | AnnotationLayer | TiledSceneLayer,
60 SpatialLayer = RasterLayer | HasGeometry | PluginLayer | MeshLayer | VectorTileLayer | PointCloudLayer | AnnotationLayer | TiledSceneLayer
61 };
62 Q_DECLARE_FLAGS( Filters, Filter )
63 Q_FLAG( Filters )
64
65
69 explicit QgsMapLayerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
70
74 QgsMapLayerModel *sourceLayerModel() const { return mModel; }
75
83 QgsMapLayerProxyModel *setFilters( QgsMapLayerProxyModel::Filters filters );
84
92 const Filters &filters() const { return mFilters; }
93
101 void setProject( QgsProject *project );
102
107 static bool layerMatchesFilters( const QgsMapLayer *layer, const Filters &filters );
108
120 Q_DECL_DEPRECATED void setLayerWhitelist( const QList<QgsMapLayer *> &layers ) SIP_DEPRECATED;
121
133 void setLayerAllowlist( const QList<QgsMapLayer *> &layers );
134
145 Q_DECL_DEPRECATED QList<QgsMapLayer *> layerWhitelist() SIP_DEPRECATED {return mLayerAllowlist;}
146
157 QList<QgsMapLayer *> layerAllowlist() {return mLayerAllowlist;}
158
165 void setExceptedLayerList( const QList<QgsMapLayer *> &exceptList );
166
173 QList<QgsMapLayer *> exceptedLayerList() {return mExceptList;}
174
180 void setExceptedLayerIds( const QStringList &ids );
181
187 QStringList exceptedLayerIds() const;
188
194 void setExcludedProviders( const QStringList &providers );
195
201 QStringList excludedProviders() const { return mExcludedProviders; }
202
209 QString filterString() const { return mFilterString; }
210
216 bool acceptsLayer( QgsMapLayer *layer ) const;
217
218 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
219 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
220
221 public slots:
222
230 void setFilterString( const QString &filter );
231
232 private:
233 Filters mFilters;
234 QList<QgsMapLayer *> mExceptList;
235 QList<QgsMapLayer *> mLayerAllowlist;
236 QgsMapLayerModel *mModel = nullptr;
237 QStringList mExcludedProviders;
238 QString mFilterString;
239};
240
241Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerProxyModel::Filters )
242
243#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...
QList< QgsMapLayer * > exceptedLayerList()
Returns the blocklist of layers which are excluded from the model.
QList< QgsMapLayer * > layerAllowlist()
Returns the list of layers which are excluded from the model.
QgsMapLayerModel * sourceLayerModel() const
layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel
QStringList excludedProviders() const
Returns the blocklist of data providers which are excluded from the model.
Q_DECL_DEPRECATED QList< QgsMapLayer * > layerWhitelist()
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.
QString filterString() const
Returns the current filter string, if set.
Base class for all map layer types.
Definition qgsmaplayer.h:74
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
#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.