QGIS API Documentation  2.5.0-Master
 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 
24 class QgsVectorLayer;
26 struct QgsVectorJoinInfo;
28 
29 
31 
34 {
35  public:
38 
39  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request );
40 
42 
43  protected:
44 
46 
48 
50 
52 
54 
55  // A deep-copy is only performed, if the original maps change
56  // see here https://github.com/qgis/Quantum-GIS/pull/673
57  // for explanation
61  QList<QgsField> mAddedAttributes;
64 };
65 
66 
67 class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsVectorLayerFeatureSource>
68 {
69  public:
70  QgsVectorLayerFeatureIterator( QgsVectorLayerFeatureSource* source, bool ownSource, const QgsFeatureRequest& request );
71 
73 
75  virtual bool rewind();
76 
78  virtual bool close();
79 
80  protected:
82  virtual bool fetchFeature( QgsFeature& feature );
83 
86  inline virtual bool nextFeatureFilterExpression( QgsFeature &f ) { return fetchFeature( f ); }
87 
89  virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod );
90 
91 
96 
97 
98  // only related to editing
99  QSet<QgsFeatureId> mFetchConsidered;
100  QgsGeometryMap::ConstIterator mFetchChangedGeomIt;
101  QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt;
102 
103  bool mFetchedFid; // when iterating by FID: indicator whether it has been fetched yet or not
104 
105  void rewindEditBuffer();
106  void prepareJoins();
107  bool fetchNextAddedFeature( QgsFeature& f );
108  bool fetchNextChangedGeomFeature( QgsFeature& f );
109  bool fetchNextChangedAttributeFeature( QgsFeature& f );
110  void useAddedFeature( const QgsFeature& src, QgsFeature& f );
111  void useChangedAttributeFeature( QgsFeatureId fid, const QgsGeometry& geom, QgsFeature& f );
112  bool nextFeatureFid( QgsFeature& f );
113  void addJoinedAttributes( QgsFeature &f );
114 
116  void updateChangedAttributes( QgsFeature& f );
117 
119  void updateFeatureGeometry( QgsFeature& f );
120 
125  {
131  int joinField;
132 
133  void addJoinedAttributesCached( QgsFeature& f, const QVariant& joinValue ) const;
134  void addJoinedAttributesDirect( QgsFeature& f, const QVariant& joinValue ) const;
135  };
136 
139  QMap<QgsVectorLayer*, FetchJoinInfo> mFetchJoinInfo;
140 
141  private:
144 
146  virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const;
147 };
148 
149 #endif // QGSVECTORLAYERFEATUREITERATOR_H
QgsAbstractFeatureSource * mProviderFeatureSource
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:323
virtual bool close()=0
end of iterating: free the resources / lock
QgsVectorLayerJoinBuffer * mJoinBuffer
virtual bool nextFeatureFilterExpression(QgsFeature &f)
Overrides default method as we only need to filter features in the edit buffer while for others filte...
QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt
QgsGeometryMap::ConstIterator mFetchChangedGeomIt
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
virtual bool providerCanSimplify(QgsSimplifyMethod::MethodType methodType) const
returns whether the iterator supports simplify geometries on provider side
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
virtual bool rewind()=0
reset the iterator to the starting position
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request)
Container of fields for a vector layer.
Definition: qgsfield.h:161
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
Manages joined fields for a vector layer.
int joinField
index of field (of the joined layer) must have equal value
QMap< QgsVectorLayer *, FetchJoinInfo > mFetchJoinInfo
information about joins used in the current select() statement.
const QgsVectorJoinInfo * joinInfo
cannonical source of information about the join
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
base class that can be used for any class that is capable of returning features
Partial snapshot of vector layer's state (only the members necessary for access to features) ...
QgsVectorLayerFeatureSource(QgsVectorLayer *layer)
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
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:320
Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAtt...
qint64 QgsFeatureId
Definition: qgsfeature.h:30
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
QgsChangedAttributesMap mChangedAttributeValues
Represents a vector layer which manages a vector based data sets.
QgsAbstractGeometrySimplifier * mEditGeometrySimplifier
optional object to locally simplify edited (changed or added) geometries fetched by this feature iter...
virtual bool prepareSimplification(const QgsSimplifyMethod &simplifyMethod)
Setup the simplification of geometries to fetch using the specified simplify method.
Abstract base class for simplify geometries using a specific algorithm.
helper template that cares of two things: 1.