QGIS API Documentation  2.99.0-Master (19b062c)
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.h"
24 
25 class QgsMapLayerModel;
26 class QgsMapLayer;
27 
33 class CORE_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
34 {
35  Q_OBJECT
36  Q_FLAGS( Filters )
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  All = RasterLayer | VectorLayer | PluginLayer
55  };
56  Q_DECLARE_FLAGS( Filters, Filter )
57 
58 
62  explicit QgsMapLayerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
63 
67  QgsMapLayerModel *sourceLayerModel() const { return mModel; }
68 
74  QgsMapLayerProxyModel *setFilters( QgsMapLayerProxyModel::Filters filters );
75  const Filters &filters() const { return mFilters; }
76 
78  void setExceptedLayerList( const QList<QgsMapLayer *> &exceptList );
80  QList<QgsMapLayer *> exceptedLayerList() {return mExceptList;}
81 
83  void setExceptedLayerIds( const QStringList &ids );
85  QStringList exceptedLayerIds() const;
86 
92  void setExcludedProviders( const QStringList &providers );
93 
99  QStringList excludedProviders() const { return mExcludedProviders; }
100 
101  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
102  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
103 
104  private:
105  Filters mFilters;
106  QList<QgsMapLayer *> mExceptList;
107  QgsMapLayerModel *mModel = nullptr;
108  QStringList mExcludedProviders;
109 };
110 
111 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerProxyModel::Filters )
112 
113 #endif // QGSMAPLAYERPROXYMODEL_H
Base class for all map layer types.
Definition: qgsmaplayer.h:56
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
QList< QgsMapLayer * > exceptedLayerList()
Get the list of maplayers which are excluded from the list.
QStringList excludedProviders() const
Returns the list of data providers which are excluded from the model.
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...
QgsMapLayerModel * sourceLayerModel() const
layerModel returns the QgsMapLayerModel used in this QSortFilterProxyModel
const Filters & filters() const