mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-07 00:15:48 -04:00
More use of implicit sharing of QgsExpression
This commit is contained in:
parent
efaae1f609
commit
b9f0c0625a
@ -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 @@ class TestQgsVectorLayer(TestCase):
|
||||
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user