Skip to content
Permalink
Browse files

More use of implicit sharing of QgsExpression

  • Loading branch information
m-kuhn committed Dec 18, 2015
1 parent efaae1f commit b9f0c0625ad013428e482de82f35370bd46e2453
@@ -36,6 +36,7 @@ void QgsExpressionFieldBuffer::removeExpression( int index )
void QgsExpressionFieldBuffer::updateExpression( int index, const QString& exp )
{
mExpressions[index].expression = exp;
mExpressions[index].cachedExpression = QgsExpression( exp );
}

void QgsExpressionFieldBuffer::writeXml( QDomNode& layerNode, QDomDocument& document ) const
@@ -23,6 +23,7 @@
#include <QDomNode>

#include "qgsfield.h"
#include "qgsexpression.h"

/**
* Buffers information about expression fields for a vector layer.
@@ -34,10 +35,14 @@ class CORE_EXPORT QgsExpressionFieldBuffer
public:
typedef struct ExpressionField
{
ExpressionField() {}
ExpressionField( const QString& exp, const QgsField& fld ) : expression( exp ), field( fld ) {}
ExpressionField() : cachedExpression( expression ) {}
ExpressionField( const QString& exp, const QgsField& fld ) : expression( exp ), cachedExpression( exp ), field( fld ) {}

/**
* @deprecated use cachedExpression instead
*/
QString expression;
QgsExpression cachedExpression;
QgsField field;
} ExpressionField;

@@ -530,7 +530,7 @@ void QgsVectorLayerFeatureIterator::prepareExpressions()
|| mRequest.subsetOfAttributes().contains( i ) )
{
int oi = mSource->mFields.fieldOriginIndex( i );
QgsExpression* exp = new QgsExpression( exps[oi].expression );
QgsExpression* exp = new QgsExpression( exps[oi].cachedExpression );
exp->prepare( mExpressionContext.data() );
mExpressionFieldInfo.insert( i, exp );

@@ -965,16 +965,16 @@ def test_ExpressionField(self):

idx = layer.addExpressionField('5', QgsField('test', QVariant.LongLong))

assert(layer.getFeatures().next()[idx] == 5)
assert(layer.pendingFields().count() == cnt + 1)
self.assertEquals(layer.getFeatures().next()[idx], 5)
self.assertEquals(layer.pendingFields().count(), cnt + 1)

layer.updateExpressionField(idx, '9')

assert(layer.getFeatures().next()[idx] == 9)
self.assertEquals(layer.getFeatures().next()[idx], 9)

layer.removeExpressionField(idx)

assert(layer.pendingFields().count() == cnt)
self.assertEquals(layer.pendingFields().count(), cnt)

def test_ExpressionFilter(self):
layer = createLayerWithOnePoint()

0 comments on commit b9f0c06

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