QGIS API Documentation  2.99.0-Master (0a63d1f)
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 
24 typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
25 
27 class QgsVectorLayer;
30 struct QgsVectorJoinInfo;
32 
34 
40 {
41  public:
42 
46  explicit QgsVectorLayerFeatureSource( const QgsVectorLayer* layer );
47 
49 
50  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request ) override;
51 
53 
54  protected:
55 
57 
59 
61 
63 
65 
66  // A deep-copy is only performed, if the original maps change
67  // see here https://github.com/qgis/Quantum-GIS/pull/673
68  // for explanation
72  QList<QgsField> mAddedAttributes;
75 
76  long mCrsId;
77 };
78 
81 class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsVectorLayerFeatureSource>
82 {
83  public:
84  QgsVectorLayerFeatureIterator( QgsVectorLayerFeatureSource* source, bool ownSource, const QgsFeatureRequest& request );
85 
87 
89  virtual bool rewind() override;
90 
92  virtual bool close() override;
93 
94  virtual void setInterruptionChecker( QgsInterruptionChecker* interruptionChecker ) override;
95 
96  protected:
98  virtual bool fetchFeature( QgsFeature& feature ) override;
99 
102  virtual bool nextFeatureFilterExpression( QgsFeature &f ) override { return fetchFeature( f ); }
103 
105  virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod ) override;
106 
108  void rewindEditBuffer();
109 
111  void prepareJoin( int fieldIdx );
112 
114  void prepareExpression( int fieldIdx );
115 
117  void prepareFields();
118 
120  void prepareField( int fieldIdx );
121 
123  bool fetchNextAddedFeature( QgsFeature& f );
125  bool fetchNextChangedGeomFeature( QgsFeature& f );
127  bool fetchNextChangedAttributeFeature( QgsFeature& f );
129  void useAddedFeature( const QgsFeature& src, QgsFeature& f );
131  void useChangedAttributeFeature( QgsFeatureId fid, const QgsGeometry& geom, QgsFeature& f );
133  bool nextFeatureFid( QgsFeature& f );
135  void addJoinedAttributes( QgsFeature &f );
136 
146  void addVirtualAttributes( QgsFeature &f );
147 
154  void addExpressionAttribute( QgsFeature& f, int attrIndex );
155 
159  void updateChangedAttributes( QgsFeature& f );
160 
164  void updateFeatureGeometry( QgsFeature& f );
165 
170  {
176  int joinField;
177 
178  void addJoinedAttributesCached( QgsFeature& f, const QVariant& joinValue ) const;
179  void addJoinedAttributesDirect( QgsFeature& f, const QVariant& joinValue ) const;
180  };
181 
186 
187  // only related to editing
188  QSet<QgsFeatureId> mFetchConsidered;
189  QgsGeometryMap::ConstIterator mFetchChangedGeomIt;
190  QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt;
191 
192  bool mFetchedFid; // when iterating by FID: indicator whether it has been fetched yet or not
193 
196  QMap<const QgsVectorJoinInfo*, FetchJoinInfo> mFetchJoinInfo;
197 
198  QMap<int, QgsExpression*> mExpressionFieldInfo;
199 
201 
202  private:
203  QScopedPointer<QgsExpressionContext> mExpressionContext;
204 
205  QgsInterruptionChecker* mInterruptionChecker;
206 
207  QList< int > mPreparedFields;
208  QList< int > mFieldsToPrepare;
209 
211  QList< FetchJoinInfo > mOrderedJoinInfoList;
212 
217  bool prepareOrderBy( const QList<QgsFeatureRequest::OrderByClause> &orderBys ) override;
218 
220  virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const override;
221 
222  void createOrderedJoinList();
223 };
224 
225 #endif // QGSVECTORLAYERFEATUREITERATOR_H
QgsAbstractFeatureSource * mProviderFeatureSource
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:346
QgsVectorLayerJoinBuffer * mJoinBuffer
QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt
QgsGeometryMap::ConstIterator mFetchChangedGeomIt
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:348
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
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.
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 optionally attached to an iterator so its nextFeature() implementaton can check...
const QgsVectorJoinInfo * joinInfo
Canonical 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:343
Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAtt...
qint64 QgsFeatureId
Definition: qgsfeature.h:33
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.