QGIS API Documentation  2.99.0-Master (08c2e66)
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 : denis.rouzaud@gmail.com
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 
24 class QgsMapLayerModel;
25 class QgsMapLayer;
26 
31 class CORE_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
32 {
33  Q_OBJECT
34  Q_FLAGS( Filters )
35 
36  Q_PROPERTY( QgsMapLayerProxyModel::Filters filters READ filters WRITE setFilters )
37  Q_PROPERTY( QList<QgsMapLayer*> exceptedLayerList READ exceptedLayerList WRITE setExceptedLayerList )
38  Q_PROPERTY( QStringList exceptedLayerIds READ exceptedLayerIds WRITE setExceptedLayerIds )
39 
40  public:
41  enum Filter
42  {
43  RasterLayer = 1,
44  NoGeometry = 2,
45  PointLayer = 4,
46  LineLayer = 8,
47  PolygonLayer = 16,
48  HasGeometry = PointLayer | LineLayer | PolygonLayer,
49  VectorLayer = NoGeometry | HasGeometry,
50  PluginLayer = 32,
51  WritableLayer = 64,
52  All = RasterLayer | VectorLayer | PluginLayer
53  };
54  Q_DECLARE_FLAGS( Filters, Filter )
55 
56 
60  explicit QgsMapLayerProxyModel( QObject *parent = nullptr );
61 
65  QgsMapLayerModel* sourceLayerModel() const { return mModel; }
66 
72  QgsMapLayerProxyModel* setFilters( QgsMapLayerProxyModel::Filters filters );
73  const Filters& filters() const { return mFilters; }
74 
76  void setExceptedLayerList( const QList<QgsMapLayer*>& exceptList );
78  QList<QgsMapLayer*> exceptedLayerList() {return mExceptList;}
79 
81  void setExceptedLayerIds( const QStringList& ids );
83  QStringList exceptedLayerIds() const;
84 
90  void setExcludedProviders( const QStringList& providers );
91 
97  QStringList excludedProviders() const { return mExcludedProviders; }
98 
99  private:
100  Filters mFilters;
101  QList<QgsMapLayer*> mExceptList;
102  QgsMapLayerModel* mModel = nullptr;
103  QStringList mExcludedProviders;
104 
105  // QSortFilterProxyModel interface
106  public:
107  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
108  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
109 };
110 
111 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerProxyModel::Filters )
112 
113 #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:52
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