summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-01-12 14:09:42 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-01-12 14:40:41 (GMT)
commit12e320a7a3a5ca93dd5287315571db1d1728e322 (patch)
tree37e46eba29bf7e0524900a457cb342724245c133 /src/gui/widgets
parent4c85bf275c9d472a17cc9210aebf6eb880be740a (diff)
downloadQt-12e320a7a3a5ca93dd5287315571db1d1728e322.zip
Qt-12e320a7a3a5ca93dd5287315571db1d1728e322.tar.gz
Qt-12e320a7a3a5ca93dd5287315571db1d1728e322.tar.bz2
Significant digits were lost in QDoubleSpinBox range when changing precision
When setting the range, the actual value precision was lost because the min and max were saved after being formatted to the current precison (decimals property), thus losing information. We now keep the user original values, and use these whenever the decimals property is changed. Auto-test included. Reviewed-by: leo Task-number: QTBUG-6496
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qspinbox.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/gui/widgets/qspinbox.cpp b/src/gui/widgets/qspinbox.cpp
index 50b225c..f382f96 100644
--- a/src/gui/widgets/qspinbox.cpp
+++ b/src/gui/widgets/qspinbox.cpp
@@ -99,6 +99,10 @@ public:
Q_Q(QDoubleSpinBox);
q->setInputMethodHints(Qt::ImhFormattedNumbersOnly);
}
+
+ // When fiddling with the decimals property, we may lose precision in these properties.
+ double actualMin;
+ double actualMax;
};
@@ -762,6 +766,7 @@ double QDoubleSpinBox::minimum() const
void QDoubleSpinBox::setMinimum(double minimum)
{
Q_D(QDoubleSpinBox);
+ d->actualMin = minimum;
const QVariant m(d->round(minimum));
d->setRange(m, (d->variantCompare(d->maximum, m) > 0 ? d->maximum : m));
}
@@ -792,6 +797,7 @@ double QDoubleSpinBox::maximum() const
void QDoubleSpinBox::setMaximum(double maximum)
{
Q_D(QDoubleSpinBox);
+ d->actualMax = maximum;
const QVariant m(d->round(maximum));
d->setRange((d->variantCompare(d->minimum, m) < 0 ? d->minimum : m), m);
}
@@ -813,6 +819,8 @@ void QDoubleSpinBox::setMaximum(double maximum)
void QDoubleSpinBox::setRange(double minimum, double maximum)
{
Q_D(QDoubleSpinBox);
+ d->actualMin = minimum;
+ d->actualMax = maximum;
d->setRange(QVariant(d->round(minimum)), QVariant(d->round(maximum)));
}
@@ -843,7 +851,7 @@ void QDoubleSpinBox::setDecimals(int decimals)
Q_D(QDoubleSpinBox);
d->decimals = qBound(0, decimals, DBL_MAX_10_EXP + DBL_DIG);
- setRange(minimum(), maximum()); // make sure values are rounded
+ setRange(d->actualMin, d->actualMax); // make sure values are rounded
setValue(value());
}
@@ -1051,8 +1059,10 @@ QVariant QSpinBoxPrivate::validateAndInterpret(QString &input, int &pos,
QDoubleSpinBoxPrivate::QDoubleSpinBoxPrivate()
{
- minimum = QVariant(0.0);
- maximum = QVariant(99.99);
+ actualMin = 0.0;
+ actualMax = 99.99;
+ minimum = QVariant(actualMin);
+ maximum = QVariant(actualMax);
value = minimum;
singleStep = QVariant(1.0);
decimals = 2;