QGIS API Documentation  2.14.11-Essen
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 
20 #include <QSet>
21 
23 
25 class QgsVectorLayer;
28 struct QgsVectorJoinInfo;
30 
32 
37 {
38  public:
41 
42  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request ) override;
43 
45 
46  protected:
47 
49 
51 
53 
55 
57 
59 
60  // A deep-copy is only performed, if the original maps change
61  // see here https://github.com/qgis/Quantum-GIS/pull/673
62  // for explanation
69 
70  long mCrsId;
71 };
72 
73 
74 class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsVectorLayerFeatureSource>
75 {
76  public:
77  QgsVectorLayerFeatureIterator( QgsVectorLayerFeatureSource* source, bool ownSource, const QgsFeatureRequest& request );
78 
80 
82  virtual bool rewind() override;
83 
85  virtual bool close() override;
86 
87  protected:
89  virtual bool fetchFeature( QgsFeature& feature ) override;
90 
93  inline virtual bool nextFeatureFilterExpression( QgsFeature &f ) override { return fetchFeature( f ); }
94 
96  virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod ) override;
97 
99  void rewindEditBuffer();
100 
102  void prepareJoin( int fieldIdx );
103 
105  void prepareExpression( int fieldIdx );
106 
108  void prepareFields();
109 
111  void prepareField( int fieldIdx );
112 
114  bool fetchNextAddedFeature( QgsFeature& f );
116  bool fetchNextChangedGeomFeature( QgsFeature& f );
118  bool fetchNextChangedAttributeFeature( QgsFeature& f );
120  void useAddedFeature( const QgsFeature& src, QgsFeature& f );
122  void useChangedAttributeFeature( QgsFeatureId fid, const QgsGeometry& geom, QgsFeature& f );
124  bool nextFeatureFid( QgsFeature& f );
126  void addJoinedAttributes( QgsFeature &f );
127 
137  void addVirtualAttributes( QgsFeature &f );
138 
145  void addExpressionAttribute( QgsFeature& f, int attrIndex );
146 
150  void updateChangedAttributes( QgsFeature& f );
151 
155  void updateFeatureGeometry( QgsFeature& f );
156 
161  {
167  int joinField;
168 
169  void addJoinedAttributesCached( QgsFeature& f, const QVariant& joinValue ) const;
170  void addJoinedAttributesDirect( QgsFeature& f, const QVariant& joinValue ) const;
171  };
172 
177 
178  // only related to editing
182 
183  bool mFetchedFid; // when iterating by FID: indicator whether it has been fetched yet or not
184 
188 
190 
192 
193  private:
195  QgsAbstractGeometrySimplifier* mEditGeometrySimplifier;
196 
197  QScopedPointer<QgsExpressionContext> mExpressionContext;
198 
199  QList< int > mPreparedFields;
200  QList< int > mFieldsToPrepare;
201 
203  QList< FetchJoinInfo > mOrderedJoinInfoList;
204 
209  bool prepareOrderBy( const QList<QgsFeatureRequest::OrderByClause> &orderBys ) override;
210 
212  virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const override;
213 
214  void createOrderedJoinList();
215 };
216 
217 #endif // QGSVECTORLAYERFEATUREITERATOR_H
QgsAbstractFeatureSource * mProviderFeatureSource
Wrapper for iterator of features from vector data provider or vector layer.
QgsVectorLayerJoinBuffer * mJoinBuffer
QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt
QgsGeometryMap::ConstIterator mFetchChangedGeomIt
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
Container of fields for a vector layer.
Definition: qgsfield.h:187
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
QMap< int, QgsExpression * > mExpressionFieldInfo
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
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
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)...
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) ...
QgsVectorLayerFeatureSource(QgsVectorLayer *layer)
int indexOffset
at what position the joined fields start
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.
Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAtt...
qint64 QgsFeatureId
Definition: qgsfeature.h:31
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.
Abstract base class for simplify geometries using a specific algorithm.
Helper template that cares of two things: 1.