! * helper function called in other shift*() functions * and doing the actual change of the data ranges. * @param x if set to \true the x-range is modified, the y-range for \c false * @param leftOrDown the "shift left" for x or "shift dows" for y is performed if set to \c \true, * "shift right" or "shift up" for \c false */
| 3173 | * "shift right" or "shift up" for \c false |
| 3174 | */ |
| 3175 | void CartesianPlot::shift(int index, const Dimension dim, bool leftOrDown) { |
| 3176 | setUndoAware(false); |
| 3177 | enableAutoScale(dim, index, false); |
| 3178 | setUndoAware(true); |
| 3179 | Q_D(CartesianPlot); |
| 3180 | |
| 3181 | Range<double> range; |
| 3182 | if (index == -1) { |
| 3183 | QVector<int> shiftedIndices; |
| 3184 | for (int i = 0; i < m_coordinateSystems.count(); i++) { |
| 3185 | int idx = coordinateSystem(i)->index(dim); |
| 3186 | if (shiftedIndices.contains(idx)) |
| 3187 | continue; |
| 3188 | shift(idx, dim, leftOrDown); |
| 3189 | shiftedIndices.append(idx); |
| 3190 | } |
| 3191 | return; |
| 3192 | } |
| 3193 | range = d->range(dim, index); |
| 3194 | |
| 3195 | double offset = 0.0, factor = 0.1; |
| 3196 | |
| 3197 | if (!leftOrDown) |
| 3198 | factor *= -1.; |
| 3199 | |
| 3200 | const double start{range.start()}, end{range.end()}; |
| 3201 | switch (range.scale()) { |
| 3202 | case RangeT::Scale::Linear: { |
| 3203 | offset = range.size() * factor; |
| 3204 | range += offset; |
| 3205 | break; |
| 3206 | } |
| 3207 | case RangeT::Scale::Log10: { |
| 3208 | if (start == 0 || end / start <= 0) |
| 3209 | break; |
| 3210 | offset = log10(end / start) * factor; |
| 3211 | range *= pow(10, offset); |
| 3212 | break; |
| 3213 | } |
| 3214 | case RangeT::Scale::Log2: { |
| 3215 | if (start == 0 || end / start <= 0) |
| 3216 | break; |
| 3217 | offset = log2(end / start) * factor; |
| 3218 | range *= exp2(offset); |
| 3219 | break; |
| 3220 | } |
| 3221 | case RangeT::Scale::Ln: { |
| 3222 | if (start == 0 || end / start <= 0) |
| 3223 | break; |
| 3224 | offset = log(end / start) * factor; |
| 3225 | range *= exp(offset); |
| 3226 | break; |
| 3227 | } |
| 3228 | case RangeT::Scale::Sqrt: |
| 3229 | if (start < 0 || end < 0) |
| 3230 | break; |
| 3231 | offset = (sqrt(end) - sqrt(start)) * factor; |
| 3232 | range += offset * offset; |
no test coverage detected