QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 
41 class CORE_EXPORT QgsLayerTreeFilterProxyModel : public QSortFilterProxyModel
42 {
43  Q_OBJECT
44  public:
46  QgsLayerTreeFilterProxyModel( QObject *parent = nullptr );
47 
52  void setCheckedLayers( const QList<QgsMapLayer *> layers );
53 
55  QList<QgsMapLayer *> checkedLayers() const {return mCheckedLayers;}
56 
58  QgsMapLayer *mapLayer( const QModelIndex &idx ) const;
59 
61  QgsLayerTreeModel *layerTreeModel() const;
63  void setLayerTreeModel( QgsLayerTreeModel *layerTreeModel );
64 
69  void setFilters( const QgsMapLayerProxyModel::Filters &filters );
70 
71  virtual int columnCount( const QModelIndex &parent ) const override;
72  virtual Qt::ItemFlags flags( const QModelIndex &idx ) const override;
73  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
74  QModelIndex parent( const QModelIndex &child ) const override;
75  QModelIndex sibling( int row, int column, const QModelIndex &idx ) const override;
76  virtual QVariant data( const QModelIndex &index, int role ) const override;
77  virtual bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
78 
79  public slots:
81  virtual void setFilterText( const QString &filterText = QString() );
82 
83  protected:
85  virtual bool isLayerChecked( QgsMapLayer *layer ) const;
86 
88  virtual void setLayerChecked( QgsMapLayer *layer, bool checked );
89 
90  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
91 
92  private:
93 
98  virtual bool layerShown( QgsMapLayer *layer ) const;
99 
100  bool nodeShown( QgsLayerTreeNode *node ) const;
101 
103  void setLayerCheckedPrivate( QgsMapLayer *layer, bool checked );
104 
105  QgsLayerTreeModel *mLayerTreeModel = nullptr;
106  QList<QgsMapLayer *> mCheckedLayers;
107  QString mFilterText;
108  QgsMapLayerProxyModel::Filters mFilters = QgsMapLayerProxyModel::All;
109 };
110 
111 #endif // QGSLAYERTREEFILTERPROXYMODEL_H
QgsLayerTreeFilterProxyModel is a sort filter proxy model to easily reproduce the legend/layer tree i...
QList< QgsMapLayer * > checkedLayers() const
Returns the checked layers.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
This class is a base class for nodes in a layer tree.
Base class for all map layer types.
Definition: qgsmaplayer.h:73