Skip to content
Permalink
Browse files

Don't generate symbol expression context scope when it's not

being used

Refs #17809
  • Loading branch information
nyalldawson committed Feb 11, 2018
1 parent 180d878 commit e4ab1a6763856a32fea66c7ebc09367e7b9d34b9
Showing with 19 additions and 11 deletions.
  1. +19 −11 src/core/symbology/qgssymbol.cpp
@@ -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;
}
@@ -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.

0 comments on commit e4ab1a6

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