Skip to content

Commit

Permalink
Fix typo in field expression-based constraint update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jan 13, 2024
1 parent 56d1ea8 commit 5407145
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/core/attributeformmodelbase.cpp
Expand Up @@ -738,14 +738,17 @@ void _checkChildrenValidity( QStandardItem *parent, bool &hardValidity, bool &so

void AttributeFormModelBase::updateVisibilityAndConstraints( int fieldIndex )
{
const QString fieldName = fieldIndex > -1 && fieldIndex < mLayer->fields().size() ? mLayer->fields().at( fieldIndex ).name() : QString();
QgsFields fields = mFeatureModel->feature().fields();
mExpressionContext.setFields( fields );
mExpressionContext.setFeature( mFeatureModel->feature() );

bool visibilityChanged = false;
for ( const VisibilityExpression &it : std::as_const( mVisibilityExpressions ) )
{
if ( fieldIndex == -1 || it.first.referencedAttributeIndexes( fields ).contains( fieldIndex ) )
// If triggered by an updated field index (fieldIndex), check if the visibility
// expression refers to that field
if ( fieldIndex == -1 || it.first.referencedColumns().contains( fieldName ) || it.first.referencedColumns().contains( QgsFeatureRequest::ALL_ATTRIBUTES ) )
{
QgsExpression exp = it.first;
exp.prepare( &mExpressionContext );
Expand All @@ -770,9 +773,10 @@ void AttributeFormModelBase::updateVisibilityAndConstraints( int fieldIndex )
int fidx = fieldIterator.value();
if ( fieldIndex != -1 && fidx != fieldIndex )
{
const QString fieldName = mLayer->fields().at( fieldIndex ).name();
const QgsExpression expression = mLayer->fields().at( fieldIndex ).constraints().constraintExpression();
if ( !expression.referencedColumns().contains( fieldName ) )
// Check whether the current field iterator index (fidx) has an expression constraints referencing the
// updated field index (fieldIndex) which triggered a constraints update
const QgsExpression expression = mLayer->fields().at( fidx ).constraints().constraintExpression();
if ( !expression.referencedColumns().contains( fieldName ) && !expression.referencedColumns().contains( QgsFeatureRequest::ALL_ATTRIBUTES ) )
{
continue;
}
Expand Down

1 comment on commit 5407145

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.