[QGIS Commit] r13971 - in branches/threading-branch: python/core
src/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Jul 27 07:13:55 EDT 2010
Author: wonder
Date: 2010-07-27 11:13:55 +0000 (Tue, 27 Jul 2010)
New Revision: 13971
Added:
branches/threading-branch/src/core/qgsfeatureiterator.cpp
branches/threading-branch/src/core/qgsfeatureiterator.h
Modified:
branches/threading-branch/python/core/qgsvectordataprovider.sip
branches/threading-branch/src/core/CMakeLists.txt
branches/threading-branch/src/core/qgsvectordataprovider.cpp
branches/threading-branch/src/core/qgsvectordataprovider.h
Log:
Moved QgsFeatureIterator class to a separate file, made some functions inline
Modified: branches/threading-branch/python/core/qgsvectordataprovider.sip
===================================================================
--- branches/threading-branch/python/core/qgsvectordataprovider.sip 2010-07-27 11:12:38 UTC (rev 13970)
+++ branches/threading-branch/python/core/qgsvectordataprovider.sip 2010-07-27 11:13:55 UTC (rev 13971)
@@ -4,7 +4,7 @@
class QgsFeatureIterator
{
%TypeHeaderCode
-#include <qgsvectordataprovider.h>
+#include <qgsfeatureiterator.h>
%End
public:
Modified: branches/threading-branch/src/core/CMakeLists.txt
===================================================================
--- branches/threading-branch/src/core/CMakeLists.txt 2010-07-27 11:12:38 UTC (rev 13970)
+++ branches/threading-branch/src/core/CMakeLists.txt 2010-07-27 11:13:55 UTC (rev 13971)
@@ -46,6 +46,7 @@
qgsdatasourceuri.cpp
qgsdistancearea.cpp
qgsfeature.cpp
+ qgsfeatureiterator.cpp
qgsfield.cpp
qgsgeometry.cpp
qgshttptransaction.cpp
@@ -391,6 +392,7 @@
qgscsexception.h
qgsexception.h
qgsfeature.h
+ qgsfeatureiterator.h
qgsfield.h
qgsgeometry.h
qgshttptransaction.h
Added: branches/threading-branch/src/core/qgsfeatureiterator.cpp
===================================================================
--- branches/threading-branch/src/core/qgsfeatureiterator.cpp (rev 0)
+++ branches/threading-branch/src/core/qgsfeatureiterator.cpp 2010-07-27 11:13:55 UTC (rev 13971)
@@ -0,0 +1,45 @@
+
+#include "qgsfeatureiterator.h"
+
+
+QgsVectorDataProviderIterator::QgsVectorDataProviderIterator(QgsAttributeList fetchAttributes,
+ QgsRectangle rect,
+ bool fetchGeometry,
+ bool useIntersect )
+ : mFetchAttributes(fetchAttributes),
+ mFetchGeometry(fetchGeometry),
+ mRect(rect),
+ mUseIntersect(useIntersect),
+ refs(0),
+ mClosed(false)
+{
+}
+
+QgsVectorDataProviderIterator::~QgsVectorDataProviderIterator()
+{
+}
+
+void QgsVectorDataProviderIterator::ref()
+{
+ refs++;
+}
+void QgsVectorDataProviderIterator::deref()
+{
+ refs--;
+ if (!refs)
+ delete this;
+}
+
+
+QgsFeatureIterator& QgsFeatureIterator::operator=(const QgsFeatureIterator& other)
+{
+ if (this != &other)
+ {
+ if (provIter)
+ provIter->deref();
+ provIter = other.provIter;
+ if (provIter)
+ provIter->ref();
+ }
+ return *this;
+}
Added: branches/threading-branch/src/core/qgsfeatureiterator.h
===================================================================
--- branches/threading-branch/src/core/qgsfeatureiterator.h (rev 0)
+++ branches/threading-branch/src/core/qgsfeatureiterator.h 2010-07-27 11:13:55 UTC (rev 13971)
@@ -0,0 +1,142 @@
+#ifndef QGSFEATUREITERATOR_H
+#define QGSFEATUREITERATOR_H
+
+#include <QList>
+
+#include "qgsrectangle.h"
+
+typedef QList<int> QgsAttributeList;
+
+class QgsFeature;
+
+/** \ingroup core
+ * Internal feature iterator to be implemented within data providers
+ */
+class QgsVectorDataProviderIterator
+{
+public:
+ //! base class constructor - stores the iteration parameters
+ QgsVectorDataProviderIterator(QgsAttributeList fetchAttributes = QgsAttributeList(),
+ QgsRectangle rect = QgsRectangle(),
+ bool fetchGeometry = true,
+ bool useIntersect = false );
+
+ //! destructor makes sure that the iterator is closed properly
+ virtual ~QgsVectorDataProviderIterator();
+
+ //! 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:
+ QgsAttributeList mFetchAttributes;
+ bool mFetchGeometry;
+ QgsRectangle mRect;
+ bool mUseIntersect;
+
+ 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 an iterator for iterating an instance of vector data provider
+ QgsFeatureIterator(QgsVectorDataProviderIterator* iter);
+ //! construct an iterator for iterating an instance of vector layer (data provider + uncommitted data)
+ //QgsFeatureIterator(VectorLayerIterator* layerIter);
+ //! copy constructor copies the provider iterator, increases ref.count
+ QgsFeatureIterator(const QgsFeatureIterator& fi);
+ //! destructor deletes the provider 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:
+ QgsVectorDataProviderIterator* provIter;
+};
+
+////////
+
+inline QgsFeatureIterator::QgsFeatureIterator()
+ : provIter(NULL)
+{
+}
+
+inline QgsFeatureIterator::QgsFeatureIterator(QgsVectorDataProviderIterator* iter)
+ : provIter(iter)
+{
+ if (iter)
+ iter->ref();
+}
+
+inline QgsFeatureIterator::QgsFeatureIterator(const QgsFeatureIterator& fi)
+ : provIter(fi.provIter)
+{
+ if (provIter)
+ provIter->ref();
+}
+
+inline QgsFeatureIterator::~QgsFeatureIterator()
+{
+ if (provIter)
+ provIter->deref();
+}
+
+inline bool QgsFeatureIterator::nextFeature(QgsFeature& f)
+{
+ return provIter ? provIter->nextFeature(f) : false;
+}
+
+inline bool QgsFeatureIterator::rewind()
+{
+ return provIter ? provIter->rewind() : false;
+}
+
+inline bool QgsFeatureIterator::close()
+{
+ return provIter ? provIter->close() : false;
+}
+
+inline bool QgsFeatureIterator::isClosed()
+{
+ return provIter ? provIter->mClosed : true;
+}
+
+
+inline bool operator== (const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
+{
+ return (fi1.provIter == fi2.provIter);
+}
+inline bool operator!= (const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
+{
+ return !(fi1 == fi2);
+}
+
+
+#endif // QGSFEATUREITERATOR_H
Modified: branches/threading-branch/src/core/qgsvectordataprovider.cpp
===================================================================
--- branches/threading-branch/src/core/qgsvectordataprovider.cpp 2010-07-27 11:12:38 UTC (rev 13970)
+++ branches/threading-branch/src/core/qgsvectordataprovider.cpp 2010-07-27 11:13:55 UTC (rev 13971)
@@ -31,112 +31,6 @@
-QgsVectorDataProviderIterator::QgsVectorDataProviderIterator(QgsAttributeList fetchAttributes,
- QgsRectangle rect,
- bool fetchGeometry,
- bool useIntersect )
- : mFetchAttributes(fetchAttributes),
- mFetchGeometry(fetchGeometry),
- mRect(rect),
- mUseIntersect(useIntersect),
- refs(0),
- mClosed(false)
-{
-}
-
-QgsVectorDataProviderIterator::~QgsVectorDataProviderIterator()
-{
-}
-
-void QgsVectorDataProviderIterator::ref()
-{
- refs++;
- QgsDebugMsg("ADDED REF: "+QString::number(refs));
-}
-void QgsVectorDataProviderIterator::deref()
-{
- refs--;
- QgsDebugMsg("REMOVED REF: "+QString::number(refs));
- if (!refs)
- delete this;
-}
-
-////////
-
-QgsFeatureIterator::QgsFeatureIterator()
- : provIter(NULL)
-{
- QgsDebugMsg("CREATED INVALID ITER");
-}
-
-QgsFeatureIterator::QgsFeatureIterator(QgsVectorDataProviderIterator* iter)
- : provIter(iter)
-{
- QgsDebugMsg("CREATED GOOD ITER");
- if (iter)
- iter->ref();
-}
-
-QgsFeatureIterator::QgsFeatureIterator(const QgsFeatureIterator& fi)
- : provIter(fi.provIter)
-{
- QgsDebugMsg("CREATED COPIED ITER");
- if (provIter)
- provIter->ref();
-}
-
-QgsFeatureIterator::~QgsFeatureIterator()
-{
- QgsDebugMsg("DELETING ITER");
- if (provIter)
- provIter->deref();
-}
-
-QgsFeatureIterator& QgsFeatureIterator::operator=(const QgsFeatureIterator& other)
-{
- if (this != &other)
- {
- if (provIter)
- provIter->deref();
- provIter = other.provIter;
- if (provIter)
- provIter->ref();
- }
- return *this;
-}
-
-bool QgsFeatureIterator::nextFeature(QgsFeature& f)
-{
- return provIter ? provIter->nextFeature(f) : false;
-}
-
-bool QgsFeatureIterator::rewind()
-{
- return provIter ? provIter->rewind() : false;
-}
-
-bool QgsFeatureIterator::close()
-{
- return provIter ? provIter->close() : false;
-}
-
-bool QgsFeatureIterator::isClosed()
-{
- return provIter ? provIter->mClosed : true;
-}
-
-
-bool operator== (const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
-{
- return (fi1.provIter == fi2.provIter);
-}
-bool operator!= (const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
-{
- return !(fi1 == fi2);
-}
-
-////////////
-
QgsVectorDataProvider::QgsVectorDataProvider( QString uri )
: QgsDataProvider( uri ),
mCacheMinMaxDirty( true ),
Modified: branches/threading-branch/src/core/qgsvectordataprovider.h
===================================================================
--- branches/threading-branch/src/core/qgsvectordataprovider.h 2010-07-27 11:12:38 UTC (rev 13970)
+++ branches/threading-branch/src/core/qgsvectordataprovider.h 2010-07-27 11:13:55 UTC (rev 13971)
@@ -26,86 +26,14 @@
#include "qgis.h"
#include "qgsdataprovider.h"
#include "qgsfeature.h"
+#include "qgsfeatureiterator.h"
#include "qgsfield.h"
-#include "qgsrectangle.h"
-typedef QList<int> QgsAttributeList;
typedef QSet<int> QgsFeatureIds;
typedef QSet<int> QgsAttributeIds;
-/** \ingroup core
- * Internal feature iterator to be implemented within data providers
- */
-class QgsVectorDataProviderIterator
-{
-public:
- //! base class constructor - stores the iteration parameters
- QgsVectorDataProviderIterator(QgsAttributeList fetchAttributes = QgsAttributeList(),
- QgsRectangle rect = QgsRectangle(),
- bool fetchGeometry = true,
- bool useIntersect = false );
- //! destructor makes sure that the iterator is closed properly
- virtual ~QgsVectorDataProviderIterator();
-
- //! 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:
- QgsAttributeList mFetchAttributes;
- bool mFetchGeometry;
- QgsRectangle mRect;
- bool mUseIntersect;
-
- 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 an iterator for iterating an instance of vector data provider
- QgsFeatureIterator(QgsVectorDataProviderIterator* iter);
- //! construct an iterator for iterating an instance of vector layer (data provider + uncommitted data)
- //QgsFeatureIterator(VectorLayerIterator* layerIter);
- //! copy constructor copies the provider iterator, increases ref.count
- QgsFeatureIterator(const QgsFeatureIterator& fi);
- //! destructor deletes the provider 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:
- QgsVectorDataProviderIterator* provIter;
-};
-
-
/** \ingroup core
* This is the base class for vector data providers.
*
More information about the QGIS-commit
mailing list