Skip to content
Permalink
Browse files

Correctly utilise expression contexts for attribute form container vi…

…sibility

- we shouldn't use a single member instance of the context here, because continually
adding new scopes to that single instance will eventually cause the context to
become massive and slow
- correctly populate the context with the global/project/layer scopes

Fixes #35558
  • Loading branch information
nyalldawson authored and m-kuhn committed Apr 20, 2020
1 parent 49b57ee commit 3726613bc62b13e2bbea62d4f89ab0509c6727ec
Showing with 10 additions and 7 deletions.
  1. +10 −6 src/gui/qgsattributeform.cpp
  2. +0 −1 src/gui/qgsattributeform.h
@@ -931,28 +931,32 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
// sync OK button status
synchronizeEnabledState();

mExpressionContext.setFeature( ft );

mExpressionContext << QgsExpressionContextUtils::formScope( ft, mContext.attributeFormModeString() );
QgsExpressionContext context;
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
context.appendScope( QgsExpressionContextUtils::formScope( ft, mContext.attributeFormModeString() ) );
context.setFeature( ft );

// Recheck visibility for all containers which are controlled by this value
const QVector<ContainerInformation *> infos = mContainerInformationDependency.value( eww->field().name() );
for ( ContainerInformation *info : infos )
{
info->apply( &mExpressionContext );
info->apply( &context );
}
}
}

void QgsAttributeForm::updateContainersVisibility()
{
mExpressionContext << QgsExpressionContextUtils::formScope( QgsFeature( mFeature ), mContext.attributeFormModeString() );
QgsExpressionContext context;
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
context.appendScope( QgsExpressionContextUtils::formScope( mFeature, mContext.attributeFormModeString() ) );
context.setFeature( mFeature );

const QVector<ContainerInformation *> infos = mContainerVisibilityInformation;

for ( ContainerInformation *info : infos )
{
info->apply( &mExpressionContext );
info->apply( &context );
}

//and update the constraints
@@ -391,7 +391,6 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
QList<QgsAttributeFormInterface *> mInterfaces;
QMap< int, QgsAttributeFormEditorWidget * > mFormEditorWidgets;
QList< QgsAttributeFormWidget *> mFormWidgets;
QgsExpressionContext mExpressionContext;
QMap<const QgsVectorLayerJoinInfo *, QgsFeature> mJoinedFeatures;
bool mValuesInitialized = false;
bool mDirty = false;

0 comments on commit 3726613

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