Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed closing of feature iterators
  • Loading branch information
wonder-sk committed Jan 7, 2013
1 parent 353e7ab commit de3f07e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 78 deletions.
81 changes: 6 additions & 75 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -180,6 +180,9 @@ QgsVectorLayer::~QgsVectorLayer()
{
QgsDebugMsg( "entered." );

if (!mLayerIterator.isClosed())
mLayerIterator.close();

emit layerDeleted();

mValid = false;
Expand Down Expand Up @@ -1662,64 +1665,6 @@ void QgsVectorLayer::addJoinedAttributes( QgsFeature& f, bool all )

void QgsVectorLayer::select( QgsAttributeList attributes, QgsRectangle rect, bool fetchGeometries, bool useIntersect )
{
#if 0
if ( !mDataProvider )
return;

mFetching = true;
mFetchRect = rect;
mFetchAttributes = attributes;
mFetchGeometry = fetchGeometries;
mFetchConsidered = mEditBuffer ? mEditBuffer->mDeletedFeatureIds : QSet<QgsFeatureId>();
QgsAttributeList targetJoinFieldList;

if ( mEditBuffer )
{
mFetchAddedFeaturesIt = mEditBuffer->mAddedFeatures.begin();
mFetchChangedGeomIt = mEditBuffer->mChangedGeometries.begin();
}

//look in the normal features of the provider
if ( mFetchAttributes.size() > 0 )
{
if ( mEditBuffer || mJoinBuffer->containsJoins() )
{
QgsAttributeList joinFields;

mJoinBuffer->select( mFetchAttributes, joinFields, mUpdatedFields );
QgsAttributeList::const_iterator joinFieldIt = joinFields.constBegin();
for ( ; joinFieldIt != joinFields.constEnd(); ++joinFieldIt )
{
if ( !mFetchAttributes.contains( *joinFieldIt ) )
{
mFetchAttributes.append( *joinFieldIt );
}
}

//detect which fields are from the provider
mFetchProvAttributes.clear();
const QgsFields& provFields = mDataProvider->fields();
for ( QgsAttributeList::iterator it = mFetchAttributes.begin(); it != mFetchAttributes.end(); it++ )
{
if ( *it < provFields.count() )
{
mFetchProvAttributes << *it;
}
}

mProviderIterator = mDataProvider->select( mFetchProvAttributes, rect, fetchGeometries, useIntersect );
}
else
{
mProviderIterator = mDataProvider->select( mFetchAttributes, rect, fetchGeometries, useIntersect );
}
}
else //we don't need any attributes at all
{
mProviderIterator = mDataProvider->select( QgsAttributeList(), rect, fetchGeometries, useIntersect );
}
#endif

QgsFeatureRequest request;
if ( !rect.isEmpty() )
request.setFilterRect( rect );
Expand All @@ -1730,27 +1675,13 @@ void QgsVectorLayer::select( QgsAttributeList attributes, QgsRectangle rect, boo
if ( attributes != pendingAllAttributesList() )
request.setSubsetOfAttributes( attributes );

if (!mLayerIterator.isClosed())
mLayerIterator.close();

mLayerIterator = getFeatures( request );
}


#if 0
void QgsVectorLayer::select( const QgsFeatureRequest& request )
{
mLayerIterator = getFeatures( request );

/*
QgsAttributeList attrs;
if ( !( request.flags() & QgsFeatureRequest::SubsetOfAttributes ) )
attrs = request.subsetOfAttributes();
else
attrs = pendingAllAttributesList();
bool fetchGeom = !( request.flags() & QgsFeatureRequest::NoGeometry );
bool exactIntersect = ( request.flags() & QgsFeatureRequest::ExactIntersect );
select( attrs, request.filterRect(), fetchGeom, exactIntersect );
*/
}
#endif


QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest& request )
Expand Down
4 changes: 1 addition & 3 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Expand Up @@ -108,7 +108,6 @@ bool QgsVectorLayerFeatureIterator::nextFeature( QgsFeature& f )
return true;
}

mClosed = true;
return false;
}

Expand Down Expand Up @@ -137,8 +136,7 @@ bool QgsVectorLayerFeatureIterator::close()
if ( mClosed )
return false;

if ( mRequest.filterType() != QgsFeatureRequest::FilterFid )
mProviderIterator.close();
mProviderIterator.close();

mClosed = true;
return true;
Expand Down
3 changes: 3 additions & 0 deletions src/providers/gpx/qgsgpxfeatureiterator.cpp
Expand Up @@ -62,6 +62,9 @@ bool QgsGPXFeatureIterator::nextFeature( QgsFeature& feature )
{
feature.setValid( false );

if ( mClosed )
return false;

if ( mRequest.filterType() == QgsFeatureRequest::FilterFid )
{
return readFid( feature );
Expand Down
1 change: 1 addition & 0 deletions src/providers/grass/qgsgrassfeatureiterator.cpp
Expand Up @@ -209,6 +209,7 @@ bool QgsGrassFeatureIterator::close()

free( mSelection );

mClosed = true;
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/providers/memory/qgsmemoryfeatureiterator.cpp
Expand Up @@ -47,6 +47,9 @@ bool QgsMemoryFeatureIterator::nextFeature( QgsFeature& feature )
{
feature.setValid( false );

if ( mClosed )
return false;

if ( mUsingFeatureIdList )
return nextFeatureUsingList( feature );
else
Expand Down
2 changes: 2 additions & 0 deletions src/providers/spatialite/qgsspatialitefeatureiterator.cpp
Expand Up @@ -106,6 +106,8 @@ bool QgsSpatiaLiteFeatureIterator::close()
sqlite3_finalize( sqliteStatement );
sqliteStatement = NULL;
}

mClosed = true;
return true;
}

Expand Down

0 comments on commit de3f07e

Please sign in to comment.