QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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
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"
25
28
41class 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
72 bool showPrivateLayers() const;
73
81 void setShowPrivateLayers( bool showPrivate );
82
87 void setFilters( Qgis::LayerFilters filters );
88
89 virtual int columnCount( const QModelIndex &parent ) const override;
90 virtual Qt::ItemFlags flags( const QModelIndex &idx ) const override;
91 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
92 QModelIndex parent( const QModelIndex &child ) const override;
93 QModelIndex sibling( int row, int column, const QModelIndex &idx ) const override;
94 virtual QVariant data( const QModelIndex &index, int role ) const override;
95 virtual bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
96
102 bool nodeShown( QgsLayerTreeNode *node ) const;
103
104 public slots:
106 virtual void setFilterText( const QString &filterText = QString() );
107
108 protected:
110 virtual bool isLayerChecked( QgsMapLayer *layer ) const;
111
113 virtual void setLayerChecked( QgsMapLayer *layer, bool checked );
114
115 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
116
117 private:
118
123 virtual bool layerShown( QgsMapLayer *layer ) const;
124
126 void setLayerCheckedPrivate( QgsMapLayer *layer, bool checked );
127
128 QgsLayerTreeModel *mLayerTreeModel = nullptr;
129 QList<QgsMapLayer *> mCheckedLayers;
130 QString mFilterText;
131 // for compatibility this defaults to true
132 bool mShowPrivateLayers = true;
134};
135
136#endif // QGSLAYERTREEFILTERPROXYMODEL_H
@ All
All layers.
QFlags< LayerFilter > LayerFilters
Definition qgis.h:206
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:76