Ver código fonte

BUG: Block signals setSingleStep()

Firing intermediate steps in singleStep is dangerous. Depending on how ctkDoubleRangeSlider is connected to other widgets, firing a minimumValueChanged equal to minimum before setting it back to its original can be confusing in a lot of cases (generates a wrong behavior in ctkRangeWidget).
Julien Finet 15 anos atrás
pai
commit
b0a3d27d41
1 arquivos alterados com 6 adições e 0 exclusões
  1. 6 0
      Libs/Widgets/ctkDoubleRangeSlider.cpp

+ 6 - 0
Libs/Widgets/ctkDoubleRangeSlider.cpp

@@ -341,17 +341,23 @@ void ctkDoubleRangeSlider::setSingleStep(double newStep)
 {
   CTK_D(ctkDoubleRangeSlider);
   d->SingleStep = newStep;
+  // The following can fire A LOT of signals that shouldn't be 
+  // fired.
+  bool oldBlockSignals = this->blockSignals(true);
   d->updateMinOffset(d->MinValue);
   d->updateMaxOffset(d->MaxValue);
   // update the new values of the ctkRangeSlider
   double _minvalue = d->MinValue;
   double _maxvalue = d->MaxValue;
+  // calling setMinimum or setMaximum can change the values MinimumValue
+  // and MaximumValue, this is why we re-set them later.  
   this->setMinimum(d->Minimum);
   this->setMaximum(d->Maximum);
   this->setMinimumValue(_minvalue);
   this->setMinimumPosition(_minvalue);
   this->setMaximumValue(_maxvalue);
   this->setMaximumPosition(_maxvalue);
+  this->blockSignals(oldBlockSignals);
 }
 
 // --------------------------------------------------------------------------