From: nds Date: Thu, 12 Feb 2015 12:02:27 +0000 (+0300) Subject: Issue #394 Undo-ing a Sketch element X-Git-Tag: V_1.1.0~198 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6a7b7e89852489a242ed25f5808d9306b00cc7d9;p=modules%2Fshaper.git Issue #394 Undo-ing a Sketch element Using the valueChanged() signal of the model widget to update the sketch feature visibility on creation. --- diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 73a422d94..f9e894085 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -30,6 +30,8 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_ myIsValueDefault = !theData->getProperty(ATTR_DEFAULT).empty(); myIsComputedDefault = false; myAttributeID = theData ? theData->widgetId() : ""; + + connect(this, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged())); } bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const @@ -71,6 +73,13 @@ void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted) } } +void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue) +{ + myFeature = theFeature; + if (theToStoreValue) + storeValue(); +} + bool ModuleBase_ModelWidget::focusTo() { QList aControls = getControls(); @@ -122,3 +131,9 @@ bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) return QObject::eventFilter(theObject, theEvent); } + +//************************************************************** +void ModuleBase_ModelWidget::onWidgetValuesChanged() +{ + storeValue(); +} diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 87fcd1db7..6a3e63894 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -72,9 +72,6 @@ Q_OBJECT return false; } - /// Saves the internal parameters to the given feature - virtual bool storeValue() const = 0; - /// Restore value from attribute data to the widget's control virtual bool restoreValue() = 0; @@ -127,10 +124,8 @@ Q_OBJECT } /// Set feature which is processing by active operation - void setFeature(const FeaturePtr& theFeature) - { - myFeature = theFeature; - } + /// \param theToStoreValue a value about necessity to store the widget value to the feature + void setFeature(const FeaturePtr& theFeature, const bool theToStoreValue = false); /// Editing mode depends on mode of current operation. This value is defined by it. void setEditingMode(bool isEditing) { myIsEditing = isEditing; } @@ -142,9 +137,6 @@ signals: /// The signal about widget values changed void valuesChanged(); - /// The signal about widget values changed - void controlValuesChanged(); - /// The signal about key release on the control, that corresponds to the attribute /// \param theEvent key release event void keyReleased(QKeyEvent* theEvent); @@ -158,6 +150,10 @@ signals: void focusOutWidget(ModuleBase_ModelWidget* theWidget); protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const = 0; + /// \brief Set the attribute name /// \param theAttribute the string value with attribute name void setAttributeID(const std::string& theAttribute) @@ -176,6 +172,10 @@ signals: /// \param theObj is object for moving void moveObject(ObjectPtr theObj) const; +protected slots: + /// Processing of values changed in model widget by store the current value to the feature + void onWidgetValuesChanged(); + protected: /// The attribute name of the model feature diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.h b/src/ModuleBase/ModuleBase_WidgetBoolValue.h index 37b15780d..518d9a163 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.h +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.h @@ -31,14 +31,17 @@ Q_OBJECT virtual ~ModuleBase_WidgetBoolValue(); - virtual bool storeValue() const; - virtual bool restoreValue(); virtual QList getControls() const; QWidget* getControl() const; +protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const; + private: /// The check box QCheckBox* myCheckBox; diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.h b/src/ModuleBase/ModuleBase_WidgetChoice.h index 3f13cc4af..18fcb55bd 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.h +++ b/src/ModuleBase/ModuleBase_WidgetChoice.h @@ -39,8 +39,6 @@ Q_OBJECT virtual ~ModuleBase_WidgetChoice(); - virtual bool storeValue() const; - virtual bool restoreValue(); virtual bool focusTo(); @@ -56,6 +54,11 @@ Q_OBJECT /// \return a controls list virtual QList getControls() const; +protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const; + private slots: /// Slot called on combo box index change void onCurrentIndexChanged(int theIndex); diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 6d17b4153..6b1f52ed3 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -94,7 +94,6 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, aControlLay->setStretch(1, 1); connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); - connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(controlValuesChanged())); } ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue() diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h index c9032e66a..9c7804bf9 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -37,10 +37,6 @@ Q_OBJECT virtual ~ModuleBase_WidgetDoubleValue(); - //! Saves the internal parameters to the given feature - // \return True in success - virtual bool storeValue() const; - //! Read value of corresponded attribute from data model to the input control // \return True in success virtual bool restoreValue(); @@ -61,7 +57,12 @@ Q_OBJECT // it gives him a 0,5 second to finish typing, when sends valueChnaged() signal // void onValueChanged(); - protected: +protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const; + +protected: /// Container for thw widget controls QWidget* myContainer; diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.h b/src/ModuleBase/ModuleBase_WidgetFileSelector.h index 3b183d703..5a628286d 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.h @@ -46,8 +46,6 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelW const std::string& theParentId); virtual ~ModuleBase_WidgetFileSelector(); - virtual bool storeValue() const; - virtual bool restoreValue(); QWidget* getControl() const; @@ -65,6 +63,11 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelW /// Processing of path changing void onPathChanged(); +protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const; + protected: /// Returns string containing formats QString formatsString() const; diff --git a/src/ModuleBase/ModuleBase_WidgetLabel.h b/src/ModuleBase/ModuleBase_WidgetLabel.h index 8d7d4281f..fd0112ff1 100644 --- a/src/ModuleBase/ModuleBase_WidgetLabel.h +++ b/src/ModuleBase/ModuleBase_WidgetLabel.h @@ -33,11 +33,6 @@ Q_OBJECT /// It returns false because this is an info widget virtual bool canSetValue() const { return false; }; - virtual bool storeValue() const - { - return true; - } - virtual bool restoreValue() { return true; @@ -50,6 +45,14 @@ Q_OBJECT /// This control doesn't accept focus virtual bool focusTo() { return false; } +protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const + { + return true; + } + private: /// A label control QLabel* myLabel; diff --git a/src/ModuleBase/ModuleBase_WidgetLineEdit.h b/src/ModuleBase/ModuleBase_WidgetLineEdit.h index a5955f84c..657b22be0 100644 --- a/src/ModuleBase/ModuleBase_WidgetLineEdit.h +++ b/src/ModuleBase/ModuleBase_WidgetLineEdit.h @@ -38,8 +38,6 @@ class MODULEBASE_EXPORT ModuleBase_WidgetLineEdit : public ModuleBase_ModelWidge const std::string& theParentId); virtual ~ModuleBase_WidgetLineEdit(); - virtual bool storeValue() const; - virtual bool restoreValue(); QWidget* getControl() const; @@ -50,7 +48,12 @@ class MODULEBASE_EXPORT ModuleBase_WidgetLineEdit : public ModuleBase_ModelWidge /// A slot for processing text changed event void onTextChanged(); - private: +protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const; + +private: /// A line edit control QLineEdit* myLineEdit; diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 8d8c9e2c8..3b092d424 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -62,9 +62,6 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Model const std::string& theParentId); virtual ~ModuleBase_WidgetMultiSelector(); - /// Saves the internal parameters to the given feature - virtual bool storeValue() const; - virtual bool restoreValue(); /// Returns the internal parent wiget control, that can be shown anywhere @@ -95,7 +92,11 @@ protected slots: void onListSelection(); protected: - /// Provide filtering of selected shapes + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const; + + /// Provide filtering of selected shapes /// \param theShapesToFilter source list of shapes /// \param theResult result list of shapes void filterShapes(const NCollection_List& theShapesToFilter, diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index b4885d240..aa0c75f13 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -71,9 +71,6 @@ Q_OBJECT virtual ~ModuleBase_WidgetShapeSelector(); - /// Saves the internal parameters to the given feature - virtual bool storeValue() const; - virtual bool restoreValue(); /// Defines if it is supposed that the widget should interact with the viewer. @@ -116,6 +113,10 @@ Q_OBJECT void onSelectionChanged(); protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const; + /// The methiod called when widget is activated virtual void activateCustom(); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index e1e18df38..f3ccdf4f7 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -200,8 +200,7 @@ void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation) void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation) { - if (PartSet_SketcherMgr::isSketchOperation(theOperation) || - PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) { + if (PartSet_SketcherMgr::isSketchOperation(theOperation)) { mySketchMgr->stopSketch(theOperation); } else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) { diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 70db7acc3..d601d5a6f 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -737,9 +737,9 @@ void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect) const QList& aWidgets = aPropertyPanel->modelWidgets(); foreach (ModuleBase_ModelWidget* aWidget, aWidgets) { if (isToConnect) - connect(aWidget, SIGNAL(controlValuesChanged()), this, SLOT(onValuesChangedInPropertyPanel())); + connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel())); else - disconnect(aWidget, SIGNAL(controlValuesChanged()), this, SLOT(onValuesChangedInPropertyPanel())); + disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel())); } } } diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 34560cdc4..ed4064004 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -75,7 +75,6 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, aGroupLay->addWidget(myXSpin, 0, 1); connect(myXSpin, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); - connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(controlValuesChanged())); } { QLabel* aLabel = new QLabel(myGroupBox); @@ -90,7 +89,6 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, aGroupLay->addWidget(myYSpin, 1, 1); connect(myYSpin, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); - connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(controlValuesChanged())); } } @@ -126,7 +124,7 @@ bool PartSet_WidgetPoint2D::setPoint(double theX, double theY) myYSpin->blockSignals(false); this->blockSignals(isBlocked); - emit valuesChanged(); + storeValue(); return true; } diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index def3b2bb7..a4e732385 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -52,8 +52,6 @@ Q_OBJECT /// \param theValue the wrapped widget value virtual bool setSelection(ModuleBase_ViewerPrs theValue); - virtual bool storeValue() const; - virtual bool restoreValue(); /// Returns the internal parent wiget control, that can be shown anywhere @@ -109,6 +107,10 @@ protected slots: void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const; + /// The methiod called when widget is activated virtual void activateCustom(); diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index b32ba1443..54887f018 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -34,7 +34,6 @@ PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent, // Reconnect to local slot disconnect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); connect(mySpinBox, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); - connect(mySpinBox, SIGNAL(valueChanged(double)), this, SLOT(controlValuesChanged())); } PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance() @@ -57,7 +56,7 @@ void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, mySpinBox->blockSignals(true); mySpinBox->setValue(aRadius); mySpinBox->blockSignals(false); - emit valuesChanged(); + storeValue(); } } diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h index 222bac774..f8e9d75b1 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.h +++ b/src/PartSet/PartSet_WidgetShapeSelector.h @@ -35,8 +35,6 @@ Q_OBJECT virtual ~PartSet_WidgetShapeSelector() {} - virtual bool storeValue() const; - /// Set sketcher /// \param theSketch a sketcher object void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; } @@ -45,6 +43,10 @@ Q_OBJECT CompositeFeaturePtr sketch() const { return mySketch; } protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const; + /// Check the selected with validators if installed virtual bool isValid(ObjectPtr theObj, std::shared_ptr theShape); @@ -73,9 +75,6 @@ Q_OBJECT virtual ~PartSet_WidgetConstraintShapeSelector() {} - /// Saves the internal parameters to the given feature - virtual bool storeValue() const; - /// Set sketcher /// \param theSketch a sketcher object void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; } @@ -83,6 +82,11 @@ Q_OBJECT /// Retrurns installed sketcher CompositeFeaturePtr sketch() const { return mySketch; } +protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const; + private: /// Pointer to a sketch CompositeFeaturePtr mySketch; diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index d7b412f16..0fa5c18f0 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -48,11 +48,6 @@ Q_OBJECT virtual ~PartSet_WidgetSketchLabel(); - virtual bool storeValue() const - { - return true; - } - virtual bool restoreValue() { return true; @@ -82,6 +77,13 @@ signals: void planeSelected(const std::shared_ptr& thePln); protected: + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValue() const + { + return true; + } + /// The methiod called when widget is activated virtual void activateCustom(); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 84d3d6a10..f7b254dea 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -651,13 +651,10 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation) QList aWidgets = aFactory.getModelWidgets(); foreach (ModuleBase_ModelWidget* aWidget, aWidgets) { - aWidget->setFeature(theOperation->feature()); + bool isStoreValue = !theOperation->isEditOperation() && + aWidget->isValueDefault() && !aWidget->isComputedDefault(); + aWidget->setFeature(theOperation->feature(), isStoreValue); aWidget->enableFocusProcessing(); - QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged())); - // Init default values - if (!theOperation->isEditOperation() && aWidget->isValueDefault() && !aWidget->isComputedDefault()) { - aWidget->storeValue(); - } } myPropertyPanel->setModelWidgets(aWidgets); @@ -1258,24 +1255,6 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) } } -//************************************************************** -void XGUI_Workshop::onWidgetValuesChanged() -{ - ModuleBase_Operation* anOperation = myOperationMgr->currentOperation(); - FeaturePtr aFeature = anOperation->feature(); - - ModuleBase_ModelWidget* aSenderWidget = dynamic_cast(sender()); - - const QList& aWidgets = myPropertyPanel->modelWidgets(); - QList::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end(); - for (; anIt != aLast; anIt++) { - ModuleBase_ModelWidget* aCustom = *anIt; - if (aCustom && (aCustom == aSenderWidget)) { - aCustom->storeValue(); - } - } -} - //************************************************************** void XGUI_Workshop::activatePart(ResultPartPtr theFeature) { diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 1cf400d0f..b492fa113 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -351,9 +351,6 @@ signals: /// \param isChecked a state of toggle if the action is checkable void onContextMenuCommand(const QString& theId, bool isChecked); - /// Processing of values changed in model widget - void onWidgetValuesChanged(); - /// Set waiting cursor void onStartWaiting();