Skip to content
Permalink
Browse files
Fixed closing of feature iterators
  • Loading branch information
wonder-sk committed Jan 7, 2013
1 parent 353e7ab commit de3f07ee3ce409427da4aab80dfafe2a3f19c725
@@ -180,6 +180,9 @@ QgsVectorLayer::~QgsVectorLayer()
{
QgsDebugMsg( "entered." );

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

emit layerDeleted();

mValid = false;
@@ -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 );
@@ -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 )
@@ -108,7 +108,6 @@ bool QgsVectorLayerFeatureIterator::nextFeature( QgsFeature& f )
return true;
}

mClosed = true;
return false;
}

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

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

mClosed = true;
return true;
@@ -62,6 +62,9 @@ bool QgsGPXFeatureIterator::nextFeature( QgsFeature& feature )
{
feature.setValid( false );

if ( mClosed )
return false;

if ( mRequest.filterType() == QgsFeatureRequest::FilterFid )
{
return readFid( feature );
@@ -209,6 +209,7 @@ bool QgsGrassFeatureIterator::close()

free( mSelection );

mClosed = true;
return true;
}

@@ -47,6 +47,9 @@ bool QgsMemoryFeatureIterator::nextFeature( QgsFeature& feature )
{
feature.setValid( false );

if ( mClosed )
return false;

if ( mUsingFeatureIdList )
return nextFeatureUsingList( feature );
else
@@ -106,6 +106,8 @@ bool QgsSpatiaLiteFeatureIterator::close()
sqlite3_finalize( sqliteStatement );
sqliteStatement = NULL;
}

mClosed = true;
return true;
}

0 comments on commit de3f07e

Please sign in to comment.