Explorar o código

ENH: Add utility function "setValues" to ctkRangeWidget

Julien Finet %!s(int64=15) %!d(string=hai) anos
pai
achega
c1716d5e3e
Modificáronse 2 ficheiros con 21 adicións e 0 borrados
  1. 18 0
      Libs/Widgets/ctkRangeWidget.cpp
  2. 3 0
      Libs/Widgets/ctkRangeWidget.h

+ 18 - 0
Libs/Widgets/ctkRangeWidget.cpp

@@ -268,6 +268,24 @@ void ctkRangeWidget::setMaximumValue(double _value)
 }
 
 // --------------------------------------------------------------------------
+void ctkRangeWidget::setValues(double newMinimumValue, double newMaximumValue)
+{
+  CTK_D(ctkRangeWidget);
+  // disable the tracking temporally to emit the
+  // signal valueChanged if changeValue() is called
+  bool isChanging = d->Changing;
+  d->Changing = false;
+  d->MinimumSpinBox->setValue(newMinimumValue);
+  d->MaximumSpinBox->setValue(newMaximumValue);
+  // Why do we need to set the value to the slider ?
+  //d->Slider->setValue(d->SpinBox->value());
+  Q_ASSERT(d->equal(d->Slider->minimumValue(), d->MinimumSpinBox->value()));
+  Q_ASSERT(d->equal(d->Slider->maximumValue(), d->MaximumSpinBox->value()));
+  // restore the prop
+  d->Changing = isChanging;
+}
+
+// --------------------------------------------------------------------------
 void ctkRangeWidget::setMinimumToMaximumSpinBox(double minimum)
 {
   ctk_d()->MaximumSpinBox->setMinimum(minimum);

+ 3 - 0
Libs/Widgets/ctkRangeWidget.h

@@ -153,6 +153,9 @@ public slots:
   void reset();
   void setMinimumValue(double value);
   void setMaximumValue(double value);
+  ///
+  /// Utility function that set the min and max values at once
+  void setValues(double minValue, double maxValue);
 
 signals:
   /// Use with care: