Skip to content

Commit

Permalink
Use QgsExpressionContextScope::addVariable instead of setVariable
Browse files Browse the repository at this point in the history
...where appropriate (ie, read-only, non user set variables).
It's much faster as it doesn't need to check whether the
variable already exists.

Results in ~10% improvement in rendering speed. Refs #15752.
  • Loading branch information
nyalldawson committed Oct 26, 2016
1 parent 2d2ce00 commit 8589788
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/app/composer/qgsattributeselectiondialog.cpp
Expand Up @@ -105,7 +105,7 @@ QgsExpressionContext QgsComposerColumnSourceDelegate::createExpressionContext()
} }


QgsExpressionContext expContext = mComposerObject->createExpressionContext(); QgsExpressionContext expContext = mComposerObject->createExpressionContext();
expContext.lastScope()->setVariable( QStringLiteral( "row_number" ), 1 ); expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "row_number" ), 1, true ) );
expContext.setHighlightedVariables( QStringList() << QStringLiteral( "row_number" ) ); expContext.setHighlightedVariables( QStringList() << QStringLiteral( "row_number" ) );
return expContext; return expContext;
} }
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -59,7 +59,7 @@ QgsExpressionContext QgsAttributeTableDialog::createExpressionContext() const
if ( mLayer ) if ( mLayer )
expContext << QgsExpressionContextUtils::layerScope( mLayer ); expContext << QgsExpressionContextUtils::layerScope( mLayer );


expContext.lastScope()->setVariable( QStringLiteral( "row_number" ), 1 ); expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "row_number" ), 1, true ) );


expContext.setHighlightedVariables( QStringList() << QStringLiteral( "row_number" ) ); expContext.setHighlightedVariables( QStringList() << QStringLiteral( "row_number" ) );


Expand Down Expand Up @@ -471,7 +471,7 @@ void QgsAttributeTableDialog::runFieldCalculation( QgsVectorLayer* layer, const
} }


context.setFeature( feature ); context.setFeature( feature );
context.lastScope()->setVariable( QStringLiteral( "row_number" ), rownum ); context.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "row_number" ), rownum, true ) );


QVariant value = exp.evaluate( &context ); QVariant value = exp.evaluate( &context );
fld.convertCompatible( value ); fld.convertCompatible( value );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsfieldcalculator.cpp
Expand Up @@ -44,7 +44,7 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer* vl, QWidget* parent )
<< QgsExpressionContextUtils::projectScope() << QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::layerScope( mVectorLayer ); << QgsExpressionContextUtils::layerScope( mVectorLayer );


expContext.lastScope()->setVariable( QStringLiteral( "row_number" ), 1 ); expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "row_number" ), 1, true ) );
expContext.setHighlightedVariables( QStringList() << QStringLiteral( "row_number" ) ); expContext.setHighlightedVariables( QStringList() << QStringLiteral( "row_number" ) );


builder->setLayer( vl ); builder->setLayer( vl );
Expand Down Expand Up @@ -282,7 +282,7 @@ void QgsFieldCalculator::accept()
while ( fit.nextFeature( feature ) ) while ( fit.nextFeature( feature ) )
{ {
expContext.setFeature( feature ); expContext.setFeature( feature );
expContext.lastScope()->setVariable( QStringLiteral( "row_number" ), rownum ); expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "row_number" ), rownum, true ) );


QVariant value = exp.evaluate( &expContext ); QVariant value = exp.evaluate( &expContext );
if ( exp.hasEvalError() ) if ( exp.hasEvalError() )
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolfeatureaction.cpp
Expand Up @@ -143,8 +143,8 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
<< QgsExpressionContextUtils::projectScope() << QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::mapSettingsScope( mCanvas->mapSettings() ); << QgsExpressionContextUtils::mapSettingsScope( mCanvas->mapSettings() );
QgsExpressionContextScope* actionScope = new QgsExpressionContextScope(); QgsExpressionContextScope* actionScope = new QgsExpressionContextScope();
actionScope->setVariable( QStringLiteral( "click_x" ), point.x() ); actionScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "click_x" ), point.x(), true ) );
actionScope->setVariable( QStringLiteral( "click_y" ), point.y() ); actionScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "click_y" ), point.y(), true ) );
context << actionScope; context << actionScope;


int actionIdx = layer->actions()->defaultAction(); int actionIdx = layer->actions()->defaultAction();
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerattributetablev2.cpp
Expand Up @@ -508,7 +508,7 @@ bool QgsComposerAttributeTableV2::getTableContents( QgsComposerTableContents &co
{ {
// Lets assume it's an expression // Lets assume it's an expression
QgsExpression* expression = new QgsExpression(( *columnIt )->attribute() ); QgsExpression* expression = new QgsExpression(( *columnIt )->attribute() );
context.lastScope()->setVariable( QStringLiteral( "row_number" ), counter + 1 ); context.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "row_number" ), counter + 1, true ) );
expression->prepare( &context ); expression->prepare( &context );
QVariant value = expression->evaluate( &context ); QVariant value = expression->evaluate( &context );
currentRow << value; currentRow << value;
Expand Down
8 changes: 4 additions & 4 deletions src/core/composer/qgscomposermapgrid.cpp
Expand Up @@ -1475,8 +1475,8 @@ QString QgsComposerMapGrid::gridAnnotationString( double value, QgsComposerMapGr
} }
else if ( mGridAnnotationFormat == CustomFormat ) else if ( mGridAnnotationFormat == CustomFormat )
{ {
expressionContext.lastScope()->setVariable( QStringLiteral( "grid_number" ), value ); expressionContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "grid_number" ), value, true ) );
expressionContext.lastScope()->setVariable( QStringLiteral( "grid_axis" ), coord == QgsComposerMapGrid::Longitude ? "x" : "y" ); expressionContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "grid_axis" ), coord == QgsComposerMapGrid::Longitude ? "x" : "y", true ) );
if ( !mGridAnnotationExpression.data() ) if ( !mGridAnnotationExpression.data() )
{ {
mGridAnnotationExpression.reset( new QgsExpression( mGridAnnotationExpressionString ) ); mGridAnnotationExpression.reset( new QgsExpression( mGridAnnotationExpressionString ) );
Expand Down Expand Up @@ -2210,8 +2210,8 @@ QgsExpressionContext QgsComposerMapGrid::createExpressionContext() const
{ {
QgsExpressionContext context = QgsComposerObject::createExpressionContext(); QgsExpressionContext context = QgsComposerObject::createExpressionContext();
context.appendScope( new QgsExpressionContextScope( tr( "Grid" ) ) ); context.appendScope( new QgsExpressionContextScope( tr( "Grid" ) ) );
context.lastScope()->setVariable( QStringLiteral( "grid_number" ), 0 ); context.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "grid_number" ), 0, true ) );
context.lastScope()->setVariable( QStringLiteral( "grid_axis" ), "x" ); context.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "grid_axis" ), "x", true ) );
context.setHighlightedVariables( QStringList() << QStringLiteral( "grid_number" ) << QStringLiteral( "grid_axis" ) ); context.setHighlightedVariables( QStringList() << QStringLiteral( "grid_number" ) << QStringLiteral( "grid_axis" ) );
return context; return context;
} }
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsactionmanager.cpp
Expand Up @@ -67,7 +67,7 @@ void QgsActionManager::doAction( int index, const QgsFeature& feat, int defaultV
{ {
QgsExpressionContext context = createExpressionContext(); QgsExpressionContext context = createExpressionContext();
QgsExpressionContextScope* actionScope = new QgsExpressionContextScope(); QgsExpressionContextScope* actionScope = new QgsExpressionContextScope();
actionScope->setVariable( QStringLiteral( "current_field" ), feat.attribute( defaultValueIndex ) ); actionScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "current_field" ), feat.attribute( defaultValueIndex ), true ) );
context << actionScope; context << actionScope;
doAction( index, feat, context ); doAction( index, feat, context );
} }
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsconditionalstyle.cpp
Expand Up @@ -195,7 +195,7 @@ void QgsConditionalStyle::setSymbol( QgsSymbol* value )
bool QgsConditionalStyle::matches( const QVariant& value, QgsExpressionContext& context ) const bool QgsConditionalStyle::matches( const QVariant& value, QgsExpressionContext& context ) const
{ {
QgsExpression exp( mRule ); QgsExpression exp( mRule );
context.lastScope()->setVariable( QStringLiteral( "value" ), value ); context.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "value" ), value, true ) );
return exp.evaluate( &context ).toBool(); return exp.evaluate( &context ).toBool();
} }


Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsexpression.cpp
Expand Up @@ -1297,7 +1297,7 @@ static QVariant fcnFeature( const QVariantList&, const QgsExpressionContext* con
if ( !context ) if ( !context )
return QVariant(); return QVariant();


return context->variable( QgsExpressionContext::EXPR_FEATURE ); return context->feature();
} }
static QVariant fcnAttribute( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent ) static QVariant fcnAttribute( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
{ {
Expand Down Expand Up @@ -4963,9 +4963,9 @@ QVariant QgsExpression::NodeColumnRef::eval( QgsExpression *parent, const QgsExp
} }
} }


if ( context && context->hasVariable( QgsExpressionContext::EXPR_FEATURE ) ) if ( context && context->feature().isValid() )
{ {
QgsFeature feature = qvariant_cast<QgsFeature>( context->variable( QgsExpressionContext::EXPR_FEATURE ) ); QgsFeature feature = context->feature();
if ( index >= 0 ) if ( index >= 0 )
return feature.attribute( index ); return feature.attribute( index );
else else
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsexpressioncontext.cpp
Expand Up @@ -196,12 +196,12 @@ void QgsExpressionContextScope::addFunction( const QString& name, QgsScopedExpre


void QgsExpressionContextScope::setFeature( const QgsFeature &feature ) void QgsExpressionContextScope::setFeature( const QgsFeature &feature )
{ {
setVariable( QgsExpressionContext::EXPR_FEATURE, QVariant::fromValue( feature ) ); addVariable( StaticVariable( QgsExpressionContext::EXPR_FEATURE, QVariant::fromValue( feature ), true ) );
} }


void QgsExpressionContextScope::setFields( const QgsFields &fields ) void QgsExpressionContextScope::setFields( const QgsFields &fields )
{ {
setVariable( QgsExpressionContext::EXPR_FIELDS, QVariant::fromValue( fields ) ); addVariable( StaticVariable( QgsExpressionContext::EXPR_FIELDS, QVariant::fromValue( fields ), true ) );
} }




Expand Down
8 changes: 4 additions & 4 deletions src/core/symbology-ng/qgsarrowsymbollayer.cpp
Expand Up @@ -691,8 +691,8 @@ void QgsArrowSymbolLayer::renderPolyline( const QPolygonF& points, QgsSymbolRend
} }


context.renderContext().expressionContext().appendScope( mExpressionScope.data() ); context.renderContext().expressionContext().appendScope( mExpressionScope.data() );
mExpressionScope->setVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT, points.size() + 1 ); mExpressionScope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT, points.size() + 1, true ) );
mExpressionScope->setVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, 1 ); mExpressionScope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, 1, true ) );
if ( isCurved() ) if ( isCurved() )
{ {
_resolveDataDefined( context ); _resolveDataDefined( context );
Expand Down Expand Up @@ -727,7 +727,7 @@ void QgsArrowSymbolLayer::renderPolyline( const QPolygonF& points, QgsSymbolRend
{ {
for ( int pIdx = 0; pIdx < points.size() - 1; pIdx += 2 ) for ( int pIdx = 0; pIdx < points.size() - 1; pIdx += 2 )
{ {
mExpressionScope->setVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, pIdx + 1 ); mExpressionScope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, pIdx + 1, true ) );
_resolveDataDefined( context ); _resolveDataDefined( context );


if ( points.size() - pIdx >= 3 ) if ( points.size() - pIdx >= 3 )
Expand Down Expand Up @@ -778,7 +778,7 @@ void QgsArrowSymbolLayer::renderPolyline( const QPolygonF& points, QgsSymbolRend
// only straight arrows // only straight arrows
for ( int pIdx = 0; pIdx < points.size() - 1; pIdx++ ) for ( int pIdx = 0; pIdx < points.size() - 1; pIdx++ )
{ {
mExpressionScope->setVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, pIdx + 1 ); mExpressionScope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, pIdx + 1, true ) );
_resolveDataDefined( context ); _resolveDataDefined( context );


// origin point // origin point
Expand Down
8 changes: 4 additions & 4 deletions src/core/symbology-ng/qgslinesymbollayer.cpp
Expand Up @@ -985,7 +985,7 @@ void QgsMarkerLineSymbolLayer::renderPolylineInterval( const QPolygonF& points,
// "c" is 1 for regular point or in interval (0,1] for begin of line segment // "c" is 1 for regular point or in interval (0,1] for begin of line segment
lastPt += c * diff; lastPt += c * diff;
lengthLeft -= painterUnitInterval; lengthLeft -= painterUnitInterval;
scope->setVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, ++pointNum ); scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, ++pointNum, true ) );
mMarker->renderPoint( lastPt, context.feature(), rc, -1, context.selected() ); mMarker->renderPoint( lastPt, context.feature(), rc, -1, context.selected() );
c = 1; // reset c (if wasn't 1 already) c = 1; // reset c (if wasn't 1 already)
} }
Expand Down Expand Up @@ -1019,7 +1019,7 @@ void QgsMarkerLineSymbolLayer::renderPolylineVertex( const QPolygonF& points, Qg


QgsExpressionContextScope* scope = new QgsExpressionContextScope(); QgsExpressionContextScope* scope = new QgsExpressionContextScope();
context.renderContext().expressionContext().appendScope( scope ); context.renderContext().expressionContext().appendScope( scope );
scope->setVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT, points.size() ); scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT, points.size(), true ) );


double offsetAlongLine = mOffsetAlongLine; double offsetAlongLine = mOffsetAlongLine;
if ( hasDataDefinedProperty( QgsSymbolLayer::EXPR_OFFSET_ALONG_LINE ) ) if ( hasDataDefinedProperty( QgsSymbolLayer::EXPR_OFFSET_ALONG_LINE ) )
Expand All @@ -1046,7 +1046,7 @@ void QgsMarkerLineSymbolLayer::renderPolylineVertex( const QPolygonF& points, Qg
int pointNum = 0; int pointNum = 0;
while ( context.renderContext().geometry()->nextVertex( vId, vPoint ) ) while ( context.renderContext().geometry()->nextVertex( vId, vPoint ) )
{ {
scope->setVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, ++pointNum ); scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, ++pointNum, true ) );


if (( placement == Vertex && vId.type == QgsVertexId::SegmentVertex ) if (( placement == Vertex && vId.type == QgsVertexId::SegmentVertex )
|| ( placement == CurvePoint && vId.type == QgsVertexId::CurveVertex ) ) || ( placement == CurvePoint && vId.type == QgsVertexId::CurveVertex ) )
Expand Down Expand Up @@ -1112,7 +1112,7 @@ void QgsMarkerLineSymbolLayer::renderPolylineVertex( const QPolygonF& points, Qg
int pointNum = 0; int pointNum = 0;
for ( ; i < maxCount; ++i ) for ( ; i < maxCount; ++i )
{ {
scope->setVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, ++pointNum ); scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, ++pointNum, true ) );


if ( isRing && placement == Vertex && i == points.count() - 1 ) if ( isRing && placement == Vertex && i == points.count() - 1 )
{ {
Expand Down
6 changes: 3 additions & 3 deletions src/core/symbology-ng/qgspointdistancerenderer.cpp
Expand Up @@ -449,15 +449,15 @@ QgsExpressionContextScope* QgsPointDistanceRenderer::createGroupScope( const Clu


if ( groupColor.isValid() ) if ( groupColor.isValid() )
{ {
clusterScope->setVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, QgsSymbolLayerUtils::encodeColor( groupColor ) ); clusterScope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, QgsSymbolLayerUtils::encodeColor( groupColor ), true ) );
} }
else else
{ {
//mixed colors //mixed colors
clusterScope->setVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, QVariant() ); clusterScope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, QVariant(), true ) );
} }


clusterScope->setVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, group.size() ); clusterScope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, group.size(), true ) );
} }
return clusterScope; return clusterScope;
} }
Expand Down
10 changes: 5 additions & 5 deletions src/core/symbology-ng/qgssymbol.cpp
Expand Up @@ -696,8 +696,8 @@ void QgsSymbol::renderFeature( const QgsFeature& feature, QgsRenderContext& cont
{ {
context.expressionContext().appendScope( mSymbolRenderContext->expressionContextScope() ); context.expressionContext().appendScope( mSymbolRenderContext->expressionContextScope() );
QgsExpressionContextUtils::updateSymbolScope( this, mSymbolRenderContext->expressionContextScope() ); QgsExpressionContextUtils::updateSymbolScope( this, mSymbolRenderContext->expressionContextScope() );
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, mSymbolRenderContext->geometryPartCount() ); mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, mSymbolRenderContext->geometryPartCount(), true ) );
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1 ); mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1, true ) );
} }


// Collection of markers to paint, only used for no curve types. // Collection of markers to paint, only used for no curve types.
Expand Down Expand Up @@ -800,7 +800,7 @@ void QgsSymbol::renderFeature( const QgsFeature& feature, QgsRenderContext& cont
for ( int i = 0; i < mp.numGeometries(); ++i ) for ( int i = 0; i < mp.numGeometries(); ++i )
{ {
mSymbolRenderContext->setGeometryPartNum( i + 1 ); mSymbolRenderContext->setGeometryPartNum( i + 1 );
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1 ); mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1, true ) );


const QgsPointV2& point = static_cast< const QgsPointV2& >( *mp.geometryN( i ) ); const QgsPointV2& point = static_cast< const QgsPointV2& >( *mp.geometryN( i ) );
const QPointF pt = _getPoint( context, point ); const QPointF pt = _getPoint( context, point );
Expand Down Expand Up @@ -829,7 +829,7 @@ void QgsSymbol::renderFeature( const QgsFeature& feature, QgsRenderContext& cont
for ( unsigned int i = 0; i < num; ++i ) for ( unsigned int i = 0; i < num; ++i )
{ {
mSymbolRenderContext->setGeometryPartNum( i + 1 ); mSymbolRenderContext->setGeometryPartNum( i + 1 );
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1 ); mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1, true ) );


context.setGeometry( geomCollection.geometryN( i ) ); context.setGeometry( geomCollection.geometryN( i ) );
const QgsCurve& curve = dynamic_cast<const QgsCurve&>( *geomCollection.geometryN( i ) ); const QgsCurve& curve = dynamic_cast<const QgsCurve&>( *geomCollection.geometryN( i ) );
Expand Down Expand Up @@ -887,7 +887,7 @@ void QgsSymbol::renderFeature( const QgsFeature& feature, QgsRenderContext& cont
{ {
const unsigned i = listPartIndex[idx]; const unsigned i = listPartIndex[idx];
mSymbolRenderContext->setGeometryPartNum( i + 1 ); mSymbolRenderContext->setGeometryPartNum( i + 1 );
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1 ); mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1, true ) );


context.setGeometry( geomCollection.geometryN( i ) ); context.setGeometry( geomCollection.geometryN( i ) );
const QgsPolygonV2& polygon = dynamic_cast<const QgsPolygonV2&>( *geomCollection.geometryN( i ) ); const QgsPolygonV2& polygon = dynamic_cast<const QgsPolygonV2&>( *geomCollection.geometryN( i ) );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsfieldconditionalformatwidget.cpp
Expand Up @@ -78,7 +78,7 @@ void QgsFieldConditionalFormatWidget::setExpression()
context << QgsExpressionContextUtils::globalScope() context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope() << QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::layerScope( mLayer ); << QgsExpressionContextUtils::layerScope( mLayer );
context.lastScope()->setVariable( QStringLiteral( "value" ), 0 ); context.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "value" ), 0, true ) );
context.setHighlightedVariables( QStringList() << QStringLiteral( "value" ) ); context.setHighlightedVariables( QStringList() << QStringLiteral( "value" ) );


QgsExpressionBuilderDialog dlg( mLayer, mRuleEdit->text(), this, QStringLiteral( "generic" ), context ); QgsExpressionBuilderDialog dlg( mLayer, mRuleEdit->text(), this, QStringLiteral( "generic" ), context );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology-ng/qgslayerpropertieswidget.cpp
Expand Up @@ -251,7 +251,7 @@ QgsExpressionContext QgsLayerPropertiesWidget::createExpressionContext() const
{ {
//cheat a bit - set the symbol color variable to match the symbol layer's color (when we should really be using the *symbols* //cheat a bit - set the symbol color variable to match the symbol layer's color (when we should really be using the *symbols*
//color, but that's not accessible here). 99% of the time these will be the same anyway //color, but that's not accessible here). 99% of the time these will be the same anyway
symbolScope->setVariable( QgsExpressionContext::EXPR_SYMBOL_COLOR, mLayer->color() ); symbolScope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_SYMBOL_COLOR, mLayer->color(), true ) );
} }
expContext << symbolScope; expContext << symbolScope;
expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, 1, true ) ); expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, 1, true ) );
Expand Down
8 changes: 4 additions & 4 deletions src/gui/symbology-ng/qgspointclusterrendererwidget.cpp
Expand Up @@ -137,8 +137,8 @@ void QgsPointClusterRendererWidget::on_mRendererSettingsButton_clicked()
w->setPanelTitle( tr( "Renderer settings" ) ); w->setPanelTitle( tr( "Renderer settings" ) );


QgsExpressionContextScope scope; QgsExpressionContextScope scope;
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "" ); scope.addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "", true ) );
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0 ); scope.addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0, true ) );
QList< QgsExpressionContextScope > scopes = mContext.additionalExpressionContextScopes(); QList< QgsExpressionContextScope > scopes = mContext.additionalExpressionContextScopes();
scopes << scope; scopes << scope;
QgsSymbolWidgetContext context = mContext; QgsSymbolWidgetContext context = mContext;
Expand Down Expand Up @@ -190,8 +190,8 @@ void QgsPointClusterRendererWidget::on_mCenterSymbolPushButton_clicked()


QgsSymbolWidgetContext context = mContext; QgsSymbolWidgetContext context = mContext;
QgsExpressionContextScope scope; QgsExpressionContextScope scope;
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "" ); scope.addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "", true ) );
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0 ); scope.addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0, true ) );
QList< QgsExpressionContextScope > scopes = context.additionalExpressionContextScopes(); QList< QgsExpressionContextScope > scopes = context.additionalExpressionContextScopes();
scopes << scope; scopes << scope;
context.setAdditionalExpressionContextScopes( scopes ); context.setAdditionalExpressionContextScopes( scopes );
Expand Down
8 changes: 4 additions & 4 deletions src/gui/symbology-ng/qgspointdisplacementrendererwidget.cpp
Expand Up @@ -218,8 +218,8 @@ void QgsPointDisplacementRendererWidget::on_mRendererSettingsButton_clicked()
QgsSymbolWidgetContext context = mContext; QgsSymbolWidgetContext context = mContext;


QgsExpressionContextScope scope; QgsExpressionContextScope scope;
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "" ); scope.addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "", true ) );
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0 ); scope.addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0, true ) );
QList< QgsExpressionContextScope > scopes = context.additionalExpressionContextScopes(); QList< QgsExpressionContextScope > scopes = context.additionalExpressionContextScopes();
scopes << scope; scopes << scope;
context.setAdditionalExpressionContextScopes( scopes ); context.setAdditionalExpressionContextScopes( scopes );
Expand Down Expand Up @@ -366,8 +366,8 @@ void QgsPointDisplacementRendererWidget::on_mCenterSymbolPushButton_clicked()
QgsSymbolWidgetContext context = mContext; QgsSymbolWidgetContext context = mContext;


QgsExpressionContextScope scope; QgsExpressionContextScope scope;
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "" ); scope.addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "", true ) );
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0 ); scope.addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0, true ) );
QList< QgsExpressionContextScope > scopes = context.additionalExpressionContextScopes(); QList< QgsExpressionContextScope > scopes = context.additionalExpressionContextScopes();
scopes << scope; scopes << scope;
context.setAdditionalExpressionContextScopes( scopes ); context.setAdditionalExpressionContextScopes( scopes );
Expand Down

0 comments on commit 8589788

Please sign in to comment.