From 8579949eed0f10bab5fb087cc9d41f8c550c3d1b Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Tue, 15 Oct 2024 21:38:05 -0300 Subject: [PATCH 01/10] in progress - field editable state and alias expressions --- app/attributes/attributecontroller.cpp | 17 +++++++++- app/attributes/attributedata.cpp | 47 ++++++++++++++++++++++++-- app/attributes/attributedata.h | 22 ++++++++++-- 3 files changed, 79 insertions(+), 7 deletions(-) diff --git a/app/attributes/attributecontroller.cpp b/app/attributes/attributecontroller.cpp index ad008c6d2..65d4ad253 100644 --- a/app/attributes/attributecontroller.cpp +++ b/app/attributes/attributecontroller.cpp @@ -232,9 +232,22 @@ void AttributeController::flatten( QStringList expressions; QString expression = field.constraints().constraintExpression(); + //Alias|name expression + QgsEditFormConfig editFormConfig = layer->editFormConfig(); + QString fieldName = field.name(); + QgsPropertyCollection fieldProperties = editFormConfig.dataDefinedFieldProperties( fieldName ); + QgsProperty nameProperty = fieldProperties.property( QgsEditFormConfig::DataDefinedProperty::Alias ); + QString nameExpressionString = nameProperty.expressionString(); + QgsExpression nameExpression( nameExpressionString ); + + //Editable expression + QgsProperty editableProperty = fieldProperties.property( QgsEditFormConfig::DataDefinedProperty::Editable ); + QString editableExpressionString = editableProperty.expressionString(); + QgsExpression editableExpression( editableExpressionString ); + if ( !expression.isEmpty() ) { - expressions << field.constraints().constraintExpression(); + expressions << field.constraints().constraintExpression() << nameExpression << editableExpression; } bool isReadOnly = ( layer->editFormConfig().readOnly( fieldIndex ) ) || @@ -249,8 +262,10 @@ void AttributeController::flatten( groupName, parentTabRow, layer->attributeDisplayName( fieldIndex ), + nameExpression, editorField->showLabel(), !isReadOnly, + editableExpression, getEditorWidgetSetup( layer, fieldIndex ), fieldIndex, parentVisibilityExpressions // field doesn't have visibility expression itself diff --git a/app/attributes/attributedata.cpp b/app/attributes/attributedata.cpp index b76fa17c8..9aaf13940 100644 --- a/app/attributes/attributedata.cpp +++ b/app/attributes/attributedata.cpp @@ -22,8 +22,10 @@ FormItem::FormItem( const QUuid &id, const int parentTabId, FormItem::FormItemType type, const QString &name, + const QgsExpression &nameExpression, bool showName, bool isEditable, + const QgsExpression &editableExpression, const QgsEditorWidgetSetup &editorWidgetSetup, int fieldIndex, const QgsExpression &visibilityExpression, @@ -35,8 +37,10 @@ FormItem::FormItem( const QUuid &id, , mParentTabId( parentTabId ) , mType( type ) , mName( name ) + , mNameExpression( nameExpression ) //mNameExpression , mShowName( showName ) , mIsEditable( isEditable ) + , mEditableExpression( editableExpression ) , mEditorWidgetSetup( editorWidgetSetup ) , mFieldIndex( fieldIndex ) , mVisibilityExpression( visibilityExpression ) @@ -48,8 +52,8 @@ FormItem *FormItem::createFieldItem( const QUuid &id, const QgsField &field, const QString &groupName, int parentTabId, - const QString &name, bool showName, - bool isEditable, + const QString &name, const QgsExpression &nameExpression, bool showName, + bool isEditable, const QgsExpression &editableExpression, const QgsEditorWidgetSetup &editorWidgetSetup, int fieldIndex, @@ -63,8 +67,10 @@ FormItem *FormItem::createFieldItem( const QUuid &id, parentTabId, FormItem::Field, name, + nameExpression, showName, isEditable, + editableExpression, editorWidgetSetup, fieldIndex, visibilityExpression, @@ -88,8 +94,10 @@ FormItem *FormItem::createRelationItem( const QUuid &id, parentTabId, FormItem::Relation, name, + QgsExpression(), showName, true, + QgsExpression(), QgsEditorWidgetSetup(), -1, visibilityExpression, @@ -119,8 +127,10 @@ FormItem *FormItem::createSpacerItem( parentTabId, FormItem::Spacer, name, + QgsExpression(), false, // label is never shown for spacer false, + QgsExpression(), config, -1, visibilityExpression, @@ -153,8 +163,10 @@ FormItem *FormItem::createRichTextItem( parentTabId, FormItem::RichText, name, + QgsExpression(), showName, false, + QgsExpression(), config, -1, visibilityExpression, @@ -228,6 +240,11 @@ void FormItem::setVisible( bool visible ) mVisible = visible; } +void FormItem::setEditable( bool editable ) +{ + mIsEditable = editable; +} + QUuid FormItem::id() const { return mId; @@ -243,6 +260,16 @@ QgsExpression FormItem::visibilityExpression() const return mVisibilityExpression; } +QgsExpression FormItem::nameExpression() const +{ + return mNameExpression; +} + +QgsExpression FormItem::editableExpression() const +{ + return mEditableExpression; +} + bool FormItem::visible() const { return mVisible; @@ -292,11 +319,15 @@ void FormItem::setRawValue( const QVariant &rawValue ) TabItem::TabItem( const int &id, const QString &name, const QVector &formItems, - const QgsExpression &visibilityExpression ) + const QgsExpression &visibilityExpression, + const QgsExpression &aliasExpression, + const QgsExpression &editableExpression ) : mTabIndex( id ) , mName( name ) , mFormItems( formItems ) , mVisibilityExpression( visibilityExpression ) + , mNameExpression( aliasExpression ) + , mEditableExpression( editableExpression ) { } @@ -325,6 +356,16 @@ QgsExpression TabItem::visibilityExpression() const return mVisibilityExpression; } +QgsExpression TabItem::nameExpression() const +{ + return mNameExpression; +} + +QgsExpression TabItem::editableExpression() const +{ + return mEditableExpression; +} + const QVector TabItem::formItems() const { return mFormItems; diff --git a/app/attributes/attributedata.h b/app/attributes/attributedata.h index 133a2e9b3..68fdf4c80 100644 --- a/app/attributes/attributedata.h +++ b/app/attributes/attributedata.h @@ -57,8 +57,10 @@ class FormItem int parentTabId, FormItem::FormItemType type, const QString &name, + const QgsExpression &nameExpression, bool showName, bool isEditable, + const QgsExpression &editableExpression, const QgsEditorWidgetSetup &editorWidgetSetup, int fieldIndex, const QgsExpression &visibilityExpression, @@ -71,8 +73,10 @@ class FormItem const QString &groupName, int parentTabId, const QString &name, + const QgsExpression &nameExpression, bool showName, bool isEditable, + const QgsExpression &editableExpression, const QgsEditorWidgetSetup &editorWidgetSetup, int fieldIndex, const QgsExpression &visibilityExpression @@ -110,7 +114,6 @@ class FormItem FormItem::FormItemType type() const; QString name() const; - bool isEditable() const; QString editorWidgetType() const; QVariantMap editorWidgetConfig() const; int fieldIndex() const; @@ -121,6 +124,9 @@ class FormItem FieldValidator::ValidationStatus validationStatus() const; void setValidationStatus( FieldValidator::ValidationStatus status ); + bool isEditable() const; + void setEditable( bool editable ); + bool isVisible() const; void setVisible( bool visible ); @@ -129,6 +135,8 @@ class FormItem int parentTabId() const; QgsExpression visibilityExpression() const; + QgsExpression nameExpression() const; + QgsExpression editableExpression() const; bool visible() const; @@ -156,13 +164,15 @@ class FormItem const FormItem::FormItemType mType; const QString mName; const bool mShowName = true; // "Show label" in Widget Display group in QGIS widget settings - const bool mIsEditable; const QgsEditorWidgetSetup mEditorWidgetSetup; const int mFieldIndex; const QgsExpression mVisibilityExpression; + const QgsExpression mNameExpression; + const QgsExpression mEditableExpression; QString mValidationMessage; FieldValidator::ValidationStatus mValidationStatus = FieldValidator::Valid; + bool mIsEditable = true; bool mVisible = false; QVariant mOriginalValue; // original unmodified value QVariant mRawValue; @@ -176,7 +186,9 @@ class TabItem TabItem( const int &id, const QString &name, const QVector &formItems, - const QgsExpression &visibilityExpression + const QgsExpression &visibilityExpression, + const QgsExpression &nameExpression, + const QgsExpression &editableExpression ); QString name() const; @@ -188,12 +200,16 @@ class TabItem int tabIndex() const; QgsExpression visibilityExpression() const; + QgsExpression nameExpression() const; + QgsExpression editableExpression() const; private: const int mTabIndex; const QString mName; const QVector mFormItems; const QgsExpression mVisibilityExpression; + const QgsExpression mNameExpression; + const QgsExpression mEditableExpression; bool mVisible = false; }; From 5a9e8c03bef7cf2d47f47792225f6c50c193fcfb Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Thu, 17 Oct 2024 01:18:03 -0300 Subject: [PATCH 02/10] evaluating alias and editable expressions --- app/attributes/attributecontroller.cpp | 50 ++++++++++++++++++++++++++ app/attributes/attributedata.cpp | 21 ++++------- app/attributes/attributedata.h | 13 +++---- 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/app/attributes/attributecontroller.cpp b/app/attributes/attributecontroller.cpp index 65d4ad253..b20554960 100644 --- a/app/attributes/attributecontroller.cpp +++ b/app/attributes/attributecontroller.cpp @@ -919,6 +919,56 @@ void AttributeController::recalculateDerivedItems( bool isFormValueChange, bool } } + // Evaluate form items editability + { + QMap>::iterator formItemsIterator = mFormItems.begin(); + while ( formItemsIterator != mFormItems.end() ) + { + std::shared_ptr item = formItemsIterator.value(); + bool editable = item->isEditable(); + QgsExpression exp = item->editableExpression(); + exp.prepare( &expressionContext ); + + if ( exp.isValid() ) + { + editable = exp.evaluate( &expressionContext ).toInt(); + } + + if ( item->isEditable() != editable ) + { + item->setEditable( editable ); + changedFormItems << item->id(); + } + + ++formItemsIterator; + } + } + + // Evaluate form items alias/name + { + QMap>::iterator formItemsIterator = mFormItems.begin(); + while ( formItemsIterator != mFormItems.end() ) + { + std::shared_ptr item = formItemsIterator.value(); + QString name = item->name(); + QgsExpression exp = item->nameExpression(); + exp.prepare( &expressionContext ); + + if ( exp.isValid() ) + { + name = exp.evaluate( &expressionContext ).toString(); + } + + if ( item->name() != name ) + { + item->setName( name ); + changedFormItems << item->id(); + } + + ++formItemsIterator; + } + } + // Evaluate form items value state - hard/soft constraints, value validity { bool containsValidationError = false; diff --git a/app/attributes/attributedata.cpp b/app/attributes/attributedata.cpp index 9aaf13940..82488b184 100644 --- a/app/attributes/attributedata.cpp +++ b/app/attributes/attributedata.cpp @@ -187,6 +187,11 @@ QString FormItem::name() const return mName; } +void FormItem::setName( QString name ) +{ + mName = name; +} + bool FormItem::isEditable() const { return mIsEditable; @@ -319,15 +324,11 @@ void FormItem::setRawValue( const QVariant &rawValue ) TabItem::TabItem( const int &id, const QString &name, const QVector &formItems, - const QgsExpression &visibilityExpression, - const QgsExpression &aliasExpression, - const QgsExpression &editableExpression ) + const QgsExpression &visibilityExpression ) : mTabIndex( id ) , mName( name ) , mFormItems( formItems ) , mVisibilityExpression( visibilityExpression ) - , mNameExpression( aliasExpression ) - , mEditableExpression( editableExpression ) { } @@ -356,16 +357,6 @@ QgsExpression TabItem::visibilityExpression() const return mVisibilityExpression; } -QgsExpression TabItem::nameExpression() const -{ - return mNameExpression; -} - -QgsExpression TabItem::editableExpression() const -{ - return mEditableExpression; -} - const QVector TabItem::formItems() const { return mFormItems; diff --git a/app/attributes/attributedata.h b/app/attributes/attributedata.h index 68fdf4c80..74edc2d87 100644 --- a/app/attributes/attributedata.h +++ b/app/attributes/attributedata.h @@ -113,7 +113,10 @@ class FormItem ); FormItem::FormItemType type() const; + QString name() const; + void setName( QString name ); + QString editorWidgetType() const; QVariantMap editorWidgetConfig() const; int fieldIndex() const; @@ -162,7 +165,6 @@ class FormItem const QString mGroupName; //empty for no group, group/tab name if widget is in container const int mParentTabId; const FormItem::FormItemType mType; - const QString mName; const bool mShowName = true; // "Show label" in Widget Display group in QGIS widget settings const QgsEditorWidgetSetup mEditorWidgetSetup; const int mFieldIndex; @@ -170,6 +172,7 @@ class FormItem const QgsExpression mNameExpression; const QgsExpression mEditableExpression; + QString mName; QString mValidationMessage; FieldValidator::ValidationStatus mValidationStatus = FieldValidator::Valid; bool mIsEditable = true; @@ -186,9 +189,7 @@ class TabItem TabItem( const int &id, const QString &name, const QVector &formItems, - const QgsExpression &visibilityExpression, - const QgsExpression &nameExpression, - const QgsExpression &editableExpression + const QgsExpression &visibilityExpression ); QString name() const; @@ -200,16 +201,12 @@ class TabItem int tabIndex() const; QgsExpression visibilityExpression() const; - QgsExpression nameExpression() const; - QgsExpression editableExpression() const; private: const int mTabIndex; const QString mName; const QVector mFormItems; const QgsExpression mVisibilityExpression; - const QgsExpression mNameExpression; - const QgsExpression mEditableExpression; bool mVisible = false; }; From a66ef1e8a30ff9635688a86aea4c938f85418142 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Thu, 17 Oct 2024 08:17:08 -0300 Subject: [PATCH 03/10] checking if there is expression --- app/attributes/attributecontroller.cpp | 44 +++++++++++++++----------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/app/attributes/attributecontroller.cpp b/app/attributes/attributecontroller.cpp index b20554960..9329dbc81 100644 --- a/app/attributes/attributecontroller.cpp +++ b/app/attributes/attributecontroller.cpp @@ -925,19 +925,23 @@ void AttributeController::recalculateDerivedItems( bool isFormValueChange, bool while ( formItemsIterator != mFormItems.end() ) { std::shared_ptr item = formItemsIterator.value(); - bool editable = item->isEditable(); QgsExpression exp = item->editableExpression(); - exp.prepare( &expressionContext ); - if ( exp.isValid() ) + if ( !exp.expression().isEmpty() ) { - editable = exp.evaluate( &expressionContext ).toInt(); - } + bool editable = item->isEditable(); + exp.prepare( &expressionContext ); - if ( item->isEditable() != editable ) - { - item->setEditable( editable ); - changedFormItems << item->id(); + if ( exp.isValid() ) + { + editable = exp.evaluate( &expressionContext ).toInt(); + } + + if ( item->isEditable() != editable ) + { + item->setEditable( editable ); + changedFormItems << item->id(); + } } ++formItemsIterator; @@ -950,19 +954,23 @@ void AttributeController::recalculateDerivedItems( bool isFormValueChange, bool while ( formItemsIterator != mFormItems.end() ) { std::shared_ptr item = formItemsIterator.value(); - QString name = item->name(); QgsExpression exp = item->nameExpression(); - exp.prepare( &expressionContext ); - if ( exp.isValid() ) + if ( !exp.expression().isEmpty() ) { - name = exp.evaluate( &expressionContext ).toString(); - } + QString name = item->name(); + exp.prepare( &expressionContext ); - if ( item->name() != name ) - { - item->setName( name ); - changedFormItems << item->id(); + if ( exp.isValid() ) + { + name = exp.evaluate( &expressionContext ).toString(); + } + + if ( item->name() != name ) + { + item->setName( name ); + changedFormItems << item->id(); + } } ++formItemsIterator; From 37749b04cf4102369c034672962a3961eeff0881 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Thu, 17 Oct 2024 10:37:49 -0300 Subject: [PATCH 04/10] small update in comments --- app/attributes/attributecontroller.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/attributes/attributecontroller.cpp b/app/attributes/attributecontroller.cpp index 9329dbc81..ccf1c18de 100644 --- a/app/attributes/attributecontroller.cpp +++ b/app/attributes/attributecontroller.cpp @@ -232,7 +232,7 @@ void AttributeController::flatten( QStringList expressions; QString expression = field.constraints().constraintExpression(); - //Alias|name expression + // Retrieving field name/alias expression QgsEditFormConfig editFormConfig = layer->editFormConfig(); QString fieldName = field.name(); QgsPropertyCollection fieldProperties = editFormConfig.dataDefinedFieldProperties( fieldName ); @@ -240,7 +240,7 @@ void AttributeController::flatten( QString nameExpressionString = nameProperty.expressionString(); QgsExpression nameExpression( nameExpressionString ); - //Editable expression + // Retrieving field editability expression QgsProperty editableProperty = fieldProperties.property( QgsEditFormConfig::DataDefinedProperty::Editable ); QString editableExpressionString = editableProperty.expressionString(); QgsExpression editableExpression( editableExpressionString ); From 00f86c366995eb7d72acba8a0a98be36d3e568cc Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Mon, 28 Oct 2024 11:07:36 -0300 Subject: [PATCH 05/10] removing unecessary addition --- app/attributes/attributecontroller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/attributes/attributecontroller.cpp b/app/attributes/attributecontroller.cpp index ccf1c18de..7e6ceb297 100644 --- a/app/attributes/attributecontroller.cpp +++ b/app/attributes/attributecontroller.cpp @@ -247,7 +247,7 @@ void AttributeController::flatten( if ( !expression.isEmpty() ) { - expressions << field.constraints().constraintExpression() << nameExpression << editableExpression; + expressions << field.constraints().constraintExpression(); } bool isReadOnly = ( layer->editFormConfig().readOnly( fieldIndex ) ) || From 27f3c938a99bf534b32959dd00d3739d25400c8c Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Wed, 30 Oct 2024 10:47:11 -0300 Subject: [PATCH 06/10] small code styling and comments adjustments --- app/attributes/attributecontroller.cpp | 5 +++-- app/attributes/attributedata.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/attributes/attributecontroller.cpp b/app/attributes/attributecontroller.cpp index 7e6ceb297..d0952b213 100644 --- a/app/attributes/attributecontroller.cpp +++ b/app/attributes/attributecontroller.cpp @@ -232,10 +232,11 @@ void AttributeController::flatten( QStringList expressions; QString expression = field.constraints().constraintExpression(); - // Retrieving field name/alias expression QgsEditFormConfig editFormConfig = layer->editFormConfig(); QString fieldName = field.name(); QgsPropertyCollection fieldProperties = editFormConfig.dataDefinedFieldProperties( fieldName ); + + // Retrieving field name expression QgsProperty nameProperty = fieldProperties.property( QgsEditFormConfig::DataDefinedProperty::Alias ); QString nameExpressionString = nameProperty.expressionString(); QgsExpression nameExpression( nameExpressionString ); @@ -948,7 +949,7 @@ void AttributeController::recalculateDerivedItems( bool isFormValueChange, bool } } - // Evaluate form items alias/name + // Evaluate form items name { QMap>::iterator formItemsIterator = mFormItems.begin(); while ( formItemsIterator != mFormItems.end() ) diff --git a/app/attributes/attributedata.cpp b/app/attributes/attributedata.cpp index 82488b184..847073455 100644 --- a/app/attributes/attributedata.cpp +++ b/app/attributes/attributedata.cpp @@ -37,7 +37,7 @@ FormItem::FormItem( const QUuid &id, , mParentTabId( parentTabId ) , mType( type ) , mName( name ) - , mNameExpression( nameExpression ) //mNameExpression + , mNameExpression( nameExpression ) , mShowName( showName ) , mIsEditable( isEditable ) , mEditableExpression( editableExpression ) From 64f7ac7a74092aea5dd3161c284d209638d25e26 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Tue, 19 Nov 2024 18:27:01 -0300 Subject: [PATCH 07/10] post review updates --- app/attributes/attributecontroller.cpp | 6 +++--- app/attributes/attributedata.cpp | 2 +- app/attributes/attributedata.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/attributes/attributecontroller.cpp b/app/attributes/attributecontroller.cpp index d0952b213..ed0f17b83 100644 --- a/app/attributes/attributecontroller.cpp +++ b/app/attributes/attributecontroller.cpp @@ -920,7 +920,7 @@ void AttributeController::recalculateDerivedItems( bool isFormValueChange, bool } } - // Evaluate form items editability + // Evaluate if form items are editable { QMap>::iterator formItemsIterator = mFormItems.begin(); while ( formItemsIterator != mFormItems.end() ) @@ -935,12 +935,12 @@ void AttributeController::recalculateDerivedItems( bool isFormValueChange, bool if ( exp.isValid() ) { - editable = exp.evaluate( &expressionContext ).toInt(); + editable = exp.evaluate( &expressionContext ).toBool(); } if ( item->isEditable() != editable ) { - item->setEditable( editable ); + item->setIsEditable( editable ); changedFormItems << item->id(); } } diff --git a/app/attributes/attributedata.cpp b/app/attributes/attributedata.cpp index 847073455..a9e761cda 100644 --- a/app/attributes/attributedata.cpp +++ b/app/attributes/attributedata.cpp @@ -245,7 +245,7 @@ void FormItem::setVisible( bool visible ) mVisible = visible; } -void FormItem::setEditable( bool editable ) +void FormItem::setIsEditable( bool editable ) { mIsEditable = editable; } diff --git a/app/attributes/attributedata.h b/app/attributes/attributedata.h index 74edc2d87..fae50f838 100644 --- a/app/attributes/attributedata.h +++ b/app/attributes/attributedata.h @@ -128,7 +128,7 @@ class FormItem void setValidationStatus( FieldValidator::ValidationStatus status ); bool isEditable() const; - void setEditable( bool editable ); + void setIsEditable( bool editable ); bool isVisible() const; void setVisible( bool visible ); From d99485891dd5bb9a60b0a11a7e8d58fcbec9e814 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Wed, 20 Nov 2024 21:16:18 -0300 Subject: [PATCH 08/10] comments on new private members of attribute data --- app/attributes/attributedata.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/attributes/attributedata.h b/app/attributes/attributedata.h index fae50f838..d24375429 100644 --- a/app/attributes/attributedata.h +++ b/app/attributes/attributedata.h @@ -169,8 +169,8 @@ class FormItem const QgsEditorWidgetSetup mEditorWidgetSetup; const int mFieldIndex; const QgsExpression mVisibilityExpression; - const QgsExpression mNameExpression; - const QgsExpression mEditableExpression; + const QgsExpression mNameExpression; // Expression to define field’s display name (alias) + const QgsExpression mEditableExpression; // Expression to determine whether the field is editable QString mName; QString mValidationMessage; From b4a95b1f82118eb1aa23be74c8af67e2afa349db Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Fri, 22 Nov 2024 15:49:45 -0300 Subject: [PATCH 09/10] if default value on update enabled, field always not editable --- app/attributes/attributecontroller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/attributes/attributecontroller.cpp b/app/attributes/attributecontroller.cpp index ed0f17b83..135319067 100644 --- a/app/attributes/attributecontroller.cpp +++ b/app/attributes/attributecontroller.cpp @@ -928,7 +928,7 @@ void AttributeController::recalculateDerivedItems( bool isFormValueChange, bool std::shared_ptr item = formItemsIterator.value(); QgsExpression exp = item->editableExpression(); - if ( !exp.expression().isEmpty() ) + if ( !exp.expression().isEmpty() && !item->field().defaultValueDefinition().applyOnUpdate() ) { bool editable = item->isEditable(); exp.prepare( &expressionContext ); From 2f3641c97480348ffe481399df4050c199274551 Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Mon, 9 Dec 2024 10:03:53 -0300 Subject: [PATCH 10/10] evaluating expression only if not enabled Apply default value on update --- app/attributes/attributecontroller.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/attributes/attributecontroller.cpp b/app/attributes/attributecontroller.cpp index 135319067..84f3d0f12 100644 --- a/app/attributes/attributecontroller.cpp +++ b/app/attributes/attributecontroller.cpp @@ -243,8 +243,15 @@ void AttributeController::flatten( // Retrieving field editability expression QgsProperty editableProperty = fieldProperties.property( QgsEditFormConfig::DataDefinedProperty::Editable ); - QString editableExpressionString = editableProperty.expressionString(); - QgsExpression editableExpression( editableExpressionString ); + QString editableExpressionString; + QgsExpression editableExpression; + + // Bypass reading the editable expression if Apply default value on update is enabled + if ( !field.defaultValueDefinition().applyOnUpdate() ) + { + editableExpressionString = editableProperty.expressionString(); + editableExpression = QgsExpression( editableExpressionString ); + } if ( !expression.isEmpty() ) { @@ -928,7 +935,7 @@ void AttributeController::recalculateDerivedItems( bool isFormValueChange, bool std::shared_ptr item = formItemsIterator.value(); QgsExpression exp = item->editableExpression(); - if ( !exp.expression().isEmpty() && !item->field().defaultValueDefinition().applyOnUpdate() ) + if ( !exp.expression().isEmpty() ) { bool editable = item->isEditable(); exp.prepare( &expressionContext );