Commit 373e65b99bc8062a65b9f653f5a1eacafc09205f
Committed by
David Graeff
1 parent
39d8e84b
sispinbox: fix stepBy to keep limit into accounts
Showing
1 changed file
with
18 additions
and
5 deletions
openhantek/src/sispinbox.cpp
| @@ -101,6 +101,14 @@ void SiSpinBox::fixup(QString &input) const { | @@ -101,6 +101,14 @@ void SiSpinBox::fixup(QString &input) const { | ||
| 101 | void SiSpinBox::stepBy(int steps) { | 101 | void SiSpinBox::stepBy(int steps) { |
| 102 | double stepsSpan = this->steps.last() / this->steps.first(); | 102 | double stepsSpan = this->steps.last() / this->steps.first(); |
| 103 | int stepsCount = this->steps.size() - 1; | 103 | int stepsCount = this->steps.size() - 1; |
| 104 | + double value = 0; | ||
| 105 | + | ||
| 106 | + // Skip if we are already at a limit or if steps is null | ||
| 107 | + if (steps == 0 || | ||
| 108 | + (steps < 0 && this->value() <= this->minimum()) || | ||
| 109 | + (steps > 0 && this->value() >= this->maximum())) { | ||
| 110 | + return; | ||
| 111 | + } | ||
| 104 | 112 | ||
| 105 | if(!this->steppedTo) { // No step done directly before this one, so we need to check where we are | 113 | if(!this->steppedTo) { // No step done directly before this one, so we need to check where we are |
| 106 | // Get how often the steps have to be fully ran through | 114 | // Get how often the steps have to be fully ran through |
| @@ -121,11 +129,16 @@ void SiSpinBox::stepBy(int steps) { | @@ -121,11 +129,16 @@ void SiSpinBox::stepBy(int steps) { | ||
| 121 | ++this->stepId; | 129 | ++this->stepId; |
| 122 | } | 130 | } |
| 123 | 131 | ||
| 124 | - this->stepId += steps; | ||
| 125 | - int stepsId = this->stepId % stepsCount; | ||
| 126 | - if(stepsId < 0) | ||
| 127 | - stepsId += stepsCount; | ||
| 128 | - double value = pow(stepsSpan, floor((double) this->stepId / stepsCount)) * this->steps[stepsId]; | 132 | + int subStep = steps / abs(steps); |
| 133 | + for (int i = 0; i != steps; i += subStep) { | ||
| 134 | + this->stepId += subStep; | ||
| 135 | + int stepsId = this->stepId % stepsCount; | ||
| 136 | + if(stepsId < 0) | ||
| 137 | + stepsId += stepsCount; | ||
| 138 | + value = pow(stepsSpan, floor((double) this->stepId / stepsCount)) * this->steps[stepsId]; | ||
| 139 | + if (value <= this->minimum() || value >= this->maximum()) | ||
| 140 | + break; | ||
| 141 | + } | ||
| 129 | this->setValue(value); | 142 | this->setValue(value); |
| 130 | value = this->value(); | 143 | value = this->value(); |
| 131 | this->steppedTo = true; | 144 | this->steppedTo = true; |