From 79ab25a25c7e102185dd53e8d217232ddff353b6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 20 Dec 2019 14:44:40 +0100 Subject: [PATCH] Gui: set/get number of decimals of a quantity spin box --- src/Gui/QuantitySpinBox.cpp | 15 +++++++++++++++ src/Gui/QuantitySpinBox.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index 825d9d3fb0..4df87365cf 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -682,6 +682,21 @@ void QuantitySpinBox::setRange(double minimum, double maximum) d->maximum = maximum; } +int QuantitySpinBox::decimals() const +{ + Q_D(const QuantitySpinBox); + return d->quantity.getFormat().precision; +} + +void QuantitySpinBox::setDecimals(int v) +{ + Q_D(QuantitySpinBox); + Base::QuantityFormat f = d->quantity.getFormat(); + f.precision = v; + d->quantity.setFormat(f); + updateText(d->quantity); +} + QAbstractSpinBox::StepEnabled QuantitySpinBox::stepEnabled() const { Q_D(const QuantitySpinBox); diff --git a/src/Gui/QuantitySpinBox.h b/src/Gui/QuantitySpinBox.h index d57070919c..23714bfb99 100644 --- a/src/Gui/QuantitySpinBox.h +++ b/src/Gui/QuantitySpinBox.h @@ -91,6 +91,11 @@ public: /// Sets the value of the maximum property void setMaximum(double max); + /// Gets the number of decimals + int decimals() const; + /// Sets the number of decimals + void setDecimals(int v); + /// Gets the path of the bound property QString boundToName() const; /// Sets the path of the bound property