QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgslayertreefilterproxymodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayertreefilterproxymodel.h
3 
4  ---------------------
5  begin : 05.06.2020
6  copyright : (C) 2020 by Denis Rouzaud
7  email : [email protected]
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSLAYERTREEFILTERPROXYMODEL_H
18 #define QGSLAYERTREEFILTERPROXYMODEL_H
19 
20 #include <QSortFilterProxyModel>
21 
22 #include "qgis_core.h"
23 #include "qgsmaplayer.h"
24 #include "qgsmaplayerproxymodel.h"
25 
26 class QgsLayerTreeModel;
27 class QgsLayerTreeNode;
28 
40 class CORE_EXPORT QgsLayerTreeFilterProxyModel : public QSortFilterProxyModel
41 {
42  Q_OBJECT
43  public:
45  QgsLayerTreeFilterProxyModel( QObject *parent = nullptr );
46 
51  void setCheckedLayers( const QList<QgsMapLayer *> layers );
52 
54  QList<QgsMapLayer *> checkedLayers() const {return mCheckedLayers;}
55 
57  QgsMapLayer *mapLayer( const QModelIndex &idx ) const;
58 
60  QgsLayerTreeModel *layerTreeModel() const;
62  void setLayerTreeModel( QgsLayerTreeModel *layerTreeModel );
63 
68  void setFilters( const QgsMapLayerProxyModel::Filters &filters );
69 
70  virtual int columnCount( const QModelIndex &parent ) const override;
71  virtual Qt::ItemFlags flags( const QModelIndex &idx ) const override;
72  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
73  QModelIndex parent( const QModelIndex &child ) const override;
74  QModelIndex sibling( int row, int column, const QModelIndex &idx ) const override;
75  virtual QVariant data( const QModelIndex &index, int role ) const override;
76  virtual bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
77 
78  public slots:
80  virtual void setFilterText( const QString &filterText = QString() );
81 
82  protected:
84  virtual bool isLayerChecked( QgsMapLayer *layer ) const;
85 
87  virtual void setLayerChecked( QgsMapLayer *layer, bool checked );
88 
89  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
90 
91  private:
92 
97  virtual bool layerShown( QgsMapLayer *layer ) const;
98 
99  bool nodeShown( QgsLayerTreeNode *node ) const;
100 
102  void setLayerCheckedPrivate( QgsMapLayer *layer, bool checked );
103 
104  QgsLayerTreeModel *mLayerTreeModel = nullptr;
105  QList<QgsMapLayer *> mCheckedLayers;
106  QString mFilterText;
107  QgsMapLayerProxyModel::Filters mFilters = QgsMapLayerProxyModel::All;
108 };
109 
110 #endif // QGSLAYERTREEFILTERPROXYMODEL_H
QgsLayerTreeNode
This class is a base class for nodes in a layer tree.
Definition: qgslayertreenode.h:75
QgsLayerTreeModel
The QgsLayerTreeModel class is model implementation for Qt item views framework.
Definition: qgslayertreemodel.h:54
QgsLayerTreeFilterProxyModel
QgsLayerTreeFilterProxyModel is a sort filter proxy model to easily reproduce the legend/layer tree i...
Definition: qgslayertreefilterproxymodel.h:41
qgsmaplayer.h
QgsLayerTreeFilterProxyModel::checkedLayers
QList< QgsMapLayer * > checkedLayers() const
Returns the checked layers.
Definition: qgslayertreefilterproxymodel.h:54
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsMapLayerProxyModel::All
@ All
Definition: qgsmaplayerproxymodel.h:55
qgsmaplayerproxymodel.h