Skip to content

Commit

Permalink
Fix @parent variable detection in aggregate subExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 31, 2016
1 parent 6d38765 commit cc6b1e3
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/core/qgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3670,14 +3670,22 @@ const QList<QgsExpression::Function*>& QgsExpression::Functions()
if ( !node )
return true;

if ( !node->args() || node->args()->count() < 4 )
if ( !node->args() )
return false;
else

QSet<QString> referencedVars;
if ( node->args()->count() > 2 )
{
QgsExpression::Node* subExpressionNode = node->args()->at( 2 );
referencedVars = subExpressionNode->referencedVariables();
}

if ( node->args()->count() > 3 )
{
QgsExpression::Node* filterNode = node->args()->at( 3 );
QSet<QString> referencedVars = filterNode->referencedVariables();
return referencedVars.contains( "parent" ) || referencedVars.contains( QString() );
referencedVars = filterNode->referencedVariables();
}
return referencedVars.contains( "parent" ) || referencedVars.contains( QString() );
},
[]( const QgsExpression::NodeFunction* node )
{
Expand All @@ -3686,18 +3694,29 @@ const QList<QgsExpression::Function*>& QgsExpression::Functions()
if ( !node )
return QSet<QString>() << QgsFeatureRequest::AllAttributes;

if ( !node->args() || node->args()->count() < 4 )
if ( !node->args() )
return QSet<QString>();
else

QSet<QString> referencedCols;
QSet<QString> referencedVars;

if ( node->args()->count() > 2 )
{
QgsExpression::Node* subExpressionNode = node->args()->at( 2 );
referencedVars = subExpressionNode->referencedVariables();
referencedCols = subExpressionNode->referencedColumns();
}
if ( node->args()->count() > 3 )
{
QgsExpression::Node* filterNode = node->args()->at( 3 );
QSet<QString> referencedVars = filterNode->referencedVariables();

if ( referencedVars.contains( "parent" ) || referencedVars.contains( QString() ) )
return QSet<QString>() << QgsFeatureRequest::AllAttributes;
else
return QSet<QString>();
referencedVars = filterNode->referencedVariables();
referencedCols.unite( filterNode->referencedColumns() );
}

if ( referencedVars.contains( "parent" ) || referencedVars.contains( QString() ) )
return QSet<QString>() << QgsFeatureRequest::AllAttributes;
else
return referencedCols;
},
true
)
Expand Down

0 comments on commit cc6b1e3

Please sign in to comment.