QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
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 
203  private:
204  QStringList mHiddenDataItemsKeys;
205  QStringList mShownDataItemsKeys;
206  QgsBrowserModel *mModel = nullptr;
207  QString mFilter; //filter string provided
208  QVector<QRegExp> mREList; //list of filters, separated by "|"
209  FilterSyntax mPatternSyntax = Normal;
210  Qt::CaseSensitivity mCaseSensitivity = Qt::CaseInsensitive;
211 
212  bool mFilterByLayerType = false;
213  bool mShowLayers = true;
215 
217  void updateFilter();
218 
220  bool filterAcceptsString( const QString &value ) const;
221 
223  bool filterAcceptsAncestor( const QModelIndex &sourceIndex ) const;
224 
226  bool filterAcceptsDescendant( const QModelIndex &sourceIndex ) const;
227 
229  bool filterAcceptsItem( const QModelIndex &sourceIndex ) const;
230 
232  bool filterAcceptsProviderKey( const QModelIndex &sourceIndex ) const;
233 
235  bool filterRootAcceptsProviderKey( const QModelIndex &sourceIndex ) const;
236 
237 
238 
239  // QAbstractItemModel interface
240  public:
241  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
242 };
243 
244 #endif // QGSBROWSERPROXYMODEL_H
QgsMapLayerType::VectorLayer
@ VectorLayer
QgsBrowserProxyModel::browserModel
QgsBrowserModel * browserModel()
Returns the underlying browser model.
Definition: qgsbrowserproxymodel.h:62
QgsMapLayerType
QgsMapLayerType
Definition: qgsmaplayer.h:67
QgsBrowserProxyModel
Definition: qgsbrowserproxymodel.h:32
QgsBrowserProxyModel::RegularExpression
@ RegularExpression
Regular expression filtering.
Definition: qgsbrowserproxymodel.h:42
qgsmaplayer.h
QgsBrowserProxyModel::Wildcards
@ Wildcards
Wildcard filtering.
Definition: qgsbrowserproxymodel.h:41
qgis_sip.h
QgsBrowserProxyModel::filterByLayerType
bool filterByLayerType() const
Returns true if the model is filtered by map layer type.
Definition: qgsbrowserproxymodel.h:118
QgsBrowserProxyModel::Normal
@ Normal
Standard string filtering.
Definition: qgsbrowserproxymodel.h:40
QgsDataItem
Definition: qgsdataitem.h:49
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsBrowserProxyModel::FilterSyntax
FilterSyntax
Filter syntax options.
Definition: qgsbrowserproxymodel.h:38
QgsBrowserModel
Definition: qgsbrowsermodel.h:73