From 050356aa55ec43380d9ae43a9ccfb07afd22c4ac Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 9 Aug 2020 11:22:47 +0200 Subject: [PATCH] plugin: [skip ci] add new signal textChanged() to QuantitySpinBox --- src/Gui/QuantitySpinBox.cpp | 11 ++++++++--- src/Gui/QuantitySpinBox.h | 4 ++++ src/Tools/plugins/widget/customwidgets.cpp | 17 +++++++++++------ src/Tools/plugins/widget/customwidgets.h | 8 +++++++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index 35fcd8aece..f2b6f057eb 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -640,7 +640,7 @@ void QuantitySpinBox::updateFromCache(bool notify) if (d->pendingEmit) { double factor; const Base::Quantity& res = d->cached; - getUserString(res, factor, d->unitStr); + QString text = getUserString(res, factor, d->unitStr); d->unitValue = res.getValue() / factor; d->quantity = res; @@ -649,6 +649,7 @@ void QuantitySpinBox::updateFromCache(bool notify) d->pendingEmit = false; valueChanged(res); valueChanged(res.getValue()); + textChanged(text); } } } @@ -670,8 +671,12 @@ void QuantitySpinBox::setUnit(const Base::Unit &unit) void QuantitySpinBox::setUnitText(const QString& str) { - Base::Quantity quant = Base::Quantity::parse(str); - setUnit(quant.getUnit()); + try { + Base::Quantity quant = Base::Quantity::parse(str); + setUnit(quant.getUnit()); + } + catch (const Base::Exception&) { + } } QString QuantitySpinBox::unitText(void) diff --git a/src/Gui/QuantitySpinBox.h b/src/Gui/QuantitySpinBox.h index e1cfd41e05..4c95deb340 100644 --- a/src/Gui/QuantitySpinBox.h +++ b/src/Gui/QuantitySpinBox.h @@ -174,6 +174,10 @@ Q_SIGNALS: * like: minimum, maximum and/or the right Unit (if specified). */ void valueChanged(double); + /** + * The new value is passed in \a text with unit. + */ + void textChanged(const QString&); /** Gets emitted if formula dialog is about to be opened (true) * or finished (false). */ diff --git a/src/Tools/plugins/widget/customwidgets.cpp b/src/Tools/plugins/widget/customwidgets.cpp index 85e983ff69..357f0cc21f 100644 --- a/src/Tools/plugins/widget/customwidgets.cpp +++ b/src/Tools/plugins/widget/customwidgets.cpp @@ -594,8 +594,8 @@ Quantity Quantity::parse(const QString& str) } double v = QLocale::system().toDouble(txt, &ok); - //if (!ok) - // throw QString("Cannot convert to double"); + //if (!ok && !txt.isEmpty()) + // throw Base::Exception(); return Quantity(v, Unit(unit)); } @@ -801,7 +801,7 @@ public: value = res.getValue(); ok = true; } - catch (...) { + catch (Base::Exception&) { } if (!ok) { @@ -975,7 +975,7 @@ void QuantitySpinBox::updateFromCache(bool notify) if (d->pendingEmit) { double factor; const Base::Quantity& res = d->cached; - getUserString(res, factor, d->unitStr); + QString text = getUserString(res, factor, d->unitStr); d->unitValue = res.getValue() / factor; d->quantity = res; @@ -984,6 +984,7 @@ void QuantitySpinBox::updateFromCache(bool notify) d->pendingEmit = false; valueChanged(res); valueChanged(res.getValue()); + textChanged(text); } } } @@ -1005,8 +1006,12 @@ void QuantitySpinBox::setUnit(const Base::Unit &unit) void QuantitySpinBox::setUnitText(const QString& str) { - Base::Quantity quant = Base::Quantity::parse(str); - setUnit(quant.getUnit()); + try { + Base::Quantity quant = Base::Quantity::parse(str); + setUnit(quant.getUnit()); + } + catch (const Base::Exception&) { + } } QString QuantitySpinBox::unitText(void) diff --git a/src/Tools/plugins/widget/customwidgets.h b/src/Tools/plugins/widget/customwidgets.h index 8206568baf..b032f43a7d 100644 --- a/src/Tools/plugins/widget/customwidgets.h +++ b/src/Tools/plugins/widget/customwidgets.h @@ -41,6 +41,8 @@ #include namespace Base { + class Exception { + }; class Unit{ public: Unit(); @@ -369,7 +371,7 @@ class QuantitySpinBox : public QAbstractSpinBox Q_PROPERTY(double maximum READ maximum WRITE setMaximum) Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep) Q_PROPERTY(double rawValue READ rawValue WRITE setValue NOTIFY valueChanged) - Q_PROPERTY(Base::Quantity value READ value WRITE setValue NOTIFY valueChanged USER true) + //Q_PROPERTY(Base::Quantity value READ value WRITE setValue NOTIFY valueChanged USER true) public: explicit QuantitySpinBox(QWidget *parent = 0); @@ -473,6 +475,10 @@ Q_SIGNALS: * like: minimum, maximum and/or the right Unit (if specified). */ void valueChanged(double); + /** + * The new value is passed in \a text with unit. + */ + void textChanged(const QString&); /** Gets emitted if formula dialog is about to be opened (true) * or finished (false). */