QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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 "qgis.h"
20#include "qgis_core.h"
21#include "qgis_sip.h"
22
23#include <QSortFilterProxyModel>
24#include <QStringList>
25
27class QgsMapLayer;
28class QgsProject;
29
34class CORE_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
35{
36 Q_OBJECT
37
40 Q_PROPERTY( QStringList exceptedLayerIds READ exceptedLayerIds WRITE setExceptedLayerIds )
41
42 public:
43
48 explicit QgsMapLayerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
49
53 QgsMapLayerModel *sourceLayerModel() const { return mModel; }
54
61 QgsMapLayerProxyModel *setFilters( Qgis::LayerFilters filters );
62
69 Q_DECL_DEPRECATED void setFilters( int filters ) SIP_DEPRECATED { setFilters( static_cast<Qgis::LayerFilters>( filters ) ); }
70
77 const Qgis::LayerFilters &filters() const { return mFilters; }
78
86 void setProject( QgsProject *project );
87
92 static bool layerMatchesFilters( const QgsMapLayer *layer, const Qgis::LayerFilters &filters );
93
105 Q_DECL_DEPRECATED void setLayerWhitelist( const QList<QgsMapLayer *> &layers ) SIP_DEPRECATED;
106
118 void setLayerAllowlist( const QList<QgsMapLayer *> &layers );
119
130 Q_DECL_DEPRECATED QList<QgsMapLayer *> layerWhitelist() SIP_DEPRECATED {return mLayerAllowlist;}
131
142 QList<QgsMapLayer *> layerAllowlist() {return mLayerAllowlist;}
143
150 void setExceptedLayerList( const QList<QgsMapLayer *> &exceptList );
151
158 QList<QgsMapLayer *> exceptedLayerList() {return mExceptList;}
159
165 void setExceptedLayerIds( const QStringList &ids );
166
172 QStringList exceptedLayerIds() const;
173
178 void setExcludedProviders( const QStringList &providers );
179
184 QStringList excludedProviders() const { return mExcludedProviders; }
185
192 QString filterString() const { return mFilterString; }
193
199 bool acceptsLayer( QgsMapLayer *layer ) const;
200
201 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
202 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
203
204 public slots:
205
213 void setFilterString( const QString &filter );
214
215 private:
216 Qgis::LayerFilters mFilters;
217 QList<QgsMapLayer *> mExceptList;
218 QList<QgsMapLayer *> mLayerAllowlist;
219 QgsMapLayerModel *mModel = nullptr;
220 QStringList mExcludedProviders;
221 QString mFilterString;
222};
223
224#endif // QGSMAPLAYERPROXYMODEL_H
QFlags< LayerFilter > LayerFilters
Definition qgis.h:227
A model for display of map layers in widgets.
A proxy model which provides an easy to use model to display the list of layers in widgets.
const Qgis::LayerFilters & filters() const
Returns the filter flags which affect how layers are filtered within the model.
void setExceptedLayerIds(const QStringList &ids)
Sets a blocklist of layers (by layer ID) to exclude from the model.
QList< QgsMapLayer * > exceptedLayerList()
Returns the blocklist of layers which are excluded from the model.
QgsMapLayerProxyModel(QObject *parent=nullptr)
QgsMapLayerProxModel creates a proxy model with a QgsMapLayerModel as source model.
QgsMapLayerProxyModel * setFilters(Qgis::LayerFilters filters)
Sets filter flags which affect how layers are filtered within the model.
QList< QgsMapLayer * > layerAllowlist()
Returns the list of layers which are excluded from the model.
QList< QgsMapLayer * > exceptedLayerList
QgsMapLayerModel * sourceLayerModel() const
layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel
Q_DECL_DEPRECATED void setFilters(int filters)
Filters according to layer type and/or geometry type.
void setExceptedLayerList(const QList< QgsMapLayer * > &exceptList)
Sets a blocklist of layers to exclude from the model.
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.
QString filterString() const
Returns the current filter string, if set.
Base class for all map layer types.
Definition qgsmaplayer.h:80
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53