QGIS API Documentation  2.2.0-Valmiera
 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 
111 class CORE_EXPORT QgsFeatureIterator
112 {
113  public:
122 
123  QgsFeatureIterator& operator=( const QgsFeatureIterator& other );
124 
125  bool nextFeature( QgsFeature& f );
126  bool rewind();
127  bool close();
128 
130  bool isClosed() const;
131 
132  friend bool operator== ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 );
133  friend bool operator!= ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 );
134 
135  protected:
137 };
138 
140 
142  : mIter( NULL )
143 {
144 }
145 
147  : mIter( iter )
148 {
149  if ( iter )
150  iter->ref();
151 }
152 
154  : mIter( fi.mIter )
155 {
156  if ( mIter )
157  mIter->ref();
158 }
159 
161 {
162  if ( mIter )
163  mIter->deref();
164 }
165 
167 {
168  return mIter ? mIter->nextFeature( f ) : false;
169 }
170 
172 {
173  return mIter ? mIter->rewind() : false;
174 }
175 
177 {
178  return mIter ? mIter->close() : false;
179 }
180 
181 inline bool QgsFeatureIterator::isClosed() const
182 {
183  return mIter ? mIter->mClosed : true;
184 }
185 
186 inline bool operator== ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 )
187 {
188  return ( fi1.mIter == fi2.mIter );
189 }
190 
191 inline bool operator!= ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 )
192 {
193  return !( fi1 == fi2 );
194 }
195 
196 #endif // QGSFEATUREITERATOR_H