From e4ab1a6763856a32fea66c7ebc09367e7b9d34b9 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 9 Feb 2018 17:15:01 +1000 Subject: [PATCH] Don't generate symbol expression context scope when it's not being used Refs #17809 --- src/core/symbology/qgssymbol.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/core/symbology/qgssymbol.cpp b/src/core/symbology/qgssymbol.cpp index 61e0bf11942..ead5f2274d9 100644 --- a/src/core/symbology/qgssymbol.cpp +++ b/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(); + 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 ) ); + 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.