Sipify core.QgsFeatureIterator

This commit is contained in:
arnaud.morvan@camptocamp.com 2017-05-02 18:47:35 +02:00
parent 05933b171a
commit 04a9264e86
3 changed files with 196 additions and 71 deletions

View File

@ -9,7 +9,6 @@ core/qgseditorwidgetsetup.sip
core/qgserror.sip
core/qgsexpressioncontext.sip
core/qgsexpressioncontextgenerator.sip
core/qgsfeatureiterator.sip
core/qgsfeaturerequest.sip
core/qgsgeometrysimplifier.sip
core/qgsgeometryvalidator.sip

View File

@ -1,125 +1,208 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsfeatureiterator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsAbstractFeatureIterator
{
%Docstring
Internal feature iterator to be implemented within data providers
%End
%TypeHeaderCode
#include <qgsfeatureiterator.h>
#include "qgsfeatureiterator.h"
%End
public:
//! Status of expression compilation for filter expression requests
enum CompileStatus
{
NoCompilation, /*!< Expression could not be compiled or not attempt was made to compile expression */
PartiallyCompiled, /*!< Expression was partially compiled, but extra checks need to be applied to features*/
Compiled, /*!< Expression was fully compiled and delegated to data provider source*/
NoCompilation,
PartiallyCompiled,
Compiled,
};
//! base class constructor - stores the iteration parameters
QgsAbstractFeatureIterator( const QgsFeatureRequest &request );
%Docstring
base class constructor - stores the iteration parameters
%End
//! destructor makes sure that the iterator is closed properly
virtual ~QgsAbstractFeatureIterator();
%Docstring
destructor makes sure that the iterator is closed properly
%End
//! fetch next feature, return true on success
virtual bool nextFeature( QgsFeature &f );
%Docstring
fetch next feature, return true on success
:rtype: bool
%End
//! reset the iterator to the starting position
virtual bool rewind() = 0;
//! end of iterating: free the resources / lock
%Docstring
reset the iterator to the starting position
:rtype: bool
%End
virtual bool close() = 0;
%Docstring
end of iterating: free the resources / lock
:rtype: bool
%End
/** Returns the status of expression compilation for filter expression requests.
* @note added in QGIS 2.16
*/
CompileStatus compileStatus() const;
%Docstring
Returns the status of expression compilation for filter expression requests.
.. versionadded:: 2.16
:rtype: CompileStatus
%End
protected:
/**
* If you write a feature iterator for your provider, this is the method you
* need to implement!!
*
* @param f The feature to write to
* @return true if a feature was written to f
*/
virtual bool fetchFeature( QgsFeature &f ) = 0;
%Docstring
If you write a feature iterator for your provider, this is the method you
need to implement!!
\param f The feature to write to
:return: true if a feature was written to f
:rtype: bool
%End
/**
* By default, the iterator will fetch all features and check if the feature
* matches the expression.
* If you have a more sophisticated metodology (SQL request for the features...)
* and you check for the expression in your fetchFeature method, you can just
* redirect this call to fetchFeature so the default check will be omitted.
*
* @param f The feature to write to
* @return true if a feature was written to f
*/
virtual bool nextFeatureFilterExpression( QgsFeature &f );
%Docstring
By default, the iterator will fetch all features and check if the feature
matches the expression.
If you have a more sophisticated metodology (SQL request for the features...)
and you check for the expression in your fetchFeature method, you can just
redirect this call to fetchFeature so the default check will be omitted.
\param f The feature to write to
:return: true if a feature was written to f
:rtype: bool
%End
/**
* By default, the iterator will fetch all features and check if the id
* is in the request.
* If you have a more sophisticated metodology (SQL request for the features...)
* and you are sure, that any feature you return from fetchFeature will match
* if the request was FilterFids you can just redirect this call to fetchFeature
* so the default check will be omitted.
*
* @param f The feature to write to
* @return true if a feature was written to f
*/
virtual bool nextFeatureFilterFids( QgsFeature &f );
%Docstring
By default, the iterator will fetch all features and check if the id
is in the request.
If you have a more sophisticated metodology (SQL request for the features...)
and you are sure, that any feature you return from fetchFeature will match
if the request was FilterFids you can just redirect this call to fetchFeature
so the default check will be omitted.
\param f The feature to write to
:return: true if a feature was written to f
:rtype: bool
%End
void ref();
%Docstring
Add reference
%End
void deref();
%Docstring
Remove reference, delete if refs == 0
%End
void ref(); //!< add reference
void deref(); //!< remove reference, delete if refs == 0
//! Setup the simplification of geometries to fetch using the specified simplify method
virtual bool prepareSimplification( const QgsSimplifyMethod &simplifyMethod );
%Docstring
Setup the simplification of geometries to fetch using the specified simplify method
:rtype: bool
%End
};
class QgsFeatureIterator
{
%Docstring
Wrapper for iterator of features from vector data provider or vector layer
%End
%TypeHeaderCode
#include <qgsfeatureiterator.h>
#include "qgsfeatureiterator.h"
%End
public:
QgsFeatureIterator *__iter__();
%Docstring
:rtype: QgsFeatureIterator
%End
%MethodCode
sipRes = sipCpp;
sipRes = sipCpp;
%End
SIP_PYOBJECT __next__();
SIP_PYOBJECT __next__();
%MethodCode
QgsFeature *f = new QgsFeature;
if (sipCpp->nextFeature(*f))
sipRes = sipConvertFromType(f, sipType_QgsFeature, Py_None);
else
{
delete f;
PyErr_SetString(PyExc_StopIteration,"");
}
QgsFeature *f = new QgsFeature;
if ( sipCpp->nextFeature( *f ) )
sipRes = sipConvertFromType( f, sipType_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
%Docstring
construct invalid iterator
%End
QgsFeatureIterator( const QgsFeatureIterator &fi );
//! destructor deletes the iterator if it has no more references
%Docstring
copy constructor copies the iterator, increases ref.count
%End
~QgsFeatureIterator();
%Docstring
destructor deletes the iterator if it has no more references
%End
// QgsFeatureIterator &operator=(const QgsFeatureIterator &other);
bool nextFeature( QgsFeature &f );
%Docstring
:rtype: bool
%End
bool rewind();
%Docstring
:rtype: bool
%End
bool close();
%Docstring
:rtype: bool
%End
//! find out whether the iterator is still valid or closed already
bool isClosed() const;
%Docstring
find out whether the iterator is still valid or closed already
:rtype: bool
%End
/** Returns the status of expression compilation for filter expression requests.
* @note added in QGIS 2.16
*/
QgsAbstractFeatureIterator::CompileStatus compileStatus() const;
%Docstring
Returns the status of expression compilation for filter expression requests.
.. versionadded:: 2.16
:rtype: QgsAbstractFeatureIterator.CompileStatus
%End
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsfeatureiterator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -19,6 +19,7 @@
#include "qgsfeaturerequest.h"
#include "qgsindexedfeature.h"
#ifndef SIP_RUN
/** \ingroup core
* Interface that can be optionally attached to an iterator so its
@ -33,6 +34,8 @@ class CORE_EXPORT QgsInterruptionChecker
virtual bool mustStop() const = 0;
};
#endif
/** \ingroup core
* Internal feature iterator to be implemented within data providers
*/
@ -62,6 +65,8 @@ class CORE_EXPORT QgsAbstractFeatureIterator
//! end of iterating: free the resources / lock
virtual bool close() = 0;
#ifndef SIP_RUN
/** Attach an object that can be queried regularly by the iterator to check
* if it must stopped. This is mostly useful for iterators where a single
* nextFeature()/fetchFeature() iteration might be very long. A typical use case is the
@ -71,6 +76,7 @@ class CORE_EXPORT QgsAbstractFeatureIterator
* \note not available in Python bindings
*/
virtual void setInterruptionChecker( QgsInterruptionChecker *interruptionChecker );
#endif
/** Returns the status of expression compilation for filter expression requests.
* \since QGIS 2.16
@ -131,8 +137,10 @@ class CORE_EXPORT QgsAbstractFeatureIterator
//! reference counting (to allow seamless copying of QgsFeatureIterator instances)
//! TODO QGIS3: make this private
int refs;
void ref(); //!< Add reference
void deref(); //!< Remove reference, delete if refs == 0
//! Add reference
void ref();
//! Remove reference, delete if refs == 0
void deref();
friend class QgsFeatureIterator;
//! Number of features already fetched by iterator
@ -171,7 +179,7 @@ class CORE_EXPORT QgsAbstractFeatureIterator
void setupOrderBy( const QList<QgsFeatureRequest::OrderByClause> &orderBys );
};
#ifndef SIP_RUN
/** \ingroup core
* Helper template that cares of two things: 1. automatic deletion of source if owned by iterator, 2. notification of open/closed iterator.
@ -203,6 +211,8 @@ class QgsAbstractFeatureIteratorFromSource : public QgsAbstractFeatureIterator
bool mOwnSource;
};
#endif
/**
* \ingroup core
* Wrapper for iterator of features from vector data provider or vector layer
@ -210,10 +220,32 @@ class QgsAbstractFeatureIteratorFromSource : public QgsAbstractFeatureIterator
class CORE_EXPORT QgsFeatureIterator
{
public:
#ifdef SIP_RUN
QgsFeatureIterator *__iter__();
% MethodCode
sipRes = sipCpp;
% End
SIP_PYOBJECT __next__();
% MethodCode
QgsFeature *f = new QgsFeature;
if ( sipCpp->nextFeature( *f ) )
sipRes = sipConvertFromType( f, sipType_QgsFeature, Py_None );
else
{
delete f;
PyErr_SetString( PyExc_StopIteration, "" );
}
% End
#endif
//! construct invalid iterator
QgsFeatureIterator();
#ifndef SIP_RUN
//! construct a valid iterator
QgsFeatureIterator( QgsAbstractFeatureIterator *iter );
#endif
//! copy constructor copies the iterator, increases ref.count
QgsFeatureIterator( const QgsFeatureIterator &fi );
//! destructor deletes the iterator if it has no more references
@ -228,6 +260,8 @@ class CORE_EXPORT QgsFeatureIterator
//! find out whether the iterator is still valid or closed already
bool isClosed() const;
#ifndef SIP_RUN
/** Attach an object that can be queried regularly by the iterator to check
* if it must stopped. This is mostly useful for iterators where a single
* nextFeature()/fetchFeature() iteration might be very long. A typical use case is the
@ -237,19 +271,26 @@ class CORE_EXPORT QgsFeatureIterator
*/
void setInterruptionChecker( QgsInterruptionChecker *interruptionChecker );
#endif
/** Returns the status of expression compilation for filter expression requests.
* \since QGIS 2.16
*/
QgsAbstractFeatureIterator::CompileStatus compileStatus() const { return mIter->compileStatus(); }
#ifndef SIP_RUN
friend bool operator== ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 );
friend bool operator!= ( const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2 );
protected:
QgsAbstractFeatureIterator *mIter = nullptr;
#endif
};
////////
#ifndef SIP_RUN
inline QgsFeatureIterator::QgsFeatureIterator()
: mIter( nullptr )
@ -318,4 +359,6 @@ inline void QgsFeatureIterator::setInterruptionChecker( QgsInterruptionChecker *
mIter->setInterruptionChecker( interruptionChecker );
}
#endif
#endif // QGSFEATUREITERATOR_H