Skip to content
Permalink
Browse files

vector providers: allow multiple iterators - testing required

  • Loading branch information
jef-n committed Jun 21, 2013
1 parent 4164d6e commit 3747c2bb020625871d6a0352f1a968657d443bf6
Showing with 177 additions and 179 deletions.
  1. +4 −3 src/core/qgsfeatureiterator.cpp
  2. +1 −2 src/core/qgsfeatureiterator.h
  3. +9 −0 src/core/qgsvectorlayer.cpp
  4. +5 −11 src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.cpp
  5. +13 −5 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
  6. +1 −1 src/providers/delimitedtext/qgsdelimitedtextprovider.h
  7. +4 −18 src/providers/gpx/qgsgpxfeatureiterator.cpp
  8. +0 −1 src/providers/gpx/qgsgpxfeatureiterator.h
  9. +8 −5 src/providers/gpx/qgsgpxprovider.cpp
  10. +1 −1 src/providers/gpx/qgsgpxprovider.h
  11. +3 −10 src/providers/grass/qgsgrassfeatureiterator.cpp
  12. +6 −3 src/providers/grass/qgsgrassprovider.cpp
  13. +1 −1 src/providers/grass/qgsgrassprovider.h
  14. +6 −11 src/providers/memory/qgsmemoryfeatureiterator.cpp
  15. +7 −4 src/providers/memory/qgsmemoryprovider.cpp
  16. +1 −1 src/providers/memory/qgsmemoryprovider.h
  17. +13 −10 src/providers/ogr/qgsogrfeatureiterator.cpp
  18. +3 −3 src/providers/ogr/qgsogrprovider.cpp
  19. +1 −1 src/providers/ogr/qgsogrprovider.h
  20. +4 −0 src/providers/oracle/qgsoraclefeatureiterator.cpp
  21. +8 −0 src/providers/oracle/qgsoracleprovider.cpp
  22. +1 −0 src/providers/oracle/qgsoracleprovider.h
  23. +3 −37 src/providers/postgres/qgspostgresfeatureiterator.cpp
  24. +33 −4 src/providers/postgres/qgspostgresprovider.cpp
  25. +5 −4 src/providers/postgres/qgspostgresprovider.h
  26. +3 −11 src/providers/spatialite/qgsspatialitefeatureiterator.cpp
  27. +6 −3 src/providers/spatialite/qgsspatialiteprovider.cpp
  28. +1 −1 src/providers/spatialite/qgsspatialiteprovider.h
  29. +7 −11 src/providers/wfs/qgswfsfeatureiterator.cpp
  30. +18 −16 src/providers/wfs/qgswfsprovider.cpp
  31. +1 −1 src/providers/wfs/qgswfsprovider.h
@@ -16,9 +16,9 @@


QgsAbstractFeatureIterator::QgsAbstractFeatureIterator( const QgsFeatureRequest& request )
: mRequest( request ),
mClosed( false ),
refs( 0 )
: mRequest( request )
, mClosed( false )
, refs( 0 )
{
}

@@ -30,6 +30,7 @@ void QgsAbstractFeatureIterator::ref()
{
refs++;
}

void QgsAbstractFeatureIterator::deref()
{
refs--;
@@ -129,15 +129,14 @@ 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
@@ -3582,6 +3582,15 @@ QString QgsVectorLayer::metadata()
myMetadata += storageType();
myMetadata += "</p>\n";

if ( dataProvider() )
{
//provider description
myMetadata += "<p class=\"glossy\">" + tr( "Description of this provider" ) + "</p>\n";
myMetadata += "<p>";
myMetadata += dataProvider()->description().replace( "\n", "<br>" );
myMetadata += "</p>\n";
}

// data source
myMetadata += "<p class=\"glossy\">" + tr( "Source for this layer" ) + "</p>\n";
myMetadata += "<p>";
@@ -26,18 +26,12 @@
#include <QTextStream>

QgsDelimitedTextFeatureIterator::QgsDelimitedTextFeatureIterator( QgsDelimitedTextProvider* p, const QgsFeatureRequest& request )
: QgsAbstractFeatureIterator( request ), P( p )
: QgsAbstractFeatureIterator( request )
, P( p )
{
// make sure that only one iterator is active
if ( P->mActiveIterator )
{
QgsMessageLog::logMessage( QObject::tr( "Already active iterator on this provider was closed." ), QObject::tr( "Delimited text" ) );
P->mActiveIterator->close();
}
P->mActiveIterator = this;
P->mActiveIterators << this;

// Determine mode to use based on request...

QgsDebugMsg( "Setting up QgsDelimitedTextIterator" );

// Does the layer have geometry - will revise later to determine if we actually need to
@@ -212,8 +206,8 @@ bool QgsDelimitedTextFeatureIterator::close()
if ( mClosed )
return false;

// tell provider that this iterator is not active anymore
P->mActiveIterator = 0;
P->mActiveIterators.remove( this );

mFeatureIds = QList<QgsFeatureId>();
mClosed = true;
return true;
@@ -82,9 +82,7 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri )
, mGeometryType( QGis::UnknownGeometry )
, mBuildSpatialIndex( false )
, mSpatialIndex( 0 )
, mActiveIterator( 0 )
{

QgsDebugMsg( "Delimited text file uri is " + uri );

QUrl url = QUrl::fromEncoded( uri.toAscii() );
@@ -169,8 +167,12 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri )

QgsDelimitedTextProvider::~QgsDelimitedTextProvider()
{
if ( mActiveIterator )
mActiveIterator->close();
while ( !mActiveIterators.empty() )
{
QgsDelimitedTextFeatureIterator *it = *mActiveIterators.begin();
QgsDebugMsg( "closing active iterator" );
it->close();
}

if ( mFile )
{
@@ -1052,7 +1054,13 @@ void QgsDelimitedTextProvider::onFileUpdated()
messages.append( tr( "The file has been updated by another application - reloading" ) );
reportErrors( messages, false );

if ( mActiveIterator ) mActiveIterator->close();
while ( !mActiveIterators.empty() )
{
QgsDelimitedTextFeatureIterator *it = *mActiveIterators.begin();
QgsDebugMsg( "closing active iterator" );
it->close();
}

rescanFile();
}

@@ -318,7 +318,7 @@ class QgsDelimitedTextProvider : public QgsVectorDataProvider
QgsSpatialIndex *mSpatialIndex;

friend class QgsDelimitedTextFeatureIterator;
QgsDelimitedTextFeatureIterator* mActiveIterator;
QSet< QgsDelimitedTextFeatureIterator* > mActiveIterators;
};

#endif
@@ -26,16 +26,10 @@


QgsGPXFeatureIterator::QgsGPXFeatureIterator( QgsGPXProvider* p, const QgsFeatureRequest& request )
: QgsAbstractFeatureIterator( request ), P( p )
: QgsAbstractFeatureIterator( request )
, P( p )
{
// make sure that only one iterator is active
if ( P->mActiveIterator )
{
QgsMessageLog::logMessage( QObject::tr( "Already active iterator on this provider was closed." ), QObject::tr( "GPX" ) );
P->mActiveIterator->close();
}
P->mActiveIterator = this;

P->mActiveIterators << this;
rewind();
}

@@ -71,19 +65,12 @@ bool QgsGPXFeatureIterator::close()
if ( mClosed )
return false;

// nothing to do

// tell provider that this iterator is not active anymore
P->mActiveIterator = 0;
P->mActiveIterators.remove( this );

mClosed = true;
return true;
}





bool QgsGPXFeatureIterator::nextFeature( QgsFeature& feature )
{
feature.setValid( false );
@@ -98,7 +85,6 @@ bool QgsGPXFeatureIterator::nextFeature( QgsFeature& feature )
return res;
}


if ( P->mFeatureType == QgsGPXProvider::WaypointType )
{
// go through the list of waypoints and return the first one that is in
@@ -63,7 +63,6 @@ class QgsGPXFeatureIterator : public QgsAbstractFeatureIterator
//! Current track iterator
QgsGPSData::TrackIterator mTrkIter;


bool mFetchedFid;
};

@@ -67,9 +67,8 @@ const QString GPX_KEY = "gpx";
const QString GPX_DESCRIPTION = QObject::tr( "GPS eXchange format provider" );


QgsGPXProvider::QgsGPXProvider( QString uri ) :
QgsVectorDataProvider( uri )
, mActiveIterator( 0 )
QgsGPXProvider::QgsGPXProvider( QString uri )
: QgsVectorDataProvider( uri )
{
// assume that it won't work
mValid = false;
@@ -114,8 +113,12 @@ QgsGPXProvider::QgsGPXProvider( QString uri ) :

QgsGPXProvider::~QgsGPXProvider()
{
if ( mActiveIterator )
mActiveIterator->close();
while ( !mActiveIterators.empty() )
{
QgsGPXFeatureIterator *it = *mActiveIterators.begin();
QgsDebugMsg( "closing active iterator" );
it->close();
}

QgsGPSData::releaseData( mFileName );
}
@@ -173,5 +173,5 @@ class QgsGPXProvider : public QgsVectorDataProvider
wkbPoint mWKBpt;

friend class QgsGPXFeatureIterator;
QgsGPXFeatureIterator* mActiveIterator;
QSet< QgsGPXFeatureIterator * > mActiveIterators;
};
@@ -39,13 +39,7 @@ extern "C"
QgsGrassFeatureIterator::QgsGrassFeatureIterator( QgsGrassProvider* p, const QgsFeatureRequest& request )
: QgsAbstractFeatureIterator( request ), P( p )
{
// make sure that only one iterator is active
if ( P->mActiveIterator )
{
QgsMessageLog::logMessage( QObject::tr( "Already active iterator on this provider was closed." ), QObject::tr( "GRASS" ) );
P->mActiveIterator->close();
}
P->mActiveIterator = this;
P->mActiveIterators << this;

// check if outdated and update if necessary
P->ensureUpdated();
@@ -242,16 +236,15 @@ bool QgsGrassFeatureIterator::close()
if ( mClosed )
return false;

P->mActiveIterators.remove( this );

// finalization
Vect_destroy_line_struct( mPoints );
Vect_destroy_cats_struct( mCats );
Vect_destroy_list( mList );

free( mSelection );

// tell provider that this iterator is not active anymore
P->mActiveIterator = 0;

mClosed = true;
return true;
}
@@ -73,7 +73,6 @@ static QString GRASS_DESCRIPTION = "Grass provider"; // XXX verify this

QgsGrassProvider::QgsGrassProvider( QString uri )
: QgsVectorDataProvider( uri )
, mActiveIterator( 0 )
{
QgsDebugMsg( QString( "QgsGrassProvider URI: %1" ).arg( uri ) );

@@ -258,8 +257,12 @@ QgsGrassProvider::~QgsGrassProvider()
{
QgsDebugMsg( "entered." );

if ( mActiveIterator )
mActiveIterator->close();
while ( !mActiveIterators.empty() )
{
QgsGrassFeatureIterator *it = *mActiveIterators.begin();
QgsDebugMsg( "closing active iterator" );
it->close();
}

closeLayer( mLayerId );
}
@@ -644,7 +644,7 @@ class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider
static std::vector<GMAP> mMaps; // Map

friend class QgsGrassFeatureIterator;
QgsGrassFeatureIterator* mActiveIterator;
QSet< QgsGrassFeatureIterator *> mActiveIterators;
};

#endif // QGSGRASSPROVIDER_H
@@ -22,15 +22,11 @@


QgsMemoryFeatureIterator::QgsMemoryFeatureIterator( QgsMemoryProvider* p, const QgsFeatureRequest& request )
: QgsAbstractFeatureIterator( request ), P( p ), mSelectRectGeom( NULL )
: QgsAbstractFeatureIterator( request )
, P( p )
, mSelectRectGeom( 0 )
{
// make sure that only one iterator is active
if ( P->mActiveIterator )
{
QgsMessageLog::logMessage( QObject::tr( "Already active iterator on this provider was closed." ), QObject::tr( "Memory provider" ) );
P->mActiveIterator->close();
}
P->mActiveIterator = this;
P->mActiveIterators << this;

if ( mRequest.filterType() == QgsFeatureRequest::FilterRect && mRequest.flags() & QgsFeatureRequest::ExactIntersect )
{
@@ -181,12 +177,11 @@ bool QgsMemoryFeatureIterator::close()
if ( mClosed )
return false;

P->mActiveIterators.remove( this );

delete mSelectRectGeom;
mSelectRectGeom = NULL;

// tell provider that this iterator is not active anymore
P->mActiveIterator = 0;

mClosed = true;
return true;
}
@@ -32,8 +32,7 @@ static const QString TEXT_PROVIDER_DESCRIPTION = "Memory provider";

QgsMemoryProvider::QgsMemoryProvider( QString uri )
: QgsVectorDataProvider( uri )
, mSpatialIndex( NULL )
, mActiveIterator( 0 )
, mSpatialIndex( 0 )
{
// Initialize the geometry with the uri to support old style uri's
// (ie, just 'point', 'line', 'polygon')
@@ -139,8 +138,12 @@ QgsMemoryProvider::QgsMemoryProvider( QString uri )

QgsMemoryProvider::~QgsMemoryProvider()
{
if ( mActiveIterator )
mActiveIterator->close();
while ( !mActiveIterators.empty() )
{
QgsMemoryFeatureIterator *it = *mActiveIterators.begin();
QgsDebugMsg( "closing active iterator" );
it->close();
}

delete mSpatialIndex;
}
@@ -169,5 +169,5 @@ class QgsMemoryProvider : public QgsVectorDataProvider
QgsSpatialIndex* mSpatialIndex;

friend class QgsMemoryFeatureIterator;
QgsMemoryFeatureIterator* mActiveIterator;
QSet< QgsMemoryFeatureIterator *> mActiveIterators;
};

0 comments on commit 3747c2b

Please sign in to comment.
You can’t perform that action at this time.