QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
6  email : [email protected]
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 
32 class 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 
50  enum Role
51  {
52  IdentifierValueRole = Qt::UserRole,
53  IdentifierValuesRole,
54  ValueRole,
55  FeatureRole,
56  FeatureIdRole
57  };
58 
62  explicit QgsFeaturePickerModelBase( QObject *parent = nullptr );
64 
68  QgsVectorLayer *sourceLayer() const;
69 
73  void setSourceLayer( QgsVectorLayer *sourceLayer );
74 
81  QString displayExpression() const;
82 
89  void setDisplayExpression( const QString &displayExpression );
90 
96  QString filterValue() const;
97 
103  void setFilterValue( const QString &filterValue );
104 
105  QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
106  QModelIndex parent( const QModelIndex &child ) const override;
107  int rowCount( const QModelIndex &parent ) const override;
108  int columnCount( const QModelIndex &parent ) const override
109  {
110  Q_UNUSED( parent )
111  return 1;
112  }
113  QVariant data( const QModelIndex &index, int role ) const override;
114 
119  QString filterExpression() const;
120 
125  void setFilterExpression( const QString &filterExpression );
126 
130  bool isLoading() const;
131 
136  virtual void setExtraIdentifierValueToNull() = 0;
137 
141  int extraIdentifierValueIndex() const;
142 
146  bool extraValueDoesNotExist() const;
147 
151  bool allowNull() const;
152 
156  void setAllowNull( bool allowNull );
157 
161  bool fetchGeometry() const;
162 
166  void setFetchGeometry( bool fetchGeometry );
167 
171  int fetchLimit() const;
172 
177  void setFetchLimit( int fetchLimit );
178 
179  signals:
180 
187  void currentFeatureChanged();
188 
192  void sourceLayerChanged();
193 
200  void displayExpressionChanged();
201 
207  void filterValueChanged();
208 
213  void filterExpressionChanged();
214 
218  void isLoadingChanged();
219 
223  void filterJobCompleted();
224 
229  void extraIdentifierValueChanged();
230 
234  void extraIdentifierValueIndexChanged( int index );
235 
239  void extraValueDoesNotExistChanged();
240 
244  void beginUpdate();
245 
249  void endUpdate();
250 
254  void allowNullChanged();
255 
259  void fetchGeometryChanged();
260 
264  void fetchLimitChanged();
265 
266 
267  private slots:
268  void updateCompleter();
269  void scheduledReload();
270 
271  protected:
272 
277  QVariant extraIdentifierValue() const;
278 
283  void setExtraIdentifierValue( const QVariant &extraIdentifierValue );
284 
286  virtual void requestToReloadCurrentFeature( QgsFeatureRequest &request ) = 0;
287 
289  void setExtraIdentifierValueUnguarded( const QVariant &identifierValue );
290 
291 #ifndef SIP_RUN
292 
297  virtual QSet<QString> requestedAttributes() const {return {};}
298 
300  virtual QgsFeatureExpressionValuesGatherer *createValuesGatherer( const QgsFeatureRequest &request ) const = 0;
301 
303  virtual QgsFeatureExpressionValuesGatherer::Entry createEntry( const QVariant &identifier ) const = 0;
304 
306  virtual QVariant entryIdentifier( const QgsFeatureExpressionValuesGatherer::Entry &entry ) const = 0;
307 
309  virtual bool compareEntries( const QgsFeatureExpressionValuesGatherer::Entry &a, const QgsFeatureExpressionValuesGatherer::Entry &b ) const = 0;
310 
312  virtual QVariant nullIdentifier() const = 0;
313 
318  virtual bool identifierIsNull( const QVariant &identifier ) const = 0;
319 
320  QVector<QgsFeatureExpressionValuesGatherer::Entry> mEntries;
321 #endif
322 
324  QVariant mExtraIdentifierValue;
325 
327  int mExtraValueIndex = -1;
328 
329  private:
330  void setExtraIdentifierValueIndex( int index, bool force = false );
331  void setExtraValueDoesNotExist( bool extraValueDoesNotExist );
332  void reload();
333  void reloadCurrentFeature();
334  QSet<QString> requestedAttributesForStyle() const;
335 
336  QgsConditionalStyle featureStyle( const QgsFeature &feature ) const;
337 
338  QgsVectorLayer *mSourceLayer = nullptr;
339  QgsExpression mDisplayExpression;
340  QString mFilterValue;
341  QString mFilterExpression;
342 
343  mutable QgsExpressionContext mExpressionContext;
344  mutable QMap< QgsFeatureId, QgsConditionalStyle > mEntryStylesMap;
345 
346  QgsFeatureExpressionValuesGatherer *mGatherer = nullptr;
347  bool mFetchGeometry = true;
348  int mFetchLimit = 100;
349 
350  QTimer mReloadTimer;
351  bool mShouldReloadCurrentFeature = false;
352  bool mKeepCurrentEntry = false; // need to keep the current value after a reload or if the value does not exist
353  bool mExtraValueDoesNotExist = false;
354  bool mAllowNull = false;
355  bool mIsSettingExtraIdentifierValue = false;
356 
357  friend class TestQgsFeatureListComboBox;
358 };
359 
360 #endif // QGSFEATUREFILTERMODELBASE_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
qgsconditionalstyle.h
QgsFeaturePickerModelBase
Provides a list of features based on filter conditions.
Definition: qgsfeaturepickermodelbase.h:32
QgsConditionalStyle
Conditional styling for a rule.
Definition: qgsconditionalstyle.h:120
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:83
qgsfeatureexpressionvaluesgatherer.h
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsFeaturePickerModelBase::Role
Role
Extra roles that can be used to fetch data from this model.
Definition: qgsfeaturepickermodelbase.h:63
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings")....
Definition: qgsexpression.h:102
SIP_ABSTRACT
#define SIP_ABSTRACT
Definition: qgis_sip.h:208