From eff45035a76e3b61e2c64a09a8864516c922b6c1 Mon Sep 17 00:00:00 2001 From: Paddle Date: Wed, 18 Oct 2023 16:07:15 +0200 Subject: [PATCH] Add a 'value' double to EditableDatumLabel such that we can store the raw value of the spinbox. For the case where editStopped but we still need to access value. Also write the value in the SoDatumLabel in case we stopEdit. --- src/Gui/EditableDatumLabel.cpp | 15 ++++++++++++++- src/Gui/EditableDatumLabel.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Gui/EditableDatumLabel.cpp b/src/Gui/EditableDatumLabel.cpp index ac40d13698..47464541e2 100644 --- a/src/Gui/EditableDatumLabel.cpp +++ b/src/Gui/EditableDatumLabel.cpp @@ -51,6 +51,7 @@ EditableDatumLabel::EditableDatumLabel(View3DInventorViewer* view, : isSet(false) , autoDistance(autoDistance) , autoDistanceReverse(false) + , value(0.0) , viewer(view) , spinBox(nullptr) , cameraSensor(nullptr) @@ -160,6 +161,7 @@ void EditableDatumLabel::startEdit(double val, QObject* eventFilteringObj, bool connect(spinBox, qOverload(&QuantitySpinBox::valueChanged), this, [this](double value) { this->isSet = true; + this->value = value; Q_EMIT this->valueChanged(value); }); } @@ -167,6 +169,15 @@ void EditableDatumLabel::startEdit(double val, QObject* eventFilteringObj, bool void EditableDatumLabel::stopEdit() { if (spinBox) { + // write the spinbox value in the label. + Base::Quantity quantity = spinBox->value(); + + double factor{}; + QString unitStr; + QString valueStr; + valueStr = quantity.getUserString(factor, unitStr); + label->string = SbString(valueStr.toUtf8().constData()); + spinBox->deleteLater(); spinBox = nullptr; } @@ -180,7 +191,8 @@ bool EditableDatumLabel::isInEdit() double EditableDatumLabel::getValue() { - return spinBox->rawValue(); + // We use value rather than spinBox->rawValue() in case edit stopped. + return value; } void EditableDatumLabel::setSpinboxValue(double val, const Base::Unit& unit) @@ -192,6 +204,7 @@ void EditableDatumLabel::setSpinboxValue(double val, const Base::Unit& unit) QSignalBlocker block(spinBox); spinBox->setValue(Base::Quantity(val, unit)); + value = val; positionSpinbox(); if (spinBox->hasFocus()) { diff --git a/src/Gui/EditableDatumLabel.h b/src/Gui/EditableDatumLabel.h index d5cc18ed04..63c520fbd2 100644 --- a/src/Gui/EditableDatumLabel.h +++ b/src/Gui/EditableDatumLabel.h @@ -75,6 +75,7 @@ public: bool isSet; bool autoDistance; bool autoDistanceReverse; + double value; // NOLINTEND Q_SIGNALS: