QGIS API Documentation  2.99.0-Master (c558d51)
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 class QgsMapLayerModel;
23 class QgsMapLayer;
24 
29 class CORE_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
30 {
31  Q_OBJECT
32  Q_FLAGS( Filters )
33 
34  Q_PROPERTY( QgsMapLayerProxyModel::Filters filters READ filters WRITE setFilters )
35  Q_PROPERTY( QList<QgsMapLayer*> exceptedLayerList READ exceptedLayerList WRITE setExceptedLayerList )
36  Q_PROPERTY( QStringList exceptedLayerIds READ exceptedLayerIds WRITE setExceptedLayerIds )
37 
38  public:
39  enum Filter
40  {
41  RasterLayer = 1,
42  NoGeometry = 2,
43  PointLayer = 4,
44  LineLayer = 8,
45  PolygonLayer = 16,
46  HasGeometry = PointLayer | LineLayer | PolygonLayer,
47  VectorLayer = NoGeometry | HasGeometry,
48  PluginLayer = 32,
49  WritableLayer = 64,
50  All = RasterLayer | VectorLayer | PluginLayer
51  };
52  Q_DECLARE_FLAGS( Filters, Filter )
53 
54 
58  explicit QgsMapLayerProxyModel( QObject *parent = nullptr );
59 
63  QgsMapLayerModel* sourceLayerModel() const { return mModel; }
64 
70  QgsMapLayerProxyModel* setFilters( QgsMapLayerProxyModel::Filters filters );
71  const Filters& filters() const { return mFilters; }
72 
74  void setExceptedLayerList( const QList<QgsMapLayer*>& exceptList );
76  QList<QgsMapLayer*> exceptedLayerList() {return mExceptList;}
77 
79  void setExceptedLayerIds( const QStringList& ids );
81  QStringList exceptedLayerIds() const;
82 
88  void setExcludedProviders( const QStringList& providers );
89 
95  QStringList excludedProviders() const { return mExcludedProviders; }
96 
97  private:
98  Filters mFilters;
99  QList<QgsMapLayer*> mExceptList;
100  QgsMapLayerModel* mModel;
101  QStringList mExcludedProviders;
102 
103  // QSortFilterProxyModel interface
104  public:
105  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
106  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
107 };
108 
109 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerProxyModel::Filters )
110 
111 #endif // QGSMAPLAYERPROXYMODEL_H
QList< QgsMapLayer * > exceptedLayerList()
Get the list of maplayers which are excluded from the list.
Base class for all map layer types.
Definition: qgsmaplayer.h:49
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...
QStringList excludedProviders() const
Returns the list of data providers which are excluded from the model.
const Filters & filters() const