Skip to content
Permalink
Browse files

Support for setSubsetString() in memory provider

  • Loading branch information
wonder-sk committed Sep 12, 2014
1 parent b44ef92 commit 02a9bc89286a6ae5bab357d2972556425abf350b
@@ -25,7 +25,13 @@
QgsMemoryFeatureIterator::QgsMemoryFeatureIterator( QgsMemoryFeatureSource* source, bool ownSource, const QgsFeatureRequest& request )
: QgsAbstractFeatureIteratorFromSource( source, ownSource, request )
, mSelectRectGeom( 0 )
, mSubsetExpression( 0 )
{
if ( !mSource->mSubsetString.isEmpty() )
{
mSubsetExpression = new QgsExpression( mSource->mSubsetString );
mSubsetExpression->prepare( mSource->mFields );
}

if ( mRequest.filterType() == QgsFeatureRequest::FilterRect && mRequest.flags() & QgsFeatureRequest::ExactIntersect )
{
@@ -58,6 +64,8 @@ QgsMemoryFeatureIterator::QgsMemoryFeatureIterator( QgsMemoryFeatureSource* sour
QgsMemoryFeatureIterator::~QgsMemoryFeatureIterator()
{
close();

delete mSubsetExpression;
}


@@ -91,6 +99,9 @@ bool QgsMemoryFeatureIterator::nextFeatureUsingList( QgsFeature& feature )
else
hasFeature = true;

if ( mSubsetExpression && !mSubsetExpression->evaluate( mSource->mFeatures[*mFeatureIdListIterator] ).toBool() )
hasFeature = false;

if ( hasFeature )
break;

@@ -141,6 +152,9 @@ bool QgsMemoryFeatureIterator::nextFeatureTraverseAll( QgsFeature& feature )
}
}

if ( mSubsetExpression && !mSubsetExpression->evaluate( *mSelectIterator ).toBool() )
hasFeature = false;

if ( hasFeature )
break;

@@ -194,6 +208,7 @@ QgsMemoryFeatureSource::QgsMemoryFeatureSource( const QgsMemoryProvider* p )
: mFields( p->mFields )
, mFeatures( p->mFeatures )
, mSpatialIndex( p->mSpatialIndex ? new QgsSpatialIndex( *p->mSpatialIndex ) : 0 ) // just shallow copy
, mSubsetString( p->mSubsetString )
{
}

@@ -36,6 +36,7 @@ class QgsMemoryFeatureSource : public QgsAbstractFeatureSource
QgsFields mFields;
QgsFeatureMap mFeatures;
QgsSpatialIndex* mSpatialIndex;
QString mSubsetString;

friend class QgsMemoryFeatureIterator;
};
@@ -67,6 +68,7 @@ class QgsMemoryFeatureIterator : public QgsAbstractFeatureIteratorFromSource<Qgs
bool mUsingFeatureIdList;
QList<QgsFeatureId> mFeatureIdList;
QList<QgsFeatureId>::const_iterator mFeatureIdListIterator;
QgsExpression* mSubsetExpression;

};

@@ -420,6 +420,26 @@ bool QgsMemoryProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
return true;
}

QString QgsMemoryProvider::subsetString()
{
return mSubsetString;
}

bool QgsMemoryProvider::setSubsetString( QString theSQL, bool updateFeatureCount )
{
Q_UNUSED( updateFeatureCount );

if ( !theSQL.isEmpty() )
{
QgsExpression tempExpression( theSQL );
if ( tempExpression.hasParserError() )
return false;
}

mSubsetString = theSQL;
return true;
}

bool QgsMemoryProvider::createSpatialIndex()
{
if ( !mSpatialIndex )
@@ -111,6 +111,14 @@ class QgsMemoryProvider : public QgsVectorDataProvider
*/
virtual bool changeGeometryValues( QgsGeometryMap & geometry_map );

/** Accessor for sql where clause used to limit dataset */
QString subsetString();

/** mutator for sql where clause used to limit dataset size */
bool setSubsetString( QString theSQL, bool updateFeatureCount = true );

virtual bool supportsSubsetString() { return true; }

/**
* Creates a spatial index
* @return true in case of success
@@ -170,5 +178,7 @@ class QgsMemoryProvider : public QgsVectorDataProvider
// indexing
QgsSpatialIndex* mSpatialIndex;

QString mSubsetString;

friend class QgsMemoryFeatureSource;
};

0 comments on commit 02a9bc8

Please sign in to comment.
You can’t perform that action at this time.