Skip to content

Commit

Permalink
Make sure that relevant fields are set always when necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Nov 7, 2011
1 parent 625ff11 commit 8e2e654
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -556,6 +556,10 @@ void QgsOgrProvider::setRelevantFields( bool fetchGeometry, const QgsAttributeLi

OGR_L_SetIgnoredFields( ogrLayer, ignoredFields.data() );
}

// mark that relevant fields may not be set appropriately for nextFeature() calls
mRelevantFieldsForNextFeature = false;

#else
Q_UNUSED( fetchGeometry );
Q_UNUSED( fetchAttributes );
Expand Down Expand Up @@ -623,6 +627,14 @@ bool QgsOgrProvider::nextFeature( QgsFeature& feature )
return false;
}

if ( !mRelevantFieldsForNextFeature )
{
// setting relevant fields has some overhead so set it only when necessary
setRelevantFields( mFetchGeom || mUseIntersect || !mFetchRect.isEmpty(),
mAttributesToFetch );
mRelevantFieldsForNextFeature = true;
}

OGRFeatureH fet;
QgsRectangle selectionRect;

Expand Down Expand Up @@ -726,6 +738,7 @@ void QgsOgrProvider::select( QgsAttributeList fetchAttributes, QgsRectangle rect

setRelevantFields( mFetchGeom || mUseIntersect || !mFetchRect.isEmpty(),
mAttributesToFetch );
mRelevantFieldsForNextFeature = true;

// spatial query to select features
if ( rect.isEmpty() )
Expand Down
7 changes: 7 additions & 0 deletions src/providers/ogr/qgsogrprovider.h
Expand Up @@ -334,6 +334,13 @@ class QgsOgrProvider : public QgsVectorDataProvider
int geomType;
long featuresCounted;

/** Flag whether OGR will return fields required by nextFeature() calls.
The relevant fields are first set in select(), however the setting may be
interferred by some other calls. This flag ensures they are set again
to correct values.
*/
bool mRelevantFieldsForNextFeature;

//! Selection rectangle
OGRGeometryH mSelectionRectangle;
/**Adds one feature*/
Expand Down

0 comments on commit 8e2e654

Please sign in to comment.