Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
vector providers: allow multiple iterators - testing required
  • Loading branch information
jef-n committed Jun 21, 2013
1 parent 4164d6e commit 3747c2b
Show file tree
Hide file tree
Showing 31 changed files with 177 additions and 179 deletions.
7 changes: 4 additions & 3 deletions src/core/qgsfeatureiterator.cpp
Expand Up @@ -16,9 +16,9 @@


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

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

void QgsAbstractFeatureIterator::deref()
{
refs--;
Expand Down
3 changes: 1 addition & 2 deletions src/core/qgsfeatureiterator.h
Expand Up @@ -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
9 changes: 9 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -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>";
Expand Down
16 changes: 5 additions & 11 deletions src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 13 additions & 5 deletions src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Expand Up @@ -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() );
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/delimitedtext/qgsdelimitedtextprovider.h
Expand Up @@ -318,7 +318,7 @@ class QgsDelimitedTextProvider : public QgsVectorDataProvider
QgsSpatialIndex *mSpatialIndex;

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

#endif
22 changes: 4 additions & 18 deletions src/providers/gpx/qgsgpxfeatureiterator.cpp
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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 );
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/providers/gpx/qgsgpxfeatureiterator.h
Expand Up @@ -63,7 +63,6 @@ class QgsGPXFeatureIterator : public QgsAbstractFeatureIterator
//! Current track iterator
QgsGPSData::TrackIterator mTrkIter;


bool mFetchedFid;
};

Expand Down
13 changes: 8 additions & 5 deletions src/providers/gpx/qgsgpxprovider.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/gpx/qgsgpxprovider.h
Expand Up @@ -173,5 +173,5 @@ class QgsGPXProvider : public QgsVectorDataProvider
wkbPoint mWKBpt;

friend class QgsGPXFeatureIterator;
QgsGPXFeatureIterator* mActiveIterator;
QSet< QgsGPXFeatureIterator * > mActiveIterators;
};
13 changes: 3 additions & 10 deletions src/providers/grass/qgsgrassfeatureiterator.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 6 additions & 3 deletions src/providers/grass/qgsgrassprovider.cpp
Expand Up @@ -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 ) );

Expand Down Expand Up @@ -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 );
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrassprovider.h
Expand Up @@ -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
17 changes: 6 additions & 11 deletions src/providers/memory/qgsmemoryfeatureiterator.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
}
11 changes: 7 additions & 4 deletions src/providers/memory/qgsmemoryprovider.cpp
Expand Up @@ -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')
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/memory/qgsmemoryprovider.h
Expand Up @@ -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.