From 7836a78dca42da91abeaec9f6c28a063ddfb1716 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 19 May 2018 07:37:58 +0200 Subject: [PATCH] Profile: minor coding style issues concerning axis-ticks 1) Fix the English of a comment. 2) Remove a number of int-to-double compares: Make "steps" an integer variable (the number of steps). Rename the old double "steps" variable to "stepsInRange". This gives a non-integer number of steps and is necessary to calculate the correct step size 3) Replace a "x = x/y" by a "x /= y" construct. 4) Remove an unnecessary if clause. Signed-off-by: Berthold Stoeger --- profile-widget/divecartesianaxis.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index d2b3b9347..e10e5112c 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -128,13 +128,11 @@ void DiveCartesianAxis::setLinesVisible(bool arg1) } template -void emptyList(QList &list, double steps) +void emptyList(QList &list, int steps) { - if (!list.isEmpty() && list.size() > steps) { - while (list.size() > steps) { - T *removedItem = list.takeLast(); - Animations::animDelete(removedItem); - } + while (list.size() > steps) { + T *removedItem = list.takeLast(); + Animations::animDelete(removedItem); } } @@ -145,7 +143,8 @@ void DiveCartesianAxis::updateTicks(color_index_t color) QLineF m = line(); // unused so far: // QGraphicsView *view = scene()->views().first(); - double steps = (max - min) / interval; + double stepsInRange = (max - min) / interval; + int steps = (int)stepsInRange; double currValueText = min; double currValueLine = min; @@ -155,8 +154,8 @@ void DiveCartesianAxis::updateTicks(color_index_t color) emptyList(labels, steps); emptyList(lines, steps); - // Move the remaining Ticks / Text to it's corerct position - // Regartind the possibly new values for the Axis + // Move the remaining ticks / text to their correct positions + // regarding the possible new values for the axis qreal begin, stepSize; if (orientation == TopToBottom) { begin = m.y1(); @@ -171,7 +170,7 @@ void DiveCartesianAxis::updateTicks(color_index_t color) begin = m.x2(); stepSize = (m.x2() - m.x1()); } - stepSize = stepSize / steps; + stepSize /= stepsInRange; for (int i = 0, count = labels.size(); i < count; i++, currValueText += interval) { qreal childPos = (orientation == TopToBottom || orientation == LeftToRight) ?