QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 "qgis.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 
162  void setHiddenDataItemProviderKeyFilter( const QStringList &hiddenItemsFilter );
163 
180  void setShownDataItemProviderKeyFilter( const QStringList &shownItemsFilter );
181 
188  bool showLayers() const;
189 
196  void setShowLayers( bool showLayers );
197 
198  protected:
199 
200  // It would be better to apply the filer only to expanded (visible) items, but using mapFromSource() + view here was causing strange errors
201  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
202 
206  QgsBrowserModel *mModel = nullptr;
207 
208  private:
209  QStringList mHiddenDataItemsKeys;
210  QStringList mShownDataItemsKeys;
211  QString mFilter; //filter string provided
212  QVector<QRegularExpression> mREList; //list of filters, separated by "|"
213  FilterSyntax mPatternSyntax = Normal;
214  Qt::CaseSensitivity mCaseSensitivity = Qt::CaseInsensitive;
215 
216  bool mFilterByLayerType = false;
217  bool mShowLayers = true;
219 
221  void updateFilter();
222 
224  bool filterAcceptsString( const QString &value ) const;
225 
227  bool filterAcceptsAncestor( const QModelIndex &sourceIndex ) const;
228 
230  bool filterAcceptsDescendant( const QModelIndex &sourceIndex ) const;
231 
233  bool filterAcceptsItem( const QModelIndex &sourceIndex ) const;
234 
236  bool filterAcceptsProviderKey( const QModelIndex &sourceIndex ) const;
237 
239  bool filterRootAcceptsProviderKey( const QModelIndex &sourceIndex ) const;
240 
241 
242 
243  // QAbstractItemModel interface
244  public:
245  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
246 };
247 
248 #endif // QGSBROWSERPROXYMODEL_H
A model for showing available data sources and other items in a structured tree.
A QSortFilterProxyModel subclass for filtering and sorting browser model items.
FilterSyntax
Filter syntax options.
@ RegularExpression
Regular expression filtering.
@ Wildcards
Wildcard filtering.
@ Normal
Standard string filtering.
bool filterByLayerType() const
Returns true if the model is filtered by map layer type.
QgsBrowserModel * browserModel()
Returns the underlying browser model.
Base class for all items in the model.
Definition: qgsdataitem.h:46
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:47
@ VectorLayer
Vector layer.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53