Skip to content

Commit

Permalink
More code tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 23, 2018
1 parent 89cd785 commit bb4699e
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -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 );
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit bb4699e

Please sign in to comment.