QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
156 
157  private:
159  QgsAbstractGeometrySimplifier* mEditGeometrySimplifier;
160 
162  virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const;
163 };
164 
165 #endif // QGSVECTORLAYERFEATUREITERATOR_H