Skip to content

Commit

Permalink
Don't generate symbol expression context scope when it's not
Browse files Browse the repository at this point in the history
being used

Refs #17809
  • Loading branch information
nyalldawson committed Feb 11, 2018
1 parent 180d878 commit e4ab1a6
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/core/symbology/qgssymbol.cpp
Expand Up @@ -651,6 +651,11 @@ bool QgsSymbol::hasDataDefinedProperties() const
{
if ( layer->dataDefinedProperties().hasActiveProperties() )
return true;
// we treat geometry generator layers like they have data defined properties,
// since the WHOLE layer is based on expressions and requires the full expression
// context
if ( layer->layerType() == QLatin1String( "GeometryGenerator" ) )
return true;
}
return false;
}
Expand Down Expand Up @@ -708,17 +713,20 @@ void QgsSymbol::renderFeature( const QgsFeature &feature, QgsRenderContext &cont
ExpressionContextScopePopper scopePopper;
if ( mSymbolRenderContext->expressionContextScope() )
{
// this is somewhat nasty - by appending this scope here it's now owned
// by both mSymbolRenderContext AND context.expressionContext()
// the RAII scopePopper is required to make sure it always has ownership transferred back
// from context.expressionContext(), even if exceptions of other early exits occur in this
// function
context.expressionContext().appendScope( mSymbolRenderContext->expressionContextScope() );
scopePopper.context = &context.expressionContext();

QgsExpressionContextUtils::updateSymbolScope( this, mSymbolRenderContext->expressionContextScope() );
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, mSymbolRenderContext->geometryPartCount(), true ) );
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1, true ) );
if ( hasDataDefinedProperties() )
{
// this is somewhat nasty - by appending this scope here it's now owned
// by both mSymbolRenderContext AND context.expressionContext()
// the RAII scopePopper is required to make sure it always has ownership transferred back
// from context.expressionContext(), even if exceptions of other early exits occur in this
// function
context.expressionContext().appendScope( mSymbolRenderContext->expressionContextScope() );
scopePopper.context = &context.expressionContext();

QgsExpressionContextUtils::updateSymbolScope( this, mSymbolRenderContext->expressionContextScope() );
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, mSymbolRenderContext->geometryPartCount(), true ) );
mSymbolRenderContext->expressionContextScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1, true ) );
}
}

// Collection of markers to paint, only used for no curve types.
Expand Down

0 comments on commit e4ab1a6

Please sign in to comment.