Skip to content

Commit

Permalink
Ensures that features (properly) fetched from provider (via nextFeature)
Browse files Browse the repository at this point in the history
are set as valid
Ensures that only valid features are rendered on the map canvas


git-svn-id: http://svn.osgeo.org/qgis/trunk@10272 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
cfarmer committed Mar 11, 2009
1 parent 8349cfd commit 539ee46
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,7 @@ void QgsVectorLayer::drawFeature( QPainter* p,
// used in all cases of the statement (otherwise they may get
// executed, but never used, in a bit of code where performance is
// critical).

if (! fet.isValid() ) { return; }
#if defined(Q_WS_X11)
bool needToTrim = false;
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/providers/gpx/qgsgpxprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ int QgsGPXProvider::capabilities() const

bool QgsGPXProvider::nextFeature( QgsFeature& feature )
{
feature.setValid( false );
bool result = false;

QgsAttributeList::const_iterator iter;
Expand Down Expand Up @@ -403,6 +404,10 @@ bool QgsGPXProvider::nextFeature( QgsFeature& feature )

}
}
if ( result )
{
feature.setValid( true );
}
return result;
}

Expand Down
3 changes: 3 additions & 0 deletions src/providers/grass/qgsgrassprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ QString QgsGrassProvider::storageType() const

bool QgsGrassProvider::nextFeature( QgsFeature& feature )
{
feature.setValid( false );
int cat, type, id;
unsigned char *wkb;
int wkbsize;
Expand Down Expand Up @@ -412,6 +413,8 @@ bool QgsGrassProvider::nextFeature( QgsFeature& feature )

setFeatureAttributes( mLayerId, cat, &feature, mAttributesToFetch );

feature.setValid( true );

return true;
}

Expand Down
4 changes: 3 additions & 1 deletion src/providers/memory/qgsmemoryprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ QString QgsMemoryProvider::storageType() const

bool QgsMemoryProvider::nextFeature( QgsFeature& feature )
{
feature.setValid( false );
bool hasFeature = FALSE;

// option 1: using spatial index
Expand Down Expand Up @@ -128,8 +129,9 @@ bool QgsMemoryProvider::nextFeature( QgsFeature& feature )
{
feature = mSelectIterator.value();
mSelectIterator++;
feature.setValid( true );
}

return hasFeature;
}

Expand Down
3 changes: 3 additions & 0 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ bool QgsOgrProvider::featureAtId( int featureId,

bool QgsOgrProvider::nextFeature( QgsFeature& feature )
{
feature.setValid( false );

if ( !valid )
{
QgsLogger::warning( "Read attempt on an invalid shapefile data source" );
Expand Down Expand Up @@ -410,6 +412,7 @@ bool QgsOgrProvider::nextFeature( QgsFeature& feature )
if ( fet )
{
OGR_F_Destroy( fet );
feature.setValid( true );
return true;
}
else
Expand Down
4 changes: 3 additions & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ void QgsPostgresProvider::select( QgsAttributeList fetchAttributes, QgsRectangle

bool QgsPostgresProvider::nextFeature( QgsFeature& feature )
{
feature.setValid( false );
QString cursorName = QString( "qgisf%1" ).arg( providerId );

if ( !valid )
Expand Down Expand Up @@ -621,7 +622,8 @@ bool QgsPostgresProvider::nextFeature( QgsFeature& feature )
feature.setAttributeMap( mFeatureQueue.front().attributeMap() );

mFeatureQueue.pop();


feature.setValid( true );
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions src/providers/wfs/qgswfsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ QgsWFSProvider::~QgsWFSProvider()

bool QgsWFSProvider::nextFeature( QgsFeature& feature )
{
feature.setValid( false );

while ( true ) //go through the loop until we find a feature in the filter
{
if ( mSelectedFeatures.size() == 0 || mFeatureIterator == mSelectedFeatures.end() )
Expand Down Expand Up @@ -92,6 +94,7 @@ bool QgsWFSProvider::nextFeature( QgsFeature& feature )
{
if ( feature.geometry() && feature.geometry()->intersects( mSpatialFilter ) )
{
feature.setValid( true );
return true;
}
else
Expand All @@ -101,6 +104,7 @@ bool QgsWFSProvider::nextFeature( QgsFeature& feature )
}
else
{
feature.setValid( true );
return true;
}
}
Expand Down

0 comments on commit 539ee46

Please sign in to comment.