Skip to content

Commit de3f07e

Browse files
committedJan 7, 2013
Fixed closing of feature iterators
1 parent 353e7ab commit de3f07e

File tree

6 files changed

+16
-78
lines changed

6 files changed

+16
-78
lines changed
 

‎src/core/qgsvectorlayer.cpp

Lines changed: 6 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ QgsVectorLayer::~QgsVectorLayer()
180180
{
181181
QgsDebugMsg( "entered." );
182182

183+
if (!mLayerIterator.isClosed())
184+
mLayerIterator.close();
185+
183186
emit layerDeleted();
184187

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

16631666
void QgsVectorLayer::select( QgsAttributeList attributes, QgsRectangle rect, bool fetchGeometries, bool useIntersect )
16641667
{
1665-
#if 0
1666-
if ( !mDataProvider )
1667-
return;
1668-
1669-
mFetching = true;
1670-
mFetchRect = rect;
1671-
mFetchAttributes = attributes;
1672-
mFetchGeometry = fetchGeometries;
1673-
mFetchConsidered = mEditBuffer ? mEditBuffer->mDeletedFeatureIds : QSet<QgsFeatureId>();
1674-
QgsAttributeList targetJoinFieldList;
1675-
1676-
if ( mEditBuffer )
1677-
{
1678-
mFetchAddedFeaturesIt = mEditBuffer->mAddedFeatures.begin();
1679-
mFetchChangedGeomIt = mEditBuffer->mChangedGeometries.begin();
1680-
}
1681-
1682-
//look in the normal features of the provider
1683-
if ( mFetchAttributes.size() > 0 )
1684-
{
1685-
if ( mEditBuffer || mJoinBuffer->containsJoins() )
1686-
{
1687-
QgsAttributeList joinFields;
1688-
1689-
mJoinBuffer->select( mFetchAttributes, joinFields, mUpdatedFields );
1690-
QgsAttributeList::const_iterator joinFieldIt = joinFields.constBegin();
1691-
for ( ; joinFieldIt != joinFields.constEnd(); ++joinFieldIt )
1692-
{
1693-
if ( !mFetchAttributes.contains( *joinFieldIt ) )
1694-
{
1695-
mFetchAttributes.append( *joinFieldIt );
1696-
}
1697-
}
1698-
1699-
//detect which fields are from the provider
1700-
mFetchProvAttributes.clear();
1701-
const QgsFields& provFields = mDataProvider->fields();
1702-
for ( QgsAttributeList::iterator it = mFetchAttributes.begin(); it != mFetchAttributes.end(); it++ )
1703-
{
1704-
if ( *it < provFields.count() )
1705-
{
1706-
mFetchProvAttributes << *it;
1707-
}
1708-
}
1709-
1710-
mProviderIterator = mDataProvider->select( mFetchProvAttributes, rect, fetchGeometries, useIntersect );
1711-
}
1712-
else
1713-
{
1714-
mProviderIterator = mDataProvider->select( mFetchAttributes, rect, fetchGeometries, useIntersect );
1715-
}
1716-
}
1717-
else //we don't need any attributes at all
1718-
{
1719-
mProviderIterator = mDataProvider->select( QgsAttributeList(), rect, fetchGeometries, useIntersect );
1720-
}
1721-
#endif
1722-
17231668
QgsFeatureRequest request;
17241669
if ( !rect.isEmpty() )
17251670
request.setFilterRect( rect );
@@ -1730,27 +1675,13 @@ void QgsVectorLayer::select( QgsAttributeList attributes, QgsRectangle rect, boo
17301675
if ( attributes != pendingAllAttributesList() )
17311676
request.setSubsetOfAttributes( attributes );
17321677

1678+
if (!mLayerIterator.isClosed())
1679+
mLayerIterator.close();
1680+
17331681
mLayerIterator = getFeatures( request );
17341682
}
17351683

17361684

1737-
#if 0
1738-
void QgsVectorLayer::select( const QgsFeatureRequest& request )
1739-
{
1740-
mLayerIterator = getFeatures( request );
1741-
1742-
/*
1743-
QgsAttributeList attrs;
1744-
if ( !( request.flags() & QgsFeatureRequest::SubsetOfAttributes ) )
1745-
attrs = request.subsetOfAttributes();
1746-
else
1747-
attrs = pendingAllAttributesList();
1748-
bool fetchGeom = !( request.flags() & QgsFeatureRequest::NoGeometry );
1749-
bool exactIntersect = ( request.flags() & QgsFeatureRequest::ExactIntersect );
1750-
select( attrs, request.filterRect(), fetchGeom, exactIntersect );
1751-
*/
1752-
}
1753-
#endif
17541685

17551686

17561687
QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest& request )

‎src/core/qgsvectorlayerfeatureiterator.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ bool QgsVectorLayerFeatureIterator::nextFeature( QgsFeature& f )
108108
return true;
109109
}
110110

111-
mClosed = true;
112111
return false;
113112
}
114113

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

140-
if ( mRequest.filterType() != QgsFeatureRequest::FilterFid )
141-
mProviderIterator.close();
139+
mProviderIterator.close();
142140

143141
mClosed = true;
144142
return true;

‎src/providers/gpx/qgsgpxfeatureiterator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ bool QgsGPXFeatureIterator::nextFeature( QgsFeature& feature )
6262
{
6363
feature.setValid( false );
6464

65+
if ( mClosed )
66+
return false;
67+
6568
if ( mRequest.filterType() == QgsFeatureRequest::FilterFid )
6669
{
6770
return readFid( feature );

‎src/providers/grass/qgsgrassfeatureiterator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ bool QgsGrassFeatureIterator::close()
209209

210210
free( mSelection );
211211

212+
mClosed = true;
212213
return true;
213214
}
214215

‎src/providers/memory/qgsmemoryfeatureiterator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ bool QgsMemoryFeatureIterator::nextFeature( QgsFeature& feature )
4747
{
4848
feature.setValid( false );
4949

50+
if ( mClosed )
51+
return false;
52+
5053
if ( mUsingFeatureIdList )
5154
return nextFeatureUsingList( feature );
5255
else

‎src/providers/spatialite/qgsspatialitefeatureiterator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ bool QgsSpatiaLiteFeatureIterator::close()
106106
sqlite3_finalize( sqliteStatement );
107107
sqliteStatement = NULL;
108108
}
109+
110+
mClosed = true;
109111
return true;
110112
}
111113

0 commit comments

Comments
 (0)
Please sign in to comment.