QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
38 Q_PROPERTY( QString filterValue READ filterValue WRITE setFilterValue NOTIFY filterValueChanged )
41 Q_PROPERTY( Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged )
42 Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull NOTIFY allowNullChanged )
44 Q_PROPERTY( int fetchLimit READ fetchLimit WRITE setFetchLimit NOTIFY fetchLimitChanged )
46
47 public:
48 // *INDENT-OFF*
49
57 {
58 IdentifierValue SIP_MONKEYPATCH_COMPAT_NAME( IdentifierValueRole ) = Qt::UserRole,
59 IdentifierValues SIP_MONKEYPATCH_COMPAT_NAME( IdentifierValuesRole ),
60 Value SIP_MONKEYPATCH_COMPAT_NAME( ValueRole ),
61 Feature SIP_MONKEYPATCH_COMPAT_NAME( FeatureRole ),
62 FeatureId SIP_MONKEYPATCH_COMPAT_NAME( FeatureIdRole )
63 };
64 Q_ENUM( CustomRole )
65 // *INDENT-ON*
66
67
70 explicit QgsFeaturePickerModelBase( QObject *parent = nullptr );
72
76 QgsVectorLayer *sourceLayer() const;
77
81 void setSourceLayer( QgsVectorLayer *sourceLayer );
82
89 QString displayExpression() const;
90
97 void setDisplayExpression( const QString &displayExpression );
98
104 QString filterValue() const;
105
111 void setFilterValue( const QString &filterValue );
112
113 QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
114 QModelIndex parent( const QModelIndex &child ) const override;
115 int rowCount( const QModelIndex &parent ) const override;
116 int columnCount( const QModelIndex &parent ) const override
117 {
118 Q_UNUSED( parent )
119 return 1;
120 }
121 QVariant data( const QModelIndex &index, int role ) const override;
122
127 QString filterExpression() const;
128
133 void setFilterExpression( const QString &filterExpression );
134
139 QString orderExpression() const;
140
145 void setOrderExpression( const QString &orderExpression );
146
151 Qt::SortOrder sortOrder() const;
152
157 void setSortOrder( const Qt::SortOrder sortOrder );
158
159
164 QgsFeature formFeature() const;
165
170 void setFormFeature( const QgsFeature &feature );
171
176 QgsFeature parentFormFeature() const;
177
182 void setParentFormFeature( const QgsFeature &feature );
183
187 bool isLoading() const;
188
194
198 int extraIdentifierValueIndex() const;
199
203 bool extraValueDoesNotExist() const;
204
208 bool allowNull() const;
209
213 void setAllowNull( bool allowNull );
214
218 bool fetchGeometry() const;
219
223 void setFetchGeometry( bool fetchGeometry );
224
228 int fetchLimit() const;
229
234 void setFetchLimit( int fetchLimit );
235
236 signals:
237
245
250
258
265
271
278
285
291
297
302
307
313
318
323
328
332 void endUpdate();
333
338
343
348
349
350 private slots:
351 void updateCompleter();
352 void scheduledReload();
353
354 protected:
359 QVariant extraIdentifierValue() const;
360
365 void setExtraIdentifierValue( const QVariant &extraIdentifierValue );
366
369
371 void setExtraIdentifierValueUnguarded( const QVariant &identifierValue );
372
373#ifndef SIP_RUN
374
379 virtual QSet<QString> requestedAttributes() const { return {}; }
380
382 virtual QgsFeatureExpressionValuesGatherer *createValuesGatherer( const QgsFeatureRequest &request ) const = 0;
383
385 virtual QgsFeatureExpressionValuesGatherer::Entry createEntry( const QVariant &identifier ) const = 0;
386
388 virtual QVariant entryIdentifier( const QgsFeatureExpressionValuesGatherer::Entry &entry ) const = 0;
389
391 virtual bool compareEntries( const QgsFeatureExpressionValuesGatherer::Entry &a, const QgsFeatureExpressionValuesGatherer::Entry &b ) const = 0;
392
394 virtual QVariant nullIdentifier() const = 0;
395
400 virtual bool identifierIsNull( const QVariant &identifier ) const = 0;
401
402 QVector<QgsFeatureExpressionValuesGatherer::Entry> mEntries;
403#endif
404
407
410
411 private:
412 void setExtraIdentifierValueIndex( int index, bool force = false );
413 void setExtraValueDoesNotExist( bool extraValueDoesNotExist );
414 void reload();
415 void reloadCurrentFeature();
416 QSet<QString> requestedAttributesForStyle() const;
417
418 QgsConditionalStyle featureStyle( const QgsFeature &feature ) const;
419
420 QgsVectorLayer *mSourceLayer = nullptr;
421 QgsExpression mDisplayExpression;
422 QString mFilterValue;
423 QString mFilterExpression;
424 QgsExpression mOrderExpression;
425 Qt::SortOrder mSortOrder = Qt::AscendingOrder;
426
427 QgsFeature mFormFeature;
428 QgsFeature mParentFormFeature;
429
430 mutable QgsExpressionContext mExpressionContext;
431 mutable QMap< QgsFeatureId, QgsConditionalStyle > mEntryStylesMap;
432
433 QgsFeatureExpressionValuesGatherer *mGatherer = nullptr;
434 bool mFetchGeometry = true;
435 int mFetchLimit = 100;
436
437 QTimer mReloadTimer;
438 bool mShouldReloadCurrentFeature = false;
439 bool mKeepCurrentEntry = false; // need to keep the current value after a reload or if the value does not exist
440 bool mExtraValueDoesNotExist = false;
441 bool mAllowNull = false;
442 bool mIsSettingExtraIdentifierValue = false;
443
445};
446
447#endif // QGSFEATUREFILTERMODELBASE_H
Conditional styling for a rule.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Handles 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.
void setFilterValue(const QString &filterValue)
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...
void setExtraIdentifierValue(const QVariant &extraIdentifierValue)
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 parentFormFeatureChanged()
A parent attribute form feature to be used alongside the filter expression.
void filterExpressionChanged()
An additional filter expression to apply, next to the filterValue.
void setFetchLimit(int fetchLimit)
Defines the feature request fetch limit If set to 0, no limit is applied when fetching.
int columnCount(const QModelIndex &parent) const override
QVariant extraIdentifierValue() const
Allows specifying one value that does not need to match the filter criteria but will still be availab...
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 setSortOrder(const Qt::SortOrder sortOrder)
The order direction will be used for sort values in the combobox.
void setFetchGeometry(bool fetchGeometry)
Defines if the geometry will be fetched.
void setExtraIdentifierValueUnguarded(const QVariant &identifierValue)
This will set the identifier value to be set in the model even if it doesn't exist currently in the d...
void extraIdentifierValueChanged()
Allows specifying one value that does not need to match the filter criteria but will still be availab...
void setOrderExpression(const QString &orderExpression)
The order expression will be used for sort values in the combobox.
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.
QModelIndex parent(const QModelIndex &child) const override
void filterJobCompleted()
Indicates that a filter job has been completed and new data may be available.
void setAllowNull(bool allowNull)
Add a NULL entry to the list.
void setDisplayExpression(const QString &displayExpression)
The display expression will be used for.
QVariant mExtraIdentifierValue
The current identifier value.
QgsFeaturePickerModelBase(QObject *parent=nullptr)
Create a new QgsFeaturePickerModelBase, optionally specifying a parent.
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...
QModelIndex index(int row, int column, const QModelIndex &parent) const override
void fetchLimitChanged()
Emitted when the fetching limit for the feature request changes.
void sourceLayerChanged()
The source layer from which features will be fetched.
void setFilterExpression(const QString &filterExpression)
An additional filter expression to apply, next to the filterValue.
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 orderExpressionChanged()
An expression for generating values for sorting.
void fetchGeometryChanged()
Emitted when the fetching of the geometry changes.
void sortOrderChanged()
The direction used for sorting.
void isLoadingChanged()
Indicator if the model is currently performing any feature iteration in the background.
void formFeatureChanged()
An attribute form feature to be used alongside the filter expression.
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.
void setSourceLayer(QgsVectorLayer *sourceLayer)
The source layer from which features will be fetched.
bool extraValueDoesNotExist() const
Flag indicating that the extraIdentifierValue does not exist in the data.
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:60
Represents a vector layer which manages a vector based dataset.
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:267
#define SIP_ABSTRACT
Definition qgis_sip.h:220
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:269