Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
also set feature validity in featureAtId of memory and spatialite pro…
…vider

git-svn-id: http://svn.osgeo.org/qgis/trunk@13379 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 25, 2010
1 parent 51f815a commit 2480fce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
36 changes: 19 additions & 17 deletions src/providers/memory/qgsmemoryprovider.cpp
Expand Up @@ -69,7 +69,7 @@ QString QgsMemoryProvider::storageType() const
bool QgsMemoryProvider::nextFeature( QgsFeature& feature )
{
feature.setValid( false );
bool hasFeature = FALSE;
bool hasFeature = false;

// option 1: using spatial index
if ( mSelectUsingSpatialIndex )
Expand All @@ -80,10 +80,10 @@ bool QgsMemoryProvider::nextFeature( QgsFeature& feature )
if ( mSelectUseIntersect )
{
if ( mFeatures[*mSelectSI_Iterator].geometry()->intersects( mSelectRectGeom ) )
hasFeature = TRUE;
hasFeature = true;
}
else
hasFeature = TRUE;
hasFeature = true;

if ( hasFeature )
break;
Expand All @@ -106,21 +106,21 @@ bool QgsMemoryProvider::nextFeature( QgsFeature& feature )
if ( mSelectRect.isEmpty() )
{
// selection rect empty => using all features
hasFeature = TRUE;
hasFeature = true;
}
else
{
if ( mSelectUseIntersect )
{
// using exact test when checking for intersection
if ( mSelectIterator->geometry()->intersects( mSelectRectGeom ) )
hasFeature = TRUE;
hasFeature = true;
}
else
{
// check just bounding box against rect when not using intersection
if ( mSelectIterator->geometry()->boundingBox().intersects( mSelectRect ) )
hasFeature = TRUE;
hasFeature = true;
}
}

Expand All @@ -147,13 +147,15 @@ bool QgsMemoryProvider::featureAtId( int featureId,
bool fetchGeometry,
QgsAttributeList fetchAttributes )
{
feature.setValid( false );
QgsFeatureMap::iterator it = mFeatures.find( featureId );

if ( it == mFeatures.end() )
return FALSE;
return false;

feature = *it;
return TRUE;
feature.setValid( true );
return true;
}


Expand All @@ -173,13 +175,13 @@ void QgsMemoryProvider::select( QgsAttributeList fetchAttributes,
// (but don't use it when selection rect is not specified)
if ( mSpatialIndex && !mSelectRect.isEmpty() )
{
mSelectUsingSpatialIndex = TRUE;
mSelectUsingSpatialIndex = true;
mSelectSI_Features = mSpatialIndex->intersects( rect );
QgsDebugMsg( "Features returned by spatial index: " + QString::number( mSelectSI_Features.count() ) );
}
else
{
mSelectUsingSpatialIndex = FALSE;
mSelectUsingSpatialIndex = false;
mSelectSI_Features.clear();
}

Expand Down Expand Up @@ -252,7 +254,7 @@ bool QgsMemoryProvider::addFeatures( QgsFeatureList & flist )

updateExtent();

return TRUE;
return true;
}

bool QgsMemoryProvider::deleteFeatures( const QgsFeatureIds & id )
Expand All @@ -274,7 +276,7 @@ bool QgsMemoryProvider::deleteFeatures( const QgsFeatureIds & id )

updateExtent();

return TRUE;
return true;
}

bool QgsMemoryProvider::addAttributes( const QList<QgsField> &attributes )
Expand All @@ -298,14 +300,14 @@ bool QgsMemoryProvider::addAttributes( const QList<QgsField> &attributes )
if ( it2.key() > nextId ) nextId = it2.key();
mFields[nextId+1] = *it;
}
return TRUE;
return true;
}

bool QgsMemoryProvider::deleteAttributes( const QgsAttributeIds& attributes )
{
for ( QgsAttributeIds::const_iterator it = attributes.begin(); it != attributes.end(); ++it )
mFields.remove( *it );
return TRUE;
return true;
}

bool QgsMemoryProvider::changeAttributeValues( const QgsChangedAttributesMap & attr_map )
Expand All @@ -320,7 +322,7 @@ bool QgsMemoryProvider::changeAttributeValues( const QgsChangedAttributesMap & a
for ( QgsAttributeMap::const_iterator it2 = attrs.begin(); it2 != attrs.end(); ++it2 )
fit->changeAttribute( it2.key(), it2.value() );
}
return TRUE;
return true;
}

bool QgsMemoryProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
Expand All @@ -344,7 +346,7 @@ bool QgsMemoryProvider::changeGeometryValues( QgsGeometryMap & geometry_map )

updateExtent();

return TRUE;
return true;
}

bool QgsMemoryProvider::createSpatialIndex()
Expand All @@ -359,7 +361,7 @@ bool QgsMemoryProvider::createSpatialIndex()
mSpatialIndex->insertFeature( *it );
}
}
return TRUE;
return true;
}

int QgsMemoryProvider::capabilities() const
Expand Down
6 changes: 5 additions & 1 deletion src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -222,6 +222,8 @@ bool QgsSpatiaLiteProvider::featureAtId( int featureId, QgsFeature & feature, bo
{
sqlite3_stmt *stmt = NULL;

feature.setValid( false );

QString sql = "SELECT ROWID";
for ( QgsAttributeList::const_iterator it = fetchAttributes.constBegin(); it != fetchAttributes.constEnd(); ++it )
{
Expand Down Expand Up @@ -347,6 +349,8 @@ bool QgsSpatiaLiteProvider::featureAtId( int featureId, QgsFeature & feature, bo
}
sqlite3_finalize( stmt );

feature.setValid( true );

return true;
}

Expand Down Expand Up @@ -1433,7 +1437,7 @@ QgsSpatiaLiteProvider::SqliteHandles * QgsSpatiaLiteProvider::SqliteHandles::ope
}

// checking the DB for sanity
if ( checkMetadata( sqlite_handle ) == false )
if ( !checkMetadata( sqlite_handle ) )
{
// failure
QgsDebugMsg( QString( "Failure while connecting to: %1\n\ninvalid metadata tables" ).arg( dbPath ) );
Expand Down

0 comments on commit 2480fce

Please sign in to comment.