ソースを参照

ctkDoubleRangeSlider better support of large double values

Apply the same check as in ctkDoubleSlider.
Julien Finet 12 年 前
コミット
9a9303a16a
共有2 個のファイルを変更した15 個の追加1 個の削除を含む
  1. 12 0
      Libs/Widgets/ctkDoubleRangeSlider.cpp
  2. 3 1
      Libs/Widgets/ctkDoubleSlider.cpp

+ 12 - 0
Libs/Widgets/ctkDoubleRangeSlider.cpp

@@ -125,7 +125,19 @@ void ctkDoubleRangeSliderPrivate::connectSlider()
 int ctkDoubleRangeSliderPrivate::toInt(double doubleValue)const
 {
   double tmp = doubleValue / this->SingleStep;
+  static const double minInt = std::numeric_limits<int>::min();
+  static const double maxInt = std::numeric_limits<int>::max();
+#ifndef QT_NO_DEBUG
+  if (tmp < minInt || tmp > maxInt)
+    {
+    qWarning() << __FUNCTION__ << ": value " << doubleValue
+               << " for singleStep " << this->SingleStep
+               << " is out of integer bounds !";
+    }
+#endif
+  tmp = qBound(minInt, tmp, maxInt);
   int intValue = qRound(tmp);
+  //qDebug() << __FUNCTION__ << doubleValue << tmp << intValue;
   return intValue;
 }
 

+ 3 - 1
Libs/Widgets/ctkDoubleSlider.cpp

@@ -122,7 +122,9 @@ int ctkDoubleSliderPrivate::toInt(double doubleValue)const
 #ifndef QT_NO_DEBUG
   if (tmp < minInt || tmp > maxInt)
     {
-    qWarning("ctkDoubleSliderPrivate::toInt value out of bounds !");
+    qWarning() << __FUNCTION__ << ": value " << doubleValue
+              << " for singleStep " << this->SingleStep
+              << " is out of integer bounds !";
     }
 #endif
   tmp = qBound(minInt, tmp, maxInt);