Просмотр исходного кода

Merge branch 'ctkdoubleslider-toint-warning'

* ctkdoubleslider-toint-warning:
  Remove warning output when double slider range is bound to double max
Julien Finet лет назад: 10
Родитель
Сommit
2af3b0a009
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);