QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
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.h"
19#include "qgis_core.h"
20#include "qgis_sip.h"
21
22#include <QSortFilterProxyModel>
23
24class QgsBrowserModel;
25class QgsDataItem;
26
33class CORE_EXPORT QgsBrowserProxyModel : public QSortFilterProxyModel
34{
35 Q_OBJECT
36 public:
37
45
49 explicit QgsBrowserProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
50
56 void setBrowserModel( QgsBrowserModel *model );
57
64
69 QgsDataItem *dataItem( const QModelIndex &index ) const;
70
76 void setFilterSyntax( FilterSyntax syntax );
77
83 FilterSyntax filterSyntax() const;
84
90 void setFilterString( const QString &filter );
91
97 QString filterString() const;
98
104 void setFilterCaseSensitivity( Qt::CaseSensitivity sensitivity );
105
111 Qt::CaseSensitivity caseSensitivity() const;
112
119 bool filterByLayerType() const { return mFilterByLayerType; }
120
127 void setFilterByLayerType( bool enabled );
128
136 Qgis::LayerType layerType() const;
137
145 void setLayerType( Qgis::LayerType type );
146
163 void setHiddenDataItemProviderKeyFilter( const QStringList &hiddenItemsFilter );
164
181 void setShownDataItemProviderKeyFilter( const QStringList &shownItemsFilter );
182
189 bool showLayers() const;
190
197 void setShowLayers( bool showLayers );
198
199 protected:
200
201 // It would be better to apply the filer only to expanded (visible) items, but using mapFromSource() + view here was causing strange errors
202 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
203
208
209 private:
210 QStringList mHiddenDataItemsKeys;
211 QStringList mShownDataItemsKeys;
212 QString mFilter; //filter string provided
213 QVector<QRegularExpression> mREList; //list of filters, separated by "|"
214 FilterSyntax mPatternSyntax = Normal;
215 Qt::CaseSensitivity mCaseSensitivity = Qt::CaseInsensitive;
216
217 bool mFilterByLayerType = false;
218 bool mShowLayers = true;
220
222 void updateFilter();
223
225 bool filterAcceptsString( const QString &value ) const;
226
228 bool filterAcceptsAncestor( const QModelIndex &sourceIndex ) const;
229
231 bool filterAcceptsDescendant( const QModelIndex &sourceIndex ) const;
232
234 bool filterAcceptsItem( const QModelIndex &sourceIndex ) const;
235
237 bool filterAcceptsProviderKey( const QModelIndex &sourceIndex ) const;
238
240 bool filterRootAcceptsProviderKey( const QModelIndex &sourceIndex ) const;
241
242
243
244 // QAbstractItemModel interface
245 public:
246 bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
247};
248
249#endif // QGSBROWSERPROXYMODEL_H
LayerType
Types of layers that can be added to a map.
Definition qgis.h:190
@ Vector
Vector layer.
Definition qgis.h:191
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.
QgsBrowserModel * browserModel()
Returns the underlying browser model.
bool hasChildren(const QModelIndex &parent=QModelIndex()) const override
QgsBrowserProxyModel(QObject *parent=nullptr)
Constructor for QgsBrowserProxyModel, with the specified parent object.
bool filterByLayerType() const
Returns true if the model is filtered by map layer type.
QgsBrowserModel * mModel
Reference to associated browser model.
Base class for all items in the model.
Definition qgsdataitem.h:47
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53