QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
22 typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
23 
25 class QgsVectorLayer;
28 struct QgsVectorJoinInfo;
29 
31 
34 {
35  public:
38 
39  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request );
40 
42 
43  protected:
44 
46 
48 
50 
52 
54 
56 
57  // A deep-copy is only performed, if the original maps change
58  // see here https://github.com/qgis/Quantum-GIS/pull/673
59  // for explanation
63  QList<QgsField> mAddedAttributes;
66 };
67 
68 
69 class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsVectorLayerFeatureSource>
70 {
71  public:
72  QgsVectorLayerFeatureIterator( QgsVectorLayerFeatureSource* source, bool ownSource, const QgsFeatureRequest& request );
73 
75 
77  virtual bool rewind();
78 
80  virtual bool close();
81 
82  protected:
84  virtual bool fetchFeature( QgsFeature& feature );
85 
88  inline virtual bool nextFeatureFilterExpression( QgsFeature &f ) { return fetchFeature( f ); }
89 
91  virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod );
92 
93 
98 
99 
100  // only related to editing
101  QSet<QgsFeatureId> mFetchConsidered;
102  QgsGeometryMap::ConstIterator mFetchChangedGeomIt;
103  QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt;
104 
105  bool mFetchedFid; // when iterating by FID: indicator whether it has been fetched yet or not
106 
107  void rewindEditBuffer();
108  void prepareJoins();
109  void prepareExpressions();
110  bool fetchNextAddedFeature( QgsFeature& f );
111  bool fetchNextChangedGeomFeature( QgsFeature& f );
112  bool fetchNextChangedAttributeFeature( QgsFeature& f );
113  void useAddedFeature( const QgsFeature& src, QgsFeature& f );
114  void useChangedAttributeFeature( QgsFeatureId fid, const QgsGeometry& geom, QgsFeature& f );
115  bool nextFeatureFid( QgsFeature& f );
116  void addJoinedAttributes( QgsFeature &f );
125  void addVirtualAttributes( QgsFeature &f );
126 
128  void updateChangedAttributes( QgsFeature& f );
129 
131  void updateFeatureGeometry( QgsFeature& f );
132 
137  {
143  int joinField;
144 
145  void addJoinedAttributesCached( QgsFeature& f, const QVariant& joinValue ) const;
146  void addJoinedAttributesDirect( QgsFeature& f, const QVariant& joinValue ) const;
147  };
148 
151  QMap<QgsVectorLayer*, FetchJoinInfo> mFetchJoinInfo;
152 
153  QMap<int, QgsExpression*> mExpressionFieldInfo;
154 
155  private:
157  QgsAbstractGeometrySimplifier* mEditGeometrySimplifier;
158 
160  virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const;
161 };
162 
163 #endif // QGSVECTORLAYERFEATUREITERATOR_H
QgsAbstractFeatureSource * mProviderFeatureSource
Definition: qgsvectorlayerfeatureiterator.h:45
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:139
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:323
virtual bool close()=0
end of iterating: free the resources / lock
QgsVectorLayerJoinBuffer * mJoinBuffer
Definition: qgsvectorlayerfeatureiterator.h:47
virtual bool nextFeatureFilterExpression(QgsFeature &f)
Overrides default method as we only need to filter features in the edit buffer while for others filte...
Definition: qgsvectorlayerfeatureiterator.h:88
QgsFields mFields
Definition: qgsvectorlayerfeatureiterator.h:51
QgsFeatureIterator mProviderIterator
Definition: qgsvectorlayerfeatureiterator.h:95
QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt
Definition: qgsvectorlayerfeatureiterator.h:103
QgsGeometryMap::ConstIterator mFetchChangedGeomIt
Definition: qgsvectorlayerfeatureiterator.h:102
bool mHasEditBuffer
Definition: qgsvectorlayerfeatureiterator.h:53
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:325
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
Definition: qgsvectorlayerfeatureiterator.h:22
virtual bool rewind()=0
reset the iterator to the starting position
bool mFetchedFid
Definition: qgsvectorlayerfeatureiterator.h:105
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request)
Definition: qgsvectorlayerfeatureiterator.cpp:81
Container of fields for a vector layer.
Definition: qgsfield.h:163
Definition: qgsgeometry.h:69
QMap< int, QgsExpression * > mExpressionFieldInfo
Definition: qgsvectorlayerfeatureiterator.h:153
QList< QgsField > mAddedAttributes
Definition: qgsvectorlayerfeatureiterator.h:63
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
QgsVectorLayer * joinLayer
resolved pointer to the joined layer
Definition: qgsvectorlayerfeatureiterator.h:141
Manages joined fields for a vector layer.
Definition: qgsvectorlayerjoinbuffer.h:32
bool mCanBeSimplified
Definition: qgsvectorlayerfeatureiterator.h:55
int joinField
index of field (of the joined layer) must have equal value
Definition: qgsvectorlayerfeatureiterator.h:143
QgsFeatureRequest mChangedFeaturesRequest
Definition: qgsvectorlayerfeatureiterator.h:96
QMap< QgsVectorLayer *, FetchJoinInfo > mFetchJoinInfo
information about joins used in the current select() statement.
Definition: qgsvectorlayerfeatureiterator.h:151
Definition: qgsvectorlayerfeatureiterator.h:69
const QgsVectorJoinInfo * joinInfo
cannonical source of information about the join
Definition: qgsvectorlayerfeatureiterator.h:138
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Definition: qgsfeaturerequest.h:58
QList< int > QgsAttributeList
Definition: qgsfeaturerequest.h:26
QgsFeatureRequest mProviderRequest
Definition: qgsvectorlayerfeatureiterator.h:94
QgsGeometryMap mChangedGeometries
Definition: qgsvectorlayerfeatureiterator.h:61
QgsFeatureIds mDeletedFeatureIds
Definition: qgsvectorlayerfeatureiterator.h:62
QgsAttributeList mDeletedAttributeIds
Definition: qgsvectorlayerfeatureiterator.h:65
QgsExpressionFieldBuffer * mExpressionFieldBuffer
Definition: qgsvectorlayerfeatureiterator.h:49
base class that can be used for any class that is capable of returning features
Definition: qgsfeaturerequest.h:169
QSet< QgsFeatureId > mFetchConsidered
Definition: qgsvectorlayerfeatureiterator.h:101
Partial snapshot of vector layer's state (only the members necessary for access to features) ...
Definition: qgsvectorlayerfeatureiterator.h:33
QgsVectorLayerFeatureSource(QgsVectorLayer *layer)
Definition: qgsvectorlayerfeatureiterator.cpp:26
int indexOffset
at what position the joined fields start
Definition: qgsvectorlayerfeatureiterator.h:140
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
Definition: qgsvectorlayereditbuffer.h:31
int targetField
index of field (of this layer) that drives the join
Definition: qgsvectorlayerfeatureiterator.h:142
~QgsVectorLayerFeatureSource()
Definition: qgsvectorlayerfeatureiterator.cpp:74
Buffers information about expression fields for a vector layer.
Definition: qgsexpressionfieldbuffer.h:32
Definition: qgsvectorlayereditbuffer.h:33
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:320
Definition: qgsvectorlayer.h:167
QgsFeatureMap mAddedFeatures
Definition: qgsvectorlayerfeatureiterator.h:60
Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAtt...
Definition: qgsvectorlayerfeatureiterator.h:136
qint64 QgsFeatureId
Definition: qgsfeature.h:30
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
Definition: qgssimplifymethod.h:25
QgsChangedAttributesMap mChangedAttributeValues
Definition: qgsvectorlayerfeatureiterator.h:64
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
virtual bool prepareSimplification(const QgsSimplifyMethod &simplifyMethod)
Setup the simplification of geometries to fetch using the specified simplify method.
Definition: qgsfeatureiterator.cpp:106
Abstract base class for simplify geometries using a specific algorithm.
Definition: qgsgeometrysimplifier.h:25
MethodType
Definition: qgssimplifymethod.h:28
QgsAttributeList attributes
attributes to fetch
Definition: qgsvectorlayerfeatureiterator.h:139
QgsFeatureIterator mChangedFeaturesIterator
Definition: qgsvectorlayerfeatureiterator.h:97
helper template that cares of two things: 1.
Definition: qgsfeatureiterator.h:110