From f9128d973f60e225045bebb97a19d292395b865d Mon Sep 17 00:00:00 2001
From: Thierry Bastian <thierry.bastian@nokia.com>
Date: Fri, 10 Jul 2009 11:24:35 +0200
Subject: QDoubleSpinBox: make sure people can't choose too many decimals

Maximum number of decimals is DBL_MAX_10_EXP + DBL_DIG

Task-number: 257291
---
 src/gui/widgets/qspinbox.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/gui/widgets/qspinbox.cpp b/src/gui/widgets/qspinbox.cpp
index e069a21..3933272 100644
--- a/src/gui/widgets/qspinbox.cpp
+++ b/src/gui/widgets/qspinbox.cpp
@@ -50,6 +50,7 @@
 #include <qdebug.h>
 
 #include <math.h>
+#include <float.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -823,8 +824,8 @@ void QDoubleSpinBox::setRange(double minimum, double maximum)
      Sets how many decimals the spinbox will use for displaying and
      interpreting doubles.
 
-     \warning The results might not be reliable with very high values
-     for \a decimals.
+     \warning The maximum value for \a decimals is DBL_MAX_10_EXP +
+     DBL_DIG (ie. 323) because of the limitations of the double type.
 
      Note: The maximum, minimum and value might change as a result of
      changing this property.
@@ -840,7 +841,7 @@ int QDoubleSpinBox::decimals() const
 void QDoubleSpinBox::setDecimals(int decimals)
 {
     Q_D(QDoubleSpinBox);
-    d->decimals = qMax(0, decimals);
+    d->decimals = qBound(0, decimals, DBL_MAX_10_EXP + DBL_DIG);
 
     setRange(minimum(), maximum()); // make sure values are rounded
     setValue(value());
-- 
cgit v0.12