QGIS API Documentation  2.99.0-Master (90ae728)
qgsvectorlayerfeatureiterator.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayerfeatureiterator.h
3  ---------------------
4  begin : Dezember 2012
5  copyright : (C) 2012 by Martin Dobias
6  email : wonder dot sk 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 QGSVECTORLAYERFEATUREITERATOR_H
16 #define QGSVECTORLAYERFEATUREITERATOR_H
17 
18 #include "qgis_core.h"
19 #include "qgsfeatureiterator.h"
20 #include "qgsfields.h"
21 
22 #include <QSet>
23 #include <memory>
24 
25 typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
26 
28 class QgsVectorLayer;
33 
35 
41 {
42  public:
43 
47  explicit QgsVectorLayerFeatureSource( const QgsVectorLayer* layer );
48 
50 
51  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request ) override;
52 
54 
55  protected:
56 
57  QgsAbstractFeatureSource* mProviderFeatureSource = nullptr;
58 
59  QgsVectorLayerJoinBuffer* mJoinBuffer = nullptr;
60 
61  QgsExpressionFieldBuffer* mExpressionFieldBuffer = nullptr;
62 
64 
66 
67  // A deep-copy is only performed, if the original maps change
68  // see here https://github.com/qgis/Quantum-GIS/pull/673
69  // for explanation
73  QList<QgsField> mAddedAttributes;
76 
77  long mCrsId;
78 };
79 
82 class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsVectorLayerFeatureSource>
83 {
84  public:
85  QgsVectorLayerFeatureIterator( QgsVectorLayerFeatureSource* source, bool ownSource, const QgsFeatureRequest& request );
86 
88 
90  virtual bool rewind() override;
91 
93  virtual bool close() override;
94 
95  virtual void setInterruptionChecker( QgsInterruptionChecker* interruptionChecker ) override;
96 
97  protected:
99  virtual bool fetchFeature( QgsFeature& feature ) override;
100 
103  virtual bool nextFeatureFilterExpression( QgsFeature &f ) override { return fetchFeature( f ); }
104 
106  virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod ) override;
107 
109  void rewindEditBuffer();
110 
112  void prepareJoin( int fieldIdx );
113 
115  void prepareExpression( int fieldIdx );
116 
118  void prepareFields();
119 
121  void prepareField( int fieldIdx );
122 
124  bool fetchNextAddedFeature( QgsFeature& f );
126  bool fetchNextChangedGeomFeature( QgsFeature& f );
128  bool fetchNextChangedAttributeFeature( QgsFeature& f );
130  void useAddedFeature( const QgsFeature& src, QgsFeature& f );
132  void useChangedAttributeFeature( QgsFeatureId fid, const QgsGeometry& geom, QgsFeature& f );
134  bool nextFeatureFid( QgsFeature& f );
136  void addJoinedAttributes( QgsFeature &f );
137 
147  void addVirtualAttributes( QgsFeature &f );
148 
155  void addExpressionAttribute( QgsFeature& f, int attrIndex );
156 
160  void updateChangedAttributes( QgsFeature& f );
161 
165  void updateFeatureGeometry( QgsFeature& f );
166 
171  {
177  int joinField;
178 
179  void addJoinedAttributesCached( QgsFeature& f, const QVariant& joinValue ) const;
180  void addJoinedAttributesDirect( QgsFeature& f, const QVariant& joinValue ) const;
181  };
182 
187 
188  // only related to editing
189  QSet<QgsFeatureId> mFetchConsidered;
190  QgsGeometryMap::ConstIterator mFetchChangedGeomIt;
191  QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt;
192 
193  bool mFetchedFid; // when iterating by FID: indicator whether it has been fetched yet or not
194 
197  QMap<const QgsVectorLayerJoinInfo*, FetchJoinInfo> mFetchJoinInfo;
198 
199  QMap<int, QgsExpression*> mExpressionFieldInfo;
200 
202 
203  private:
204  std::unique_ptr<QgsExpressionContext> mExpressionContext;
205 
206  QgsInterruptionChecker* mInterruptionChecker = nullptr;
207 
208  QList< int > mPreparedFields;
209  QList< int > mFieldsToPrepare;
210 
212  QList< FetchJoinInfo > mOrderedJoinInfoList;
213 
218  bool prepareOrderBy( const QList<QgsFeatureRequest::OrderByClause> &orderBys ) override;
219 
221  virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const override;
222 
223  void createOrderedJoinList();
224 };
225 
226 #endif // QGSVECTORLAYERFEATUREITERATOR_H
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:353
const QgsVectorLayerJoinInfo * joinInfo
Canonical source of information about the join.
virtual bool close()=0
end of iterating: free the resources / lock
QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt
QgsGeometryMap::ConstIterator mFetchChangedGeomIt
virtual bool fetchFeature(QgsFeature &f)=0
If you write a feature iterator for your provider, this is the method you need to implement!! ...
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:355
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
virtual bool rewind()=0
reset the iterator to the starting position
Container of fields for a vector layer.
Definition: qgsfields.h:39
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:79
QMap< int, QgsExpression * > mExpressionFieldInfo
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:136
QgsVectorLayer * joinLayer
Resolved pointer to the joined layer.
Manages joined fields for a vector layer.
int joinField
Index of field (of the joined layer) must have equal value.
Interface that can be optionally attached to an iterator so its nextFeature() implementaton can check...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Defines left outer join from our vector layer to some other vector layer.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
Base class that can be used for any class that is capable of returning features.
Partial snapshot of vector layer&#39;s state (only the members necessary for access to features) ...
int indexOffset
At what position the joined fields start.
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
int targetField
Index of field (of this layer) that drives the join.
Buffers information about expression fields for a vector layer.
virtual void setInterruptionChecker(QgsInterruptionChecker *interruptionChecker)
Attach an object that can be queried regularly by the iterator to check if it must stopped...
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:350
Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAtt...
QMap< const QgsVectorLayerJoinInfo *, FetchJoinInfo > mFetchJoinInfo
Information about joins used in the current select() statement.
qint64 QgsFeatureId
Definition: qgsfeature.h:33
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request)=0
Get an iterator for features matching the specified request.
virtual bool nextFeatureFilterExpression(QgsFeature &f) override
Overrides default method as we only need to filter features in the edit buffer while for others filte...
QgsChangedAttributesMap mChangedAttributeValues
Represents a vector layer which manages a vector based data sets.
virtual bool prepareSimplification(const QgsSimplifyMethod &simplifyMethod)
Setup the simplification of geometries to fetch using the specified simplify method.
Helper template that cares of two things: 1.