QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgsfeaturepickermodelbase.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfeaturefiltermodel.h - QgsFeatureFilterModel
3 ---------------------
4 begin : 10.3.2017
5 copyright : (C) 2017 by Matthias Kuhn
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 QGSFEATUREFILTERMODELBASE_H
16#define QGSFEATUREFILTERMODELBASE_H
17
18#include "qgsconditionalstyle.h"
20
21#include <QAbstractItemModel>
22#include <QTimer>
23
32class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABSTRACT
33{
34 Q_OBJECT
35
36 Q_PROPERTY( QgsVectorLayer *sourceLayer READ sourceLayer WRITE setSourceLayer NOTIFY sourceLayerChanged )
37 Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
38 Q_PROPERTY( QString filterValue READ filterValue WRITE setFilterValue NOTIFY filterValueChanged )
39 Q_PROPERTY( QString filterExpression READ filterExpression WRITE setFilterExpression NOTIFY filterExpressionChanged )
40 Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull NOTIFY allowNullChanged )
41 Q_PROPERTY( bool fetchGeometry READ fetchGeometry WRITE setFetchGeometry NOTIFY fetchGeometryChanged )
42 Q_PROPERTY( int fetchLimit READ fetchLimit WRITE setFetchLimit NOTIFY fetchLimitChanged )
43 Q_PROPERTY( int extraIdentifierValueIndex READ extraIdentifierValueIndex NOTIFY extraIdentifierValueIndexChanged )
44
45 public:
46
47 // *INDENT-OFF*
48
56 {
57 IdentifierValue SIP_MONKEYPATCH_COMPAT_NAME(IdentifierValueRole) = Qt::UserRole,
58 IdentifierValues SIP_MONKEYPATCH_COMPAT_NAME(IdentifierValuesRole),
59 Value SIP_MONKEYPATCH_COMPAT_NAME(ValueRole),
60 Feature SIP_MONKEYPATCH_COMPAT_NAME(FeatureRole),
61 FeatureId SIP_MONKEYPATCH_COMPAT_NAME(FeatureIdRole)
62 };
63 Q_ENUM( CustomRole )
64 // *INDENT-ON*
65
66
69 explicit QgsFeaturePickerModelBase( QObject *parent = nullptr );
71
75 QgsVectorLayer *sourceLayer() const;
76
80 void setSourceLayer( QgsVectorLayer *sourceLayer );
81
88 QString displayExpression() const;
89
96 void setDisplayExpression( const QString &displayExpression );
97
103 QString filterValue() const;
104
110 void setFilterValue( const QString &filterValue );
111
112 QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
113 QModelIndex parent( const QModelIndex &child ) const override;
114 int rowCount( const QModelIndex &parent ) const override;
115 int columnCount( const QModelIndex &parent ) const override
116 {
117 Q_UNUSED( parent )
118 return 1;
119 }
120 QVariant data( const QModelIndex &index, int role ) const override;
121
126 QString filterExpression() const;
127
132 void setFilterExpression( const QString &filterExpression );
133
137 bool isLoading() const;
138
144
148 int extraIdentifierValueIndex() const;
149
153 bool extraValueDoesNotExist() const;
154
158 bool allowNull() const;
159
163 void setAllowNull( bool allowNull );
164
168 bool fetchGeometry() const;
169
173 void setFetchGeometry( bool fetchGeometry );
174
178 int fetchLimit() const;
179
184 void setFetchLimit( int fetchLimit );
185
186 signals:
187
195
200
208
215
221
226
231
237
242
247
252
256 void endUpdate();
257
262
267
272
273
274 private slots:
275 void updateCompleter();
276 void scheduledReload();
277
278 protected:
279
284 QVariant extraIdentifierValue() const;
285
290 void setExtraIdentifierValue( const QVariant &extraIdentifierValue );
291
294
296 void setExtraIdentifierValueUnguarded( const QVariant &identifierValue );
297
298#ifndef SIP_RUN
299
304 virtual QSet<QString> requestedAttributes() const {return {};}
305
307 virtual QgsFeatureExpressionValuesGatherer *createValuesGatherer( const QgsFeatureRequest &request ) const = 0;
308
310 virtual QgsFeatureExpressionValuesGatherer::Entry createEntry( const QVariant &identifier ) const = 0;
311
313 virtual QVariant entryIdentifier( const QgsFeatureExpressionValuesGatherer::Entry &entry ) const = 0;
314
316 virtual bool compareEntries( const QgsFeatureExpressionValuesGatherer::Entry &a, const QgsFeatureExpressionValuesGatherer::Entry &b ) const = 0;
317
319 virtual QVariant nullIdentifier() const = 0;
320
325 virtual bool identifierIsNull( const QVariant &identifier ) const = 0;
326
327 QVector<QgsFeatureExpressionValuesGatherer::Entry> mEntries;
328#endif
329
332
334 int mExtraValueIndex = -1;
335
336 private:
337 void setExtraIdentifierValueIndex( int index, bool force = false );
338 void setExtraValueDoesNotExist( bool extraValueDoesNotExist );
339 void reload();
340 void reloadCurrentFeature();
341 QSet<QString> requestedAttributesForStyle() const;
342
343 QgsConditionalStyle featureStyle( const QgsFeature &feature ) const;
344
345 QgsVectorLayer *mSourceLayer = nullptr;
346 QgsExpression mDisplayExpression;
347 QString mFilterValue;
348 QString mFilterExpression;
349
350 mutable QgsExpressionContext mExpressionContext;
351 mutable QMap< QgsFeatureId, QgsConditionalStyle > mEntryStylesMap;
352
353 QgsFeatureExpressionValuesGatherer *mGatherer = nullptr;
354 bool mFetchGeometry = true;
355 int mFetchLimit = 100;
356
357 QTimer mReloadTimer;
358 bool mShouldReloadCurrentFeature = false;
359 bool mKeepCurrentEntry = false; // need to keep the current value after a reload or if the value does not exist
360 bool mExtraValueDoesNotExist = false;
361 bool mAllowNull = false;
362 bool mIsSettingExtraIdentifierValue = false;
363
364 friend class TestQgsFeatureListComboBox;
365};
366
367#endif // QGSFEATUREFILTERMODELBASE_H
Conditional styling for a rule.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class for parsing and evaluation of expressions (formerly called "search strings").
Provides a list of features based on filter conditions.
void extraIdentifierValueIndexChanged(int index)
The index at which the extra identifier value is available within the model.
void beginUpdate()
Notification that the model is about to be changed because a job was completed.
virtual QVariant entryIdentifier(const QgsFeatureExpressionValuesGatherer::Entry &entry) const =0
Returns the identifier of the given entry.
void filterValueChanged()
This value will be used to filter the features available from this model.
virtual void setExtraIdentifierValueToNull()=0
Allows specifying one value that does not need to match the filter criteria but will still be availab...
virtual void requestToReloadCurrentFeature(QgsFeatureRequest &request)=0
Update the request to match the current feature to be reloaded.
void filterExpressionChanged()
An additional filter expression to apply, next to the filterValue.
int columnCount(const QModelIndex &parent) const override
void extraValueDoesNotExistChanged(bool found)
Notification whether the model has found a feature tied to the extraIdentifierValue or not.
virtual QgsFeatureExpressionValuesGatherer * createValuesGatherer(const QgsFeatureRequest &request) const =0
Creates the value gatherer.
void extraIdentifierValueChanged()
Allows specifying one value that does not need to match the filter criteria but will still be availab...
virtual QSet< QString > requestedAttributes() const
Returns the attributes to be fetched in the request.
CustomRole
Extra roles that can be used to fetch data from this model.
void filterJobCompleted()
Indicates that a filter job has been completed and new data may be available.
QVariant mExtraIdentifierValue
The current identifier value.
virtual QgsFeatureExpressionValuesGatherer::Entry createEntry(const QVariant &identifier) const =0
Creates an entry with just the identifier so the feature can be retrieved in a next iteration.
virtual bool identifierIsNull(const QVariant &identifier) const =0
Returns true if the entry is null The identifier can be either the feature ID or the list of identifi...
void fetchLimitChanged()
Emitted when the fetching limit for the feature request changes.
void sourceLayerChanged()
The source layer from which features will be fetched.
void allowNullChanged()
Add a NULL entry to the list.
virtual bool compareEntries(const QgsFeatureExpressionValuesGatherer::Entry &a, const QgsFeatureExpressionValuesGatherer::Entry &b) const =0
Returns true if the 2 entries refers to the same feature.
void currentFeatureChanged()
Emitted when the current feature in the model has changed This emitted both when the extra value chan...
void fetchGeometryChanged()
Emitted when the fetching of the geometry changes.
void isLoadingChanged()
Indicator if the model is currently performing any feature iteration in the background.
QVector< QgsFeatureExpressionValuesGatherer::Entry > mEntries
virtual QVariant nullIdentifier() const =0
Returns a null identifier.
void endUpdate()
Notification that the model change is finished.
void displayExpressionChanged()
The display expression will be used for.
This class wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Represents a vector layer which manages a vector based data sets.
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_ABSTRACT
Definition qgis_sip.h:213
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273