Skip to content

Commit cc6b1e3

Browse files
committed
Fix @parent variable detection in aggregate subExpression
1 parent 6d38765 commit cc6b1e3

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

src/core/qgsexpression.cpp

+31-12
Original file line numberDiff line numberDiff line change
@@ -3670,14 +3670,22 @@ const QList<QgsExpression::Function*>& QgsExpression::Functions()
36703670
if ( !node )
36713671
return true;
36723672

3673-
if ( !node->args() || node->args()->count() < 4 )
3673+
if ( !node->args() )
36743674
return false;
3675-
else
3675+
3676+
QSet<QString> referencedVars;
3677+
if ( node->args()->count() > 2 )
3678+
{
3679+
QgsExpression::Node* subExpressionNode = node->args()->at( 2 );
3680+
referencedVars = subExpressionNode->referencedVariables();
3681+
}
3682+
3683+
if ( node->args()->count() > 3 )
36763684
{
36773685
QgsExpression::Node* filterNode = node->args()->at( 3 );
3678-
QSet<QString> referencedVars = filterNode->referencedVariables();
3679-
return referencedVars.contains( "parent" ) || referencedVars.contains( QString() );
3686+
referencedVars = filterNode->referencedVariables();
36803687
}
3688+
return referencedVars.contains( "parent" ) || referencedVars.contains( QString() );
36813689
},
36823690
[]( const QgsExpression::NodeFunction* node )
36833691
{
@@ -3686,18 +3694,29 @@ const QList<QgsExpression::Function*>& QgsExpression::Functions()
36863694
if ( !node )
36873695
return QSet<QString>() << QgsFeatureRequest::AllAttributes;
36883696

3689-
if ( !node->args() || node->args()->count() < 4 )
3697+
if ( !node->args() )
36903698
return QSet<QString>();
3691-
else
3699+
3700+
QSet<QString> referencedCols;
3701+
QSet<QString> referencedVars;
3702+
3703+
if ( node->args()->count() > 2 )
3704+
{
3705+
QgsExpression::Node* subExpressionNode = node->args()->at( 2 );
3706+
referencedVars = subExpressionNode->referencedVariables();
3707+
referencedCols = subExpressionNode->referencedColumns();
3708+
}
3709+
if ( node->args()->count() > 3 )
36923710
{
36933711
QgsExpression::Node* filterNode = node->args()->at( 3 );
3694-
QSet<QString> referencedVars = filterNode->referencedVariables();
3695-
3696-
if ( referencedVars.contains( "parent" ) || referencedVars.contains( QString() ) )
3697-
return QSet<QString>() << QgsFeatureRequest::AllAttributes;
3698-
else
3699-
return QSet<QString>();
3712+
referencedVars = filterNode->referencedVariables();
3713+
referencedCols.unite( filterNode->referencedColumns() );
37003714
}
3715+
3716+
if ( referencedVars.contains( "parent" ) || referencedVars.contains( QString() ) )
3717+
return QSet<QString>() << QgsFeatureRequest::AllAttributes;
3718+
else
3719+
return referencedCols;
37013720
},
37023721
true
37033722
)

0 commit comments

Comments
 (0)