瀏覽代碼

Remove warning output when double slider range is bound to double max

toInt was warning the developer that it failed to use ints to represent
the double value. This is to track issues with the single step.

In this case (ctkDoubleSlider::setRange(-DOUBLE_MAX, DOUBLE_MAX);), the
limitation does not come from the single step, it is simply expected to
fail and there is nothing we can do about it (expected behavior).

Therefore we do not print error messages.

See Slicer issue 3755
Julien Finet 10 年之前
父節點
當前提交
5fead84624
共有 2 個文件被更改,包括 12 次插入4 次删除
  1. 5 1
      Libs/Widgets/ctkDoubleRangeSlider.cpp
  2. 7 3
      Libs/Widgets/ctkDoubleSlider.cpp

+ 5 - 1
Libs/Widgets/ctkDoubleRangeSlider.cpp

@@ -138,7 +138,11 @@ int ctkDoubleRangeSliderPrivate::toInt(double doubleValue)const
   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)
+  static const double maxDouble = std::numeric_limits<double>::max();
+  if ( (tmp < minInt || tmp > maxInt) &&
+       // If the value is the min or max double, there is no need
+       // to warn. It is expected that the number is outside of bounds.
+       (doubleValue != -maxDouble && doubleValue != maxDouble) )
     {
     qWarning() << __FUNCTION__ << ": value " << doubleValue
                << " for singleStep " << this->SingleStep

+ 7 - 3
Libs/Widgets/ctkDoubleSlider.cpp

@@ -130,11 +130,15 @@ int ctkDoubleSliderPrivate::toInt(double doubleValue)const
   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)
+  static const double maxDouble = std::numeric_limits<double>::max();
+  if ( (tmp < minInt || tmp > maxInt) &&
+       // If the value is the min or max double, there is no need
+       // to warn. It is expected that the number is outside of bounds.
+       (doubleValue != -maxDouble && doubleValue != maxDouble) )
     {
     qWarning() << __FUNCTION__ << ": value " << doubleValue
-              << " for singleStep " << this->SingleStep
-              << " is out of integer bounds !";
+               << " for singleStep " << this->SingleStep
+               << " is out of integer bounds !";
     }
 #endif
   tmp = qBound(minInt, tmp, maxInt);