QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
qgsbrowserproxymodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsbrowserproxymodel.h
3  ---------------------
4  begin : October 2018
5  copyright : (C) 2018 by Nyall Dawson
6  email : nyall dot dawson at gmail dot 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 #ifndef QGSBROWSERPROXYMODEL_H
16 #define QGSBROWSERPROXYMODEL_H
17 
18 #include "qgis_core.h"
19 #include "qgis_sip.h"
20 #include "qgsmaplayer.h"
21 #include <QSortFilterProxyModel>
22 
23 class QgsBrowserModel;
24 class QgsDataItem;
25 
32 class CORE_EXPORT QgsBrowserProxyModel : public QSortFilterProxyModel
33 {
34  Q_OBJECT
35  public:
36 
39  {
43  };
44 
48  explicit QgsBrowserProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
49 
55  void setBrowserModel( QgsBrowserModel *model );
56 
62  QgsBrowserModel *browserModel() { return mModel; }
63 
68  QgsDataItem *dataItem( const QModelIndex &index ) const;
69 
75  void setFilterSyntax( FilterSyntax syntax );
76 
82  FilterSyntax filterSyntax() const;
83 
89  void setFilterString( const QString &filter );
90 
96  QString filterString() const;
97 
103  void setFilterCaseSensitivity( Qt::CaseSensitivity sensitivity );
104 
110  Qt::CaseSensitivity caseSensitivity() const;
111 
118  bool filterByLayerType() const { return mFilterByLayerType; }
119 
126  void setFilterByLayerType( bool enabled );
127 
135  QgsMapLayerType layerType() const;
136 
144  void setLayerType( QgsMapLayerType type );
145 
159  void setDataItemProviderKeyFilter( const QStringList &filter );
160 
161  protected:
162 
163  // It would be better to apply the filer only to expanded (visible) items, but using mapFromSource() + view here was causing strange errors
164  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
165 
166  private:
167  QStringList mHiddenDataItemsKeys;
168  QgsBrowserModel *mModel = nullptr;
169  QString mFilter; //filter string provided
170  QVector<QRegExp> mREList; //list of filters, separated by "|"
171  FilterSyntax mPatternSyntax = Normal;
172  Qt::CaseSensitivity mCaseSensitivity = Qt::CaseInsensitive;
173 
174  bool mFilterByLayerType = false;
176 
178  void updateFilter();
179 
181  bool filterAcceptsString( const QString &value ) const;
182 
184  bool filterAcceptsAncestor( const QModelIndex &sourceIndex ) const;
185 
187  bool filterAcceptsDescendant( const QModelIndex &sourceIndex ) const;
188 
190  bool filterAcceptsItem( const QModelIndex &sourceIndex ) const;
191 
193  bool filterAcceptsProviderKey( const QModelIndex &sourceIndex ) const;
194 
196  bool filterRootAcceptsProviderKey( const QModelIndex &sourceIndex ) const;
197 };
198 
199 #endif // QGSBROWSERPROXYMODEL_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
FilterSyntax
Filter syntax options.
QgsBrowserModel * browserModel()
Returns the underlying browser model.
bool filterByLayerType() const
Returns true if the model is filtered by map layer type.
Base class for all items in the model.
Definition: qgsdataitem.h:49
Standard string filtering.
A QSortFilterProxyModel subclass for filtering and sorting browser model items.
A model for showing available data sources and other items in a structured tree.
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgsmaplayer.h:66