Skip to content
Permalink
Browse files

More code tweaks

  • Loading branch information
nyalldawson committed Aug 23, 2018
1 parent 89cd785 commit bb4699e2eab7afeb3e70176cfbbfc0709e814940
Showing with 20 additions and 12 deletions.
  1. +20 −12 src/core/expression/qgsexpressionfunction.cpp
@@ -4809,8 +4809,12 @@ QVariant QgsArrayForeachExpressionFunction::run( QgsExpressionNode::NodeList *ar
QVariantList array = args->at( 0 )->eval( parent, context ).toList();

QgsExpressionContext *subContext = const_cast<QgsExpressionContext *>( context );
if ( !context )
subContext = new QgsExpressionContext();
std::unique_ptr< QgsExpressionContext > tempContext;
if ( !subContext )
{
tempContext = qgis::make_unique< QgsExpressionContext >();
subContext = tempContext.get();
}

QgsExpressionContextScope *subScope = new QgsExpressionContextScope();
subContext->appendScope( subScope );
@@ -4821,8 +4825,8 @@ QVariant QgsArrayForeachExpressionFunction::run( QgsExpressionNode::NodeList *ar
result << args->at( 1 )->eval( parent, subContext );
}

if ( !context )
delete subContext;
if ( context )
delete subContext->popScope();

return result;
}
@@ -4909,15 +4913,19 @@ QVariant QgsWithVariableExpressionFunction::run( QgsExpressionNode::NodeList *ar
QVariant name = args->at( 0 )->eval( parent, context );
QVariant value = args->at( 1 )->eval( parent, context );

QgsExpressionContext *updatedContext = const_cast<QgsExpressionContext *>( context );
if ( !context )
updatedContext = new QgsExpressionContext();
const QgsExpressionContext *updatedContext = context;
std::unique_ptr< QgsExpressionContext > tempContext;
if ( !updatedContext )
{
tempContext = qgis::make_unique< QgsExpressionContext >();
updatedContext = tempContext.get();
}

appendTemporaryVariable( updatedContext, name.toString(), value );
result = args->at( 2 )->eval( parent, updatedContext );
popTemporaryVariable( updatedContext );
if ( !context )
delete updatedContext;

if ( context )
popTemporaryVariable( updatedContext );

return result;
}
@@ -4945,9 +4953,9 @@ bool QgsWithVariableExpressionFunction::prepare( const QgsExpressionNodeFunction
QVariant name = args->at( 0 )->prepare( parent, context );
QVariant value = args->at( 1 )->prepare( parent, context );

QgsExpressionContext *updatedContext = const_cast<QgsExpressionContext *>( context );
const QgsExpressionContext *updatedContext = context;
std::unique_ptr< QgsExpressionContext > tempContext;
if ( !context )
if ( !updatedContext )
{
tempContext = qgis::make_unique< QgsExpressionContext >();
updatedContext = tempContext.get();

0 comments on commit bb4699e

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