QGIS API Documentation  2.3.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsfeatureiterator.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfeatureiterator.h
3  ---------------------
4  begin : Juli 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 QGSFEATUREITERATOR_H
16 #define QGSFEATUREITERATOR_H
17 
18 #include "qgsfeaturerequest.h"
19 #include "qgslogger.h"
20 
22 
26 class CORE_EXPORT QgsAbstractFeatureIterator
27 {
28  public:
31 
33  virtual ~QgsAbstractFeatureIterator();
34 
36  virtual bool nextFeature( QgsFeature& f );
37 
39  virtual bool rewind() = 0;
41  virtual bool close() = 0;
42 
43  protected:
51  virtual bool fetchFeature( QgsFeature& f ) = 0;
52 
63  virtual bool nextFeatureFilterExpression( QgsFeature &f );
64 
76  virtual bool nextFeatureFilterFids( QgsFeature & f );
77 
80 
82  bool mClosed;
83 
85  int refs;
86  void ref();
87  void deref();
88  friend class QgsFeatureIterator;
89 
91  virtual bool prepareSimplification( const QgsSimplifyMethod& simplifyMethod );
92 
93  private:
98 
100  virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const;
101 
103  virtual bool simplify( QgsFeature& feature );
104 };
105 
106 
107 
109 template<typename T>
111 {
112  public:
113  QgsAbstractFeatureIteratorFromSource( T* source, bool ownSource, const QgsFeatureRequest& request )
114  : QgsAbstractFeatureIterator( request ), mSource( source ), mOwnSource( ownSource )
115  {
116  mSource->iteratorOpened( this );
117  }
118 
120  {
121  if ( mOwnSource )
122  delete mSource;
123  }
124 
125  protected:
127  void iteratorClosed() { mSource->iteratorClosed( this ); }
128 
131 };
132 
133 
134 
139 class CORE_EXPORT QgsFeatureIterator
140 {
141  public:
150 
151  QgsFeatureIterator& operator=( const QgsFeatureIterator& other );
152 
153  bool nextFeature( QgsFeature& f );
154  bool rewind();
155  bool close();
156 
158  bool isClosed() const;
159 
160  friend bool operator== ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 );
161  friend bool operator!= ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 );
162 
163  protected:
165 };
166 
168 
170  : mIter( NULL )
171 {
172 }
173 
175  : mIter( iter )
176 {
177  if ( iter )
178  iter->ref();
179 }
180 
182  : mIter( fi.mIter )
183 {
184  if ( mIter )
185  mIter->ref();
186 }
187 
189 {
190  if ( mIter )
191  mIter->deref();
192 }
193 
195 {
196  return mIter ? mIter->nextFeature( f ) : false;
197 }
198 
200 {
201  return mIter ? mIter->rewind() : false;
202 }
203 
205 {
206  return mIter ? mIter->close() : false;
207 }
208 
209 inline bool QgsFeatureIterator::isClosed() const
210 {
211  return mIter ? mIter->mClosed : true;
212 }
213 
214 inline bool operator== ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 )
215 {
216  return ( fi1.mIter == fi2.mIter );
217 }
218 
219 inline bool operator!= ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 )
220 {
221  return !( fi1 == fi2 );
222 }
223 
224 #endif // QGSFEATUREITERATOR_H
Wrapper for iterator of features from vector data provider or vector layer.
virtual bool close()=0
end of iterating: free the resources / lock
bool mLocalSimplification
this iterator runs local simplification
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
virtual bool rewind()=0
reset the iterator to the starting position
bool mClosed
Set to true, as soon as the iterator is closed.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:114
bool isClosed() const
find out whether the iterator is still valid or closed already
void iteratorClosed()
to be called by from subclass in close()
virtual bool nextFeature(QgsFeature &f)
fetch next feature, return true on success
Internal feature iterator to be implemented within data providers.
QgsFeatureIterator()
construct invalid iterator
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void deref()
remove reference, delete if refs == 0
QgsFeatureRequest mRequest
A copy of the feature request.
QgsAbstractGeometrySimplifier * mGeometrySimplifier
optional object to locally simplify geometries fetched by this feature iterator
QgsAbstractFeatureIterator * mIter
~QgsFeatureIterator()
destructor deletes the iterator if it has no more references
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
int refs
reference counting (to allow seamless copying of QgsFeatureIterator instances)
bool nextFeature(QgsFeature &f)
Abstract base class for simplify geometries using a specific algorithm.
QgsAbstractFeatureIteratorFromSource(T *source, bool ownSource, const QgsFeatureRequest &request)
helper template that cares of two things: 1.