From: nds Date: Thu, 12 Feb 2015 13:00:53 +0000 (+0300) Subject: Issue #394 Undo-ing a Sketch element X-Git-Tag: V_1.1.0~197 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2af64c581d1ed96ce5ecc455f27a537e3a63fcb5;p=modules%2Fshaper.git Issue #394 Undo-ing a Sketch element Reset for the widget value by mouse leaving the active window. --- diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index f9e894085..4c672c5b6 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -27,7 +27,7 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_ : QObject(theParent), myParentId(theParentId) { - myIsValueDefault = !theData->getProperty(ATTR_DEFAULT).empty(); + myDefaultValue = theData->getProperty(ATTR_DEFAULT); myIsComputedDefault = false; myAttributeID = theData ? theData->widgetId() : ""; diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 6a3e63894..706793035 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -43,6 +43,9 @@ Q_OBJECT { } + /// Fills the widget with default values + virtual void reset() {}; + /// Returns the state whether the attribute of the feature is initialized /// \param theObject a model feature to be checked /// \return the boolean result @@ -55,7 +58,7 @@ Q_OBJECT /// Returns true, if default value of the widget is defined in the XML and it is not the /// computed value /// \return the boolean result - bool isValueDefault() { return myIsValueDefault; } + bool isValueDefault() { return !myDefaultValue.empty(); } /// Defines if it is supposed that the widget should interact with the viewer. virtual bool isViewerSelector() { return false; } @@ -190,8 +193,9 @@ protected slots: /// Value should be computed on execute, like radius for circle's constraint (can not be zero) bool myIsComputedDefault; - /// the default value is defined in the XML for this attribute - bool myIsValueDefault; + /// the default value, which is defined in the XML for this attribute + std::string myDefaultValue; + /// Flag which shows that current operation is in editing mode bool myIsEditing; }; diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 6b1f52ed3..cd1cc4565 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -79,8 +79,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, mySpinBox->setSingleStep(aStepVal); } - aProp = theData->getProperty(ATTR_DEFAULT); - double aDefVal = QString::fromStdString(aProp).toDouble(&isOk); + double aDefVal = QString::fromStdString(myDefaultValue).toDouble(&isOk); if (isOk) { mySpinBox->setValue(aDefVal); } else if (aProp == DOUBLE_WDG_DEFAULT_COMPUTED){ @@ -100,6 +99,13 @@ ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue() { } +void ModuleBase_WidgetDoubleValue::reset() +{ + bool isOk; + double aDefValue = QString::fromStdString(myDefaultValue).toDouble(&isOk); + mySpinBox->setValue(isOk ? aDefValue : 0.0); +} + bool ModuleBase_WidgetDoubleValue::storeValue() const { DataPtr aData = myFeature->data(); diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h index 9c7804bf9..957d289a7 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -37,6 +37,9 @@ Q_OBJECT virtual ~ModuleBase_WidgetDoubleValue(); + /// Fills the widget with default values + virtual void reset(); + //! Read value of corresponded attribute from data model to the input control // \return True in success virtual bool restoreValue(); diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index d601d5a6f..6ce573b0d 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -141,15 +141,29 @@ PartSet_SketcherMgr::~PartSet_SketcherMgr() void PartSet_SketcherMgr::onMouseMoveOverWindow(bool theOverWindow) { + ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation(); + if (!aOperation || aOperation->isEditOperation()) + return; + myIsMouseOverWindow = theOverWindow; if (theOverWindow) myIsPropertyPanelValueChanged = false; - + else { + ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); + ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget(); + if(aActiveWgt) { + aActiveWgt->reset(); + } + } updateVisibilityOfCreatedFeature(); } void PartSet_SketcherMgr::onValuesChangedInPropertyPanel() { + ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation(); + if (!aOperation || aOperation->isEditOperation()) + return; + myIsPropertyPanelValueChanged = true; updateVisibilityOfCreatedFeature(); diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index ed4064004..5788a92c3 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -92,6 +92,15 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, } } +void PartSet_WidgetPoint2D::reset() +{ + bool isOk; + double aDefValue = QString::fromStdString(myDefaultValue).toDouble(&isOk); + + myXSpin->setValue(isOk ? aDefValue : 0.0); + myYSpin->setValue(isOk ? aDefValue : 0.0); +} + PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D() { } diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index a4e732385..b976abf18 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -47,6 +47,9 @@ Q_OBJECT /// Destructor virtual ~PartSet_WidgetPoint2D(); + /// Fills the widget with default values + virtual void reset(); + /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// \param theValue the wrapped widget value diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index 54887f018..086133ded 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -40,6 +40,13 @@ PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance() { } +void PartSet_WidgetPoint2dDistance::reset() +{ + bool isOk; + double aDefValue = QString::fromStdString(myDefaultValue).toDouble(&isOk); + mySpinBox->setValue(isOk ? aDefValue : 0.0); +} + void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, const std::shared_ptr& thePnt) { diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.h b/src/PartSet/PartSet_WidgetPoint2dDistance.h index aa0ce98cd..5ebfb4d1c 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.h +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.h @@ -47,6 +47,9 @@ Q_OBJECT virtual ~PartSet_WidgetPoint2dDistance(); + /// Fills the widget with default values + virtual void reset(); + /// The methiod called when widget is deactivated virtual void deactivate();