From 745e2525a61873031e831b6c7ca6e569606ac253 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 21 Oct 2015 18:18:09 +0300 Subject: [PATCH] A correction for the parameters: after entering the parameter name, when the value input gets the focus, an error message is displayed (unnexpected EOF while parsing (, line 0) while the user didn't type yet anything. It's not fair. The decision: do not set the editor value to the feature attribute by the control activation. --- src/ModuleBase/ModuleBase_ModelWidget.cpp | 24 +++++++++++-------- src/ModuleBase/ModuleBase_ModelWidget.h | 4 ++++ .../ModuleBase_WidgetExprEditor.cpp | 5 ++++ src/ModuleBase/ModuleBase_WidgetExprEditor.h | 3 +++ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 721c6c7b0..c84b8e646 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -122,20 +122,24 @@ void ModuleBase_ModelWidget::activate() // It should happens in the creation mode only because all fields are filled in the edition mode if (!isEditingMode()) { AttributePtr anAttribute = myFeature->data()->attribute(myAttributeID); - if (anAttribute.get() != NULL && !anAttribute->isInitialized()) { - if (isComputedDefault()) { - if (myFeature->compute(myAttributeID)) { - restoreValue(); - } - } - else { - storeValue(); - } - } + if (anAttribute.get() != NULL && !anAttribute->isInitialized()) + initializeValueByActivate(); } activateCustom(); } +void ModuleBase_ModelWidget::initializeValueByActivate() +{ + if (isComputedDefault()) { + if (myFeature->compute(myAttributeID)) { + restoreValue(); + } + } + else { + storeValue(); + } +} + QWidget* ModuleBase_ModelWidget::getControlAcceptingFocus(const bool isFirst) { QWidget* aControl = 0; diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index c805502d1..f1d257362 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -225,6 +225,10 @@ protected: /// \param theState a new state void setValueState(const ValueState& theState); + /// Compute the feature default value and fill the controls with it + /// or store the control value to the feature + virtual void initializeValueByActivate(); + /// Saves the internal parameters to the given feature. Emits signals before and after store /// \return True in success bool storeValue(); diff --git a/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp b/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp index a7e7878e6..b11bd6714 100644 --- a/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp @@ -263,6 +263,10 @@ ModuleBase_WidgetExprEditor::~ModuleBase_WidgetExprEditor() { } +void ModuleBase_WidgetExprEditor::initializeValueByActivate() +{ +} + bool ModuleBase_WidgetExprEditor::storeValueCustom() const { // A rare case when plugin was not loaded. @@ -270,6 +274,7 @@ bool ModuleBase_WidgetExprEditor::storeValueCustom() const return false; DataPtr aData = myFeature->data(); AttributeStringPtr aStringAttr = aData->string(attributeID()); + QString aWidgetValue = myEditor->toPlainText(); aStringAttr->setValue(aWidgetValue.toStdString()); updateObject(myFeature); diff --git a/src/ModuleBase/ModuleBase_WidgetExprEditor.h b/src/ModuleBase/ModuleBase_WidgetExprEditor.h index eb2ff9aa1..69f36b46c 100644 --- a/src/ModuleBase/ModuleBase_WidgetExprEditor.h +++ b/src/ModuleBase/ModuleBase_WidgetExprEditor.h @@ -135,6 +135,9 @@ protected slots: void onTextChanged(); protected: + /// Do not initialize value on the widget activation + virtual void initializeValueByActivate(); + /// Saves the internal parameters to the given feature /// \return True in success virtual bool storeValueCustom() const; -- 2.39.2