QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 <QAbstractItemModel>
19 
20 #include "qgsconditionalstyle.h"
22 
30 class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABSTRACT
31 {
32  Q_OBJECT
33 
34  Q_PROPERTY( QgsVectorLayer *sourceLayer READ sourceLayer WRITE setSourceLayer NOTIFY sourceLayerChanged )
35  Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
36  Q_PROPERTY( QString filterValue READ filterValue WRITE setFilterValue NOTIFY filterValueChanged )
37  Q_PROPERTY( QString filterExpression READ filterExpression WRITE setFilterExpression NOTIFY filterExpressionChanged )
38  Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull NOTIFY allowNullChanged )
39  Q_PROPERTY( bool fetchGeometry READ fetchGeometry WRITE setFetchGeometry NOTIFY fetchGeometryChanged )
40  Q_PROPERTY( int fetchLimit READ fetchLimit WRITE setFetchLimit NOTIFY fetchLimitChanged )
41  Q_PROPERTY( int extraIdentifierValueIndex READ extraIdentifierValueIndex NOTIFY extraIdentifierValueIndexChanged )
42 
43  public:
44 
48  enum Role
49  {
50  IdentifierValueRole = Qt::UserRole,
51  IdentifierValuesRole,
52  ValueRole,
53  FeatureRole,
54  FeatureIdRole
55  };
56 
60  explicit QgsFeaturePickerModelBase( QObject *parent = nullptr );
62 
66  QgsVectorLayer *sourceLayer() const;
67 
71  void setSourceLayer( QgsVectorLayer *sourceLayer );
72 
79  QString displayExpression() const;
80 
87  void setDisplayExpression( const QString &displayExpression );
88 
94  QString filterValue() const;
95 
101  void setFilterValue( const QString &filterValue );
102 
103  QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
104  QModelIndex parent( const QModelIndex &child ) const override;
105  int rowCount( const QModelIndex &parent ) const override;
106  int columnCount( const QModelIndex &parent ) const override
107  {
108  Q_UNUSED( parent )
109  return 1;
110  }
111  QVariant data( const QModelIndex &index, int role ) const override;
112 
117  QString filterExpression() const;
118 
123  void setFilterExpression( const QString &filterExpression );
124 
128  bool isLoading() const;
129 
134  virtual void setExtraIdentifierValueToNull() = 0;
135 
139  int extraIdentifierValueIndex() const;
140 
144  bool extraValueDoesNotExist() const;
145 
149  bool allowNull() const;
150 
154  void setAllowNull( bool allowNull );
155 
159  bool fetchGeometry() const;
160 
164  void setFetchGeometry( bool fetchGeometry );
165 
169  int fetchLimit() const;
170 
175  void setFetchLimit( int fetchLimit );
176 
177  signals:
178 
182  void sourceLayerChanged();
183 
190  void displayExpressionChanged();
191 
197  void filterValueChanged();
198 
203  void filterExpressionChanged();
204 
208  void isLoadingChanged();
209 
213  void filterJobCompleted();
214 
219  void extraIdentifierValueChanged();
220 
224  void extraIdentifierValueIndexChanged( int index );
225 
229  void extraValueDoesNotExistChanged();
230 
234  void beginUpdate();
235 
239  void endUpdate();
240 
244  void allowNullChanged();
245 
249  void fetchGeometryChanged();
250 
254  void fetchLimitChanged();
255 
256 
257  private slots:
258  void updateCompleter();
259  void scheduledReload();
260 
261  protected:
262 
267  QVariant extraIdentifierValue() const;
268 
273  void setExtraIdentifierValue( const QVariant &extraIdentifierValue );
274 
276  virtual void requestToReloadCurrentFeature( QgsFeatureRequest &request ) = 0;
277 
279  void setExtraIdentifierValueUnguarded( const QVariant &identifierValue );
280 
281 #ifndef SIP_RUN
282 
287  virtual QSet<QString> requestedAttributes() const {return {};}
288 
290  virtual QgsFeatureExpressionValuesGatherer *createValuesGatherer( const QgsFeatureRequest &request ) const = 0;
291 
293  virtual QgsFeatureExpressionValuesGatherer::Entry createEntry( const QVariant &identifier ) const = 0;
294 
296  virtual QVariant entryIdentifier( const QgsFeatureExpressionValuesGatherer::Entry &entry ) const = 0;
297 
299  virtual bool compareEntries( const QgsFeatureExpressionValuesGatherer::Entry &a, const QgsFeatureExpressionValuesGatherer::Entry &b ) const = 0;
300 
302  virtual QVariant nullIentifier() const = 0;
303 
308  virtual bool identifierIsNull( const QVariant &identifier ) const = 0;
309 
310  QVector<QgsFeatureExpressionValuesGatherer::Entry> mEntries;
311 #endif
312 
314  QVariant mExtraIdentifierValue;
315 
317  int mExtraValueIndex = -1;
318 
319  private:
320  void setExtraIdentifierValueIndex( int index, bool force = false );
321  void setExtraValueDoesNotExist( bool extraValueDoesNotExist );
322  void reload();
323  void reloadCurrentFeature();
324  QSet<QString> requestedAttributesForStyle() const;
325 
326  QgsConditionalStyle featureStyle( const QgsFeature &feature ) const;
327 
328  QgsVectorLayer *mSourceLayer = nullptr;
329  QgsExpression mDisplayExpression;
330  QString mFilterValue;
331  QString mFilterExpression;
332 
333  mutable QgsExpressionContext mExpressionContext;
334  mutable QMap< QgsFeatureId, QgsConditionalStyle > mEntryStylesMap;
335 
336  QgsFeatureExpressionValuesGatherer *mGatherer = nullptr;
337  bool mFetchGeometry = true;
338  int mFetchLimit = 100;
339 
340  QTimer mReloadTimer;
341  bool mShouldReloadCurrentFeature = false;
342  bool mKeepCurrentEntry = false; // need to keep the current value after a reload or if the value does not exist
343  bool mExtraValueDoesNotExist = false;
344  bool mAllowNull = false;
345  bool mIsSettingExtraIdentifierValue = false;
346 
347  friend class TestQgsFeatureListComboBox;
348 };
349 
350 #endif // QGSFEATUREFILTERMODELBASE_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
qgsconditionalstyle.h
QgsFeaturePickerModelBase
Definition: qgsfeaturepickermodelbase.h:30
QgsConditionalStyle
Definition: qgsconditionalstyle.h:112
QgsFeatureRequest
Definition: qgsfeaturerequest.h:75
qgsfeatureexpressionvaluesgatherer.h
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsFeature
Definition: qgsfeature.h:55
QgsFeaturePickerModelBase::Role
Role
Extra roles that can be used to fetch data from this model.
Definition: qgsfeaturepickermodelbase.h:61
QgsExpression
Definition: qgsexpression.h:113
SIP_ABSTRACT
#define SIP_ABSTRACT
Definition: qgis_sip.h:194