QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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  QgsMapLayer::LayerType layerType() const;
136 
144  void setLayerType( QgsMapLayer::LayerType type );
145 
146  protected:
147 
148  // It would be better to apply the filer only to expanded (visible) items, but using mapFromSource() + view here was causing strange errors
149  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
150 
151  private:
152 
153  QgsBrowserModel *mModel = nullptr;
154  QString mFilter; //filter string provided
155  QVector<QRegExp> mREList; //list of filters, separated by "|"
156  FilterSyntax mPatternSyntax = Normal;
157  Qt::CaseSensitivity mCaseSensitivity = Qt::CaseInsensitive;
158 
159  bool mFilterByLayerType = false;
161 
163  void updateFilter();
164 
166  bool filterAcceptsString( const QString &value ) const;
167 
169  bool filterAcceptsAncestor( const QModelIndex &sourceIndex ) const;
170 
172  bool filterAcceptsDescendant( const QModelIndex &sourceIndex ) const;
173 
175  bool filterAcceptsItem( const QModelIndex &sourceIndex ) const;
176 };
177 
178 #endif // QGSBROWSERPROXYMODEL_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
FilterSyntax
Filter syntax options.
bool filterByLayerType() const
Returns true if the model is filtered by map layer type.
LayerType
Types of layers that can be added to a map.
Definition: qgsmaplayer.h:105
QgsBrowserModel * browserModel()
Returns the underlying browser model.
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.