QGIS API Documentation  2.99.0-Master (6a61179)
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 "qgsfeatureiterator.h"
19 #include "qgsfields.h"
20 
21 #include <QSet>
22 
23 typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
24 
26 class QgsVectorLayer;
29 struct QgsVectorJoinInfo;
31 
33 
39 {
40  public:
41 
45  explicit QgsVectorLayerFeatureSource( const QgsVectorLayer* layer );
46 
48 
49  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request ) override;
50 
52 
53  protected:
54 
56 
58 
60 
62 
64 
65  // A deep-copy is only performed, if the original maps change
66  // see here https://github.com/qgis/Quantum-GIS/pull/673
67  // for explanation
71  QList<QgsField> mAddedAttributes;
74 
75  long mCrsId;
76 };
77 
80 class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsVectorLayerFeatureSource>
81 {
82  public:
83  QgsVectorLayerFeatureIterator( QgsVectorLayerFeatureSource* source, bool ownSource, const QgsFeatureRequest& request );
84 
86 
88  virtual bool rewind() override;
89 
91  virtual bool close() override;
92 
93  virtual void setInterruptionChecker( QgsInterruptionChecker* interruptionChecker ) override;
94 
95  protected:
97  virtual bool fetchFeature( QgsFeature& feature ) override;
98 
101  virtual bool nextFeatureFilterExpression( QgsFeature &f ) override { return fetchFeature( f ); }
102 
104  virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod ) override;
105 
107  void rewindEditBuffer();
108 
110  void prepareJoin( int fieldIdx );
111 
113  void prepareExpression( int fieldIdx );
114 
116  void prepareFields();
117 
119  void prepareField( int fieldIdx );
120 
122  bool fetchNextAddedFeature( QgsFeature& f );
124  bool fetchNextChangedGeomFeature( QgsFeature& f );
126  bool fetchNextChangedAttributeFeature( QgsFeature& f );
128  void useAddedFeature( const QgsFeature& src, QgsFeature& f );
130  void useChangedAttributeFeature( QgsFeatureId fid, const QgsGeometry& geom, QgsFeature& f );
132  bool nextFeatureFid( QgsFeature& f );
134  void addJoinedAttributes( QgsFeature &f );
135 
145  void addVirtualAttributes( QgsFeature &f );
146 
153  void addExpressionAttribute( QgsFeature& f, int attrIndex );
154 
158  void updateChangedAttributes( QgsFeature& f );
159 
163  void updateFeatureGeometry( QgsFeature& f );
164 
169  {
175  int joinField;
176 
177  void addJoinedAttributesCached( QgsFeature& f, const QVariant& joinValue ) const;
178  void addJoinedAttributesDirect( QgsFeature& f, const QVariant& joinValue ) const;
179  };
180 
185 
186  // only related to editing
187  QSet<QgsFeatureId> mFetchConsidered;
188  QgsGeometryMap::ConstIterator mFetchChangedGeomIt;
189  QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt;
190 
191  bool mFetchedFid; // when iterating by FID: indicator whether it has been fetched yet or not
192 
195  QMap<const QgsVectorJoinInfo*, FetchJoinInfo> mFetchJoinInfo;
196 
197  QMap<int, QgsExpression*> mExpressionFieldInfo;
198 
200 
201  private:
202  QScopedPointer<QgsExpressionContext> mExpressionContext;
203 
204  QgsInterruptionChecker* mInterruptionChecker;
205 
206  QList< int > mPreparedFields;
207  QList< int > mFieldsToPrepare;
208 
210  QList< FetchJoinInfo > mOrderedJoinInfoList;
211 
216  bool prepareOrderBy( const QList<QgsFeatureRequest::OrderByClause> &orderBys ) override;
217 
219  virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const override;
220 
221  void createOrderedJoinList();
222 };
223 
224 #endif // QGSVECTORLAYERFEATUREITERATOR_H
QgsAbstractFeatureSource * mProviderFeatureSource
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:353
QgsVectorLayerJoinBuffer * mJoinBuffer
QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt
QgsGeometryMap::ConstIterator mFetchChangedGeomIt
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:355
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
Container of fields for a vector layer.
Definition: qgsfields.h:36
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:78
QMap< int, QgsExpression * > mExpressionFieldInfo
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:135
QgsVectorLayer * joinLayer
Resolved pointer to the joined layer.
QMap< const QgsVectorJoinInfo *, FetchJoinInfo > mFetchJoinInfo
Information about joins used in the current select() statement.
Manages joined fields for a vector layer.
int joinField
Index of field (of the joined layer) must have equal value.
Interface that can be optionaly attached to an iterator so its nextFeature() implementaton can check ...
const QgsVectorJoinInfo * joinInfo
Cannonical source of information about the join.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
QgsExpressionFieldBuffer * mExpressionFieldBuffer
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 QgsFeatureIterator getFeatures(const QgsFeatureRequest &request) override
Get an iterator for features matching the specified request.
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:350
Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAtt...
qint64 QgsFeatureId
Definition: qgsfeature.h:32
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
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.
QgsVectorLayerFeatureSource(const QgsVectorLayer *layer)
Constructor for QgsVectorLayerFeatureSource.
Helper template that cares of two things: 1.