소스 검색

BUG: Assertion when setting the number of decimals to 0.

The number of decimals changes the range and the value of the spinbox. It should be synchronized with the slider to avoid inconsistency.
Julien Finet 15 년 전
부모
커밋
b7b7d42c0e
3개의 변경된 파일33개의 추가작업 그리고 5개의 파일을 삭제
  1. 21 5
      Libs/Widgets/Testing/Cpp/ctkSliderSpinBoxWidgetTest1.cpp
  2. 6 0
      Libs/Widgets/ctkRangeWidget.cpp
  3. 6 0
      Libs/Widgets/ctkSliderSpinBoxWidget.cpp

+ 21 - 5
Libs/Widgets/Testing/Cpp/ctkSliderSpinBoxWidgetTest1.cpp

@@ -79,7 +79,7 @@ int ctkSliderSpinBoxWidgetTest1(int argc, char * argv [] )
   if (!qFuzzyCompare(sliderSpinBox.singleStep(), 0.1) || 
       !qFuzzyCompare(sliderSpinBox.value(), 32.12))
     {
-    std::cerr << "ctkSliderSpinBoxWidget::setMaximum failed."
+    std::cerr << "ctkSliderSpinBoxWidget::setSingleStep failed."
               << sliderSpinBox.singleStep() << " "
               << sliderSpinBox.value() << std::endl;
     return EXIT_FAILURE;
@@ -88,11 +88,15 @@ int ctkSliderSpinBoxWidgetTest1(int argc, char * argv [] )
   sliderSpinBox.setDecimals(1);
 
   if (sliderSpinBox.decimals() != 1 || 
-      !qFuzzyCompare(sliderSpinBox.value(), 32.1))
+      !qFuzzyCompare(sliderSpinBox.value(), 32.1) ||
+      !qFuzzyCompare(sliderSpinBox.minimum(), 10.0) ||
+      !qFuzzyCompare(sliderSpinBox.maximum(), 2051.0))
     {
     std::cerr << "ctkSliderSpinBoxWidget::setDecimals failed."
               << sliderSpinBox.decimals() << " "
-              << sliderSpinBox.value() << std::endl;
+              << sliderSpinBox.value() << " " 
+              << sliderSpinBox.minimum() << " " 
+              << sliderSpinBox.maximum() << std::endl;
     return EXIT_FAILURE;
     }  
 
@@ -141,7 +145,7 @@ int ctkSliderSpinBoxWidgetTest1(int argc, char * argv [] )
   if (sliderSpinBox.spinBoxAlignment() != Qt::AlignRight || 
       !qFuzzyCompare(sliderSpinBox.value(), 80.6))
     {
-    std::cerr << "ctkSliderSpinBoxWidget::setMinimum failed."
+    std::cerr << "ctkSliderSpinBoxWidget::setSpinBoxAlignment failed."
               << sliderSpinBox.spinBoxAlignment() << " "
               << sliderSpinBox.value() << std::endl;
     return EXIT_FAILURE;
@@ -152,7 +156,7 @@ int ctkSliderSpinBoxWidgetTest1(int argc, char * argv [] )
   if (sliderSpinBox.isAutoSpinBoxWidth() != false || 
       !qFuzzyCompare(sliderSpinBox.value(), 80.6))
     {
-    std::cerr << "ctkSliderSpinBoxWidget::setMinimum failed."
+    std::cerr << "ctkSliderSpinBoxWidget::setAutoSpinBoxWidth failed."
               << sliderSpinBox.isAutoSpinBoxWidth() << " "
               << sliderSpinBox.value() << std::endl;
     return EXIT_FAILURE;
@@ -180,6 +184,18 @@ int ctkSliderSpinBoxWidgetTest1(int argc, char * argv [] )
     return EXIT_FAILURE;
     }
 
+  sliderSpinBox.setDecimals(0);
+
+  if (!qFuzzyCompare(sliderSpinBox.value(), 81) ||
+      !qFuzzyCompare(sliderSpinBox.minimum(), 81) ||
+      !qFuzzyCompare(sliderSpinBox.maximum(), 2051))
+    {
+    std::cerr << "ctkSliderSpinBoxWidget::setDecimals failed."
+              << sliderSpinBox.value() << " " 
+              << sliderSpinBox.minimum() << " " 
+              << sliderSpinBox.maximum() << std::endl;
+    return EXIT_FAILURE;
+    }
 
   // FIXME check that the correct signals are sent.
   return EXIT_SUCCESS;

+ 6 - 0
Libs/Widgets/ctkRangeWidget.cpp

@@ -399,6 +399,12 @@ void ctkRangeWidget::setDecimals(int newDecimals)
   CTK_D(ctkRangeWidget);
   d->MinimumSpinBox->setDecimals(newDecimals);
   d->MaximumSpinBox->setDecimals(newDecimals);
+  // The number of decimals can change the range values
+  // i.e. 50.55 with 2 decimals -> 51 with 0 decimals
+  // As the SpinBox range change doesn't fire signals, 
+  // we have to do the synchronization manually here
+  d->Slider->setMinimum(d->MinimumSpinBox->minimum());
+  d->Slider->setMaximum(d->MaximumSpinBox->maximum());
 }
 
 // --------------------------------------------------------------------------

+ 6 - 0
Libs/Widgets/ctkSliderSpinBoxWidget.cpp

@@ -323,6 +323,12 @@ void ctkSliderSpinBoxWidget::setDecimals(int newDecimals)
 {
   CTK_D(ctkSliderSpinBoxWidget);
   d->SpinBox->setDecimals(newDecimals);
+  // The number of decimals can change the range values
+  // i.e. 50.55 with 2 decimals -> 51 with 0 decimals
+  // As the SpinBox range change doesn't fire signals, 
+  // we have to do the synchronization manually here
+  d->Slider->setMinimum(d->SpinBox->minimum());
+  d->Slider->setMaximum(d->SpinBox->maximum());
 }
 
 // --------------------------------------------------------------------------