From cedbcc9f78684b65af0d19da1066710314374f93 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 16 Feb 2015 11:39:28 +0300 Subject: [PATCH] Issue #394 Undo-ing a Sketch element The spin box value set without emitting a signal about valueChanged is necessary for some controls. So, it is moved to ModuleBase_Tools. --- src/ModuleBase/ModuleBase_Tools.cpp | 8 ++++++++ src/ModuleBase/ModuleBase_Tools.h | 7 +++++++ .../ModuleBase_WidgetDoubleValue.cpp | 6 ++---- src/ModuleBase/ModuleBase_WidgetEditor.cpp | 4 +--- src/PartSet/PartSet_WidgetPoint2d.cpp | 19 ++++++------------- src/PartSet/PartSet_WidgetPoint2d.h | 5 ----- src/PartSet/PartSet_WidgetPoint2dDistance.cpp | 9 +++++---- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 21fa0db1f..38357449c 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace ModuleBase_Tools { @@ -97,6 +98,13 @@ QPixmap lighter(const QString& theIcon, const int theLighterValue) return QPixmap::fromImage(aResult); } +void setSpinValue(QDoubleSpinBox* theSpin, double theValue) +{ + bool isBlocked = theSpin->blockSignals(true); + theSpin->setValue(theValue); + theSpin->blockSignals(isBlocked); +} + } diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index c6ad57e8c..1f55bec75 100644 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -13,6 +13,7 @@ class QWidget; class QLayout; +class QDoubleSpinBox; namespace ModuleBase_Tools { @@ -50,6 +51,12 @@ MODULEBASE_EXPORT QPixmap composite(const QString& theAdditionalIcon, const QStr //! \param theLighterValue a lighter factor //! \return resulting pixmap MODULEBASE_EXPORT QPixmap lighter(const QString& theIcon, const int theLighterValue = 200); + +/// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged) +/// \param theSpin an X or Y coordinate widget +/// \param theValue a new value +MODULEBASE_EXPORT void setSpinValue(QDoubleSpinBox* theSpin, double theValue); + } #endif diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index b18aa2089..8e8843af9 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -106,7 +106,7 @@ void ModuleBase_WidgetDoubleValue::reset() bool isOk; double aDefValue = QString::fromStdString(myDefaultValue).toDouble(&isOk); - mySpinBox->setValue(isOk ? aDefValue : 0.0); + ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0); } bool ModuleBase_WidgetDoubleValue::storeValue() const @@ -123,9 +123,7 @@ bool ModuleBase_WidgetDoubleValue::restoreValue() DataPtr aData = myFeature->data(); AttributeDoublePtr aRef = aData->real(attributeID()); - bool isBlocked = mySpinBox->blockSignals(true); - mySpinBox->setValue(aRef->value()); - mySpinBox->blockSignals(isBlocked); + ModuleBase_Tools::setSpinValue(mySpinBox, aRef->value()); return true; } diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index 7f77acd5a..07c59651d 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -78,9 +78,7 @@ void ModuleBase_WidgetEditor::showPopupEditor() aValue = editedValue(aValue, isDone); if (isDone) { - bool isBlocked = mySpinBox->blockSignals(true); - mySpinBox->setValue(aValue); - mySpinBox->blockSignals(isBlocked); + ModuleBase_Tools::setSpinValue(mySpinBox, aValue); } emit valuesChanged(); emit focusOutWidget(this); diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 51609754f..034d063da 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -98,8 +98,8 @@ void PartSet_WidgetPoint2D::reset() double aDefValue = QString::fromStdString(myDefaultValue).toDouble(&isOk); // it is important to block the spin box control in order to do not through out the // locking of the validating state. - setSpinValue(myXSpin, isOk ? aDefValue : 0.0); - setSpinValue(myYSpin, isOk ? aDefValue : 0.0); + ModuleBase_Tools::setSpinValue(myXSpin, isOk ? aDefValue : 0.0); + ModuleBase_Tools::setSpinValue(myYSpin, isOk ? aDefValue : 0.0); } PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D() @@ -125,8 +125,8 @@ bool PartSet_WidgetPoint2D::setPoint(double theX, double theY) if (fabs(theY) >= MaxCoordinate) return false; - setSpinValue(myXSpin, theX); - setSpinValue(myYSpin, theY); + ModuleBase_Tools::setSpinValue(myXSpin, theX); + ModuleBase_Tools::setSpinValue(myYSpin, theY); storeValue(); return true; @@ -169,8 +169,8 @@ bool PartSet_WidgetPoint2D::restoreValue() double _Y = aPoint->y(); #endif - setSpinValue(myXSpin, aPoint->x()); - setSpinValue(myYSpin, aPoint->y()); + ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x()); + ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y()); return true; } @@ -320,10 +320,3 @@ void PartSet_WidgetPoint2D::onValuesChanged() myWorkshop->operationMgr()->setLockValidating(false); emit valuesChanged(); } - -void PartSet_WidgetPoint2D::setSpinValue(ModuleBase_DoubleSpinBox* theSpin, double theValue) -{ - bool isBlocked = theSpin->blockSignals(true); - theSpin->setValue(theValue); - theSpin->blockSignals(isBlocked); -} diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index c709280e1..de3ab120d 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -131,11 +131,6 @@ private slots: bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape, double& theX, double& theY) const; - /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged) - /// \param theSpin an X or Y coordinate widget - /// \param theValue a new value - static void setSpinValue(ModuleBase_DoubleSpinBox* theSpin, double theValue); - XGUI_Workshop* myWorkshop; QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index 086133ded..756e9a8a9 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -44,7 +45,8 @@ void PartSet_WidgetPoint2dDistance::reset() { bool isOk; double aDefValue = QString::fromStdString(myDefaultValue).toDouble(&isOk); - mySpinBox->setValue(isOk ? aDefValue : 0.0); + + ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0); } void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, @@ -60,9 +62,8 @@ void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, AttributeDoublePtr aReal = aData->real(attributeID()); if (aReal && (aReal->value() != aRadius)) { aReal->setValue(aRadius); - mySpinBox->blockSignals(true); - mySpinBox->setValue(aRadius); - mySpinBox->blockSignals(false); + + ModuleBase_Tools::setSpinValue(mySpinBox, aRadius); storeValue(); } } -- 2.39.2