-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API] added QgsFeatureIterator, changed QgsVectorProvider API
Vector data provider now has getFeatures() method to access features. select(), nextFeature(), featureAtId(), rewind() were removed resp. moved to provider's feature iterator implementations. Providers that currently do not implement the new API were disabled.
- Loading branch information
Showing
49 changed files
with
2,378 additions
and
1,947 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
|
||
class QgsFeatureIterator | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsfeatureiterator.h> | ||
%End | ||
|
||
public: | ||
|
||
|
||
QgsFeatureIterator* __iter__(); | ||
%MethodCode | ||
sipRes = sipCpp; | ||
%End | ||
|
||
SIP_PYOBJECT __next__(); | ||
%MethodCode | ||
QgsFeature* f = new QgsFeature; | ||
if (sipCpp->nextFeature(*f)) | ||
sipRes = sipConvertFromInstance(f, sipClass_QgsFeature, Py_None); | ||
else | ||
{ | ||
delete f; | ||
PyErr_SetString(PyExc_StopIteration,""); | ||
} | ||
%End | ||
|
||
|
||
//! construct invalid iterator | ||
QgsFeatureIterator(); | ||
//! construct a valid iterator | ||
//QgsFeatureIterator(QgsAbstractFeatureIterator* iter); | ||
//! copy constructor copies the iterator, increases ref.count | ||
QgsFeatureIterator(const QgsFeatureIterator& fi); | ||
//! destructor deletes the iterator if it has no more references | ||
~QgsFeatureIterator(); | ||
|
||
//QgsFeatureIterator& operator=(const QgsFeatureIterator& other); | ||
|
||
bool nextFeature(QgsFeature& f); | ||
bool rewind(); | ||
bool close(); | ||
|
||
//! find out whether the iterator is still valid or closed already | ||
bool isClosed(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "qgsfeatureiterator.h" | ||
|
||
|
||
QgsAbstractFeatureIterator::QgsAbstractFeatureIterator( const QgsFeatureRequest& request ) | ||
: mRequest( request ), | ||
mClosed( false ), | ||
refs( 0 ) | ||
{ | ||
} | ||
|
||
QgsAbstractFeatureIterator::~QgsAbstractFeatureIterator() | ||
{ | ||
} | ||
|
||
void QgsAbstractFeatureIterator::ref() | ||
{ | ||
refs++; | ||
} | ||
void QgsAbstractFeatureIterator::deref() | ||
{ | ||
refs--; | ||
if ( !refs ) | ||
delete this; | ||
} | ||
|
||
/////// | ||
|
||
QgsFeatureIterator& QgsFeatureIterator::operator=( const QgsFeatureIterator & other ) | ||
{ | ||
if ( this != &other ) | ||
{ | ||
if ( mIter ) | ||
mIter->deref(); | ||
mIter = other.mIter; | ||
if ( mIter ) | ||
mIter->ref(); | ||
} | ||
return *this; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#ifndef QGSFEATUREITERATOR_H | ||
#define QGSFEATUREITERATOR_H | ||
|
||
#include "qgsfeaturerequest.h" | ||
|
||
|
||
/** \ingroup core | ||
* Internal feature iterator to be implemented within data providers | ||
*/ | ||
class QgsAbstractFeatureIterator | ||
{ | ||
public: | ||
//! base class constructor - stores the iteration parameters | ||
QgsAbstractFeatureIterator( const QgsFeatureRequest& request ); | ||
|
||
//! destructor makes sure that the iterator is closed properly | ||
virtual ~QgsAbstractFeatureIterator(); | ||
|
||
//! fetch next feature, return true on success | ||
virtual bool nextFeature( QgsFeature& f ) = 0; | ||
//! reset the iterator to the starting position | ||
virtual bool rewind() = 0; | ||
//! end of iterating: free the resources / lock | ||
virtual bool close() = 0; | ||
|
||
protected: | ||
QgsFeatureRequest mRequest; | ||
|
||
bool mClosed; | ||
|
||
// reference counting (to allow seamless copying of QgsFeatureIterator instances) | ||
int refs; | ||
void ref(); // add reference | ||
void deref(); // remove reference, delete if refs == 0 | ||
friend class QgsFeatureIterator; | ||
}; | ||
|
||
|
||
/** | ||
* \ingroup core | ||
* Wrapper for iterator of features from vector data provider or vector layer | ||
*/ | ||
class QgsFeatureIterator | ||
{ | ||
public: | ||
//! construct invalid iterator | ||
QgsFeatureIterator(); | ||
//! construct a valid iterator | ||
QgsFeatureIterator( QgsAbstractFeatureIterator* iter ); | ||
//! copy constructor copies the iterator, increases ref.count | ||
QgsFeatureIterator( const QgsFeatureIterator& fi ); | ||
//! destructor deletes the iterator if it has no more references | ||
~QgsFeatureIterator(); | ||
|
||
QgsFeatureIterator& operator=( const QgsFeatureIterator& other ); | ||
|
||
bool nextFeature( QgsFeature& f ); | ||
bool rewind(); | ||
bool close(); | ||
|
||
//! find out whether the iterator is still valid or closed already | ||
bool isClosed(); | ||
|
||
friend bool operator== ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 ); | ||
friend bool operator!= ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 ); | ||
|
||
protected: | ||
QgsAbstractFeatureIterator* mIter; | ||
}; | ||
|
||
//////// | ||
|
||
inline QgsFeatureIterator::QgsFeatureIterator() | ||
: mIter( NULL ) | ||
{ | ||
} | ||
|
||
inline QgsFeatureIterator::QgsFeatureIterator( QgsAbstractFeatureIterator* iter ) | ||
: mIter( iter ) | ||
{ | ||
if ( iter ) | ||
iter->ref(); | ||
} | ||
|
||
inline QgsFeatureIterator::QgsFeatureIterator( const QgsFeatureIterator& fi ) | ||
: mIter( fi.mIter ) | ||
{ | ||
if ( mIter ) | ||
mIter->ref(); | ||
} | ||
|
||
inline QgsFeatureIterator::~QgsFeatureIterator() | ||
{ | ||
if ( mIter ) | ||
mIter->deref(); | ||
} | ||
|
||
inline bool QgsFeatureIterator::nextFeature( QgsFeature& f ) | ||
{ | ||
return mIter ? mIter->nextFeature( f ) : false; | ||
} | ||
|
||
inline bool QgsFeatureIterator::rewind() | ||
{ | ||
return mIter ? mIter->rewind() : false; | ||
} | ||
|
||
inline bool QgsFeatureIterator::close() | ||
{ | ||
return mIter ? mIter->close() : false; | ||
} | ||
|
||
inline bool QgsFeatureIterator::isClosed() | ||
{ | ||
return mIter ? mIter->mClosed : true; | ||
} | ||
|
||
|
||
inline bool operator== ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 ) | ||
{ | ||
return ( fi1.mIter == fi2.mIter ); | ||
} | ||
inline bool operator!= ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 ) | ||
{ | ||
return !( fi1 == fi2 ); | ||
} | ||
|
||
|
||
#endif // QGSFEATUREITERATOR_H |
Oops, something went wrong.