Skip to content
Permalink
Browse files

Port providers to expression contexts

  • Loading branch information
nyalldawson committed Aug 22, 2015
1 parent f108dcd commit a1e21f3994c5c75253c37ed04e326f6a99e7c250
@@ -345,7 +345,8 @@ bool QgsDelimitedTextFeatureIterator::nextFeatureInternal( QgsFeature& feature )

if ( mTestSubset )
{
QVariant isOk = mSource->mSubsetExpression->evaluate( &feature );
mSource->mExpressionContext.setFeature( feature );
QVariant isOk = mSource->mSubsetExpression->evaluate( &mSource->mExpressionContext );
if ( mSource->mSubsetExpression->hasEvalError() ) continue;
if ( ! isOk.toBool() ) continue;
}
@@ -490,6 +491,10 @@ QgsDelimitedTextFeatureSource::QgsDelimitedTextFeatureSource( const QgsDelimited
{
mFile = new QgsDelimitedTextFile();
mFile->setFromUrl( p->mFile->url() );

mExpressionContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
mExpressionContext.setFields( mFields );
}

QgsDelimitedTextFeatureSource::~QgsDelimitedTextFeatureSource()
@@ -18,6 +18,7 @@
#include <QList>
#include "qgsfeatureiterator.h"
#include "qgsfeature.h"
#include "qgsexpressioncontext.h"

#include "qgsdelimitedtextprovider.h"

@@ -32,6 +33,7 @@ class QgsDelimitedTextFeatureSource : public QgsAbstractFeatureSource
protected:
QgsDelimitedTextProvider::GeomRepresentationType mGeomRep;
QgsExpression *mSubsetExpression;
QgsExpressionContext mExpressionContext;
QgsRectangle mExtent;
bool mUseSpatialIndex;
QgsSpatialIndex *mSpatialIndex;
@@ -1006,7 +1006,8 @@ bool QgsDelimitedTextProvider::setSubsetString( QString subset, bool updateFeatu
}
else
{
expression->prepare( fields() );
QgsExpressionContext context = QgsExpressionContextUtils::createFeatureBasedContext( QgsFeature(), fields() );
expression->prepare( &context );
if ( expression->hasEvalError() )
{
error = expression->evalErrorString();
@@ -30,7 +30,7 @@ QgsMemoryFeatureIterator::QgsMemoryFeatureIterator( QgsMemoryFeatureSource* sour
if ( !mSource->mSubsetString.isEmpty() )
{
mSubsetExpression = new QgsExpression( mSource->mSubsetString );
mSubsetExpression->prepare( mSource->mFields );
mSubsetExpression->prepare( &mSource->mExpressionContext );
}

if ( !mRequest.filterRect().isNull() && mRequest.flags() & QgsFeatureRequest::ExactIntersect )
@@ -99,8 +99,12 @@ bool QgsMemoryFeatureIterator::nextFeatureUsingList( QgsFeature& feature )
else
hasFeature = true;

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

if ( hasFeature )
break;
@@ -152,8 +156,12 @@ bool QgsMemoryFeatureIterator::nextFeatureTraverseAll( QgsFeature& feature )
}
}

if ( mSubsetExpression && !mSubsetExpression->evaluate( *mSelectIterator ).toBool() )
hasFeature = false;
if ( mSubsetExpression )
{
mSource->mExpressionContext.setFeature( *mSelectIterator );
if ( !mSubsetExpression->evaluate( &mSource->mExpressionContext ).toBool() )
hasFeature = false;
}

if ( hasFeature )
break;
@@ -210,6 +218,9 @@ QgsMemoryFeatureSource::QgsMemoryFeatureSource( const QgsMemoryProvider* p )
, mSpatialIndex( p->mSpatialIndex ? new QgsSpatialIndex( *p->mSpatialIndex ) : 0 ) // just shallow copy
, mSubsetString( p->mSubsetString )
{
mExpressionContext << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
mExpressionContext.setFields( mFields );
}

QgsMemoryFeatureSource::~QgsMemoryFeatureSource()
@@ -16,6 +16,7 @@
#define QGSMEMORYFEATUREITERATOR_H

#include "qgsfeatureiterator.h"
#include "qgsexpressioncontext.h"

class QgsMemoryProvider;

@@ -37,6 +38,7 @@ class QgsMemoryFeatureSource : public QgsAbstractFeatureSource
QgsFeatureMap mFeatures;
QgsSpatialIndex* mSpatialIndex;
QString mSubsetString;
QgsExpressionContext mExpressionContext;

friend class QgsMemoryFeatureIterator;
};

0 comments on commit a1e21f3

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