From 3579e36b7d6ab68acf45dde73d62aadfefcd75b6 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 4 Dec 2021 21:45:46 +0100 Subject: [PATCH] profile: don't show 0m label The old profile code didn't show the 0m label, because that was cut off. This was lost when redoing the axis code. Reimplement this. The code is very ugly: it recognizes the depth axis by the fact that is the only "inverted" axis. Signed-off-by: Berthold Stoeger --- profile-widget/divecartesianaxis.cpp | 20 +++++++++++++------- profile-widget/divecartesianaxis.h | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index 40b2cef99..4db33d861 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -220,24 +220,24 @@ QLineF DiveCartesianAxis::linePos(double pos) const void DiveCartesianAxis::updateLabel(Label &label, double opacityEnd, double pos) const { - label.opacityStart = textVisibility ? label.label->opacity() - : label.line->opacity(); + label.opacityStart = label.label ? label.label->opacity() + : label.line->opacity(); label.opacityEnd = opacityEnd; - if (textVisibility) { + if (label.label) { label.labelPosStart = label.label->pos(); label.labelPosEnd = labelPos(pos); } - if (lineVisibility) { + if (label.line) { label.lineStart = label.line->line(); label.lineEnd = linePos(pos); } } -DiveCartesianAxis::Label DiveCartesianAxis::createLabel(double value, double pos, double dataMinOld, double dataMaxOld, int animSpeed) +DiveCartesianAxis::Label DiveCartesianAxis::createLabel(double value, double pos, double dataMinOld, double dataMaxOld, int animSpeed, bool noLabel) { Label label { value, 0.0, 1.0 }; double posStart = posAtValue(value, dataMaxOld, dataMinOld); - if (textVisibility) { + if (textVisibility && !noLabel) { label.labelPosStart = labelPos(posStart); label.labelPosEnd = labelPos(pos); int alignFlags = position == Position::Bottom ? Qt::AlignTop | Qt::AlignHCenter : @@ -271,6 +271,7 @@ void DiveCartesianAxis::updateLabels(int numTicks, double firstPosScreen, double newLabels.reserve(numTicks); auto actOld = labels.begin(); double value = firstValue; + for (int i = 0; i < numTicks; i++, value += stepValue) { // Check if we already got that label. If we find unused labels, mark them for deletion. @@ -291,8 +292,13 @@ void DiveCartesianAxis::updateLabels(int numTicks, double firstPosScreen, double newLabels.push_back(std::move(*actOld)); ++actOld; } else { + // This is horrible: for the depth axis, we don't want to show the first label (0). + // We recognize this by the fact that the depth axis is the only "inverted" axis. + // This really should be replaced by a general flag to avoid surprises! + bool noLabel = inverted && i == 0; + // Create new label - newLabels.push_back(createLabel(value, pos, dataMinOld, dataMaxOld, animSpeed)); + newLabels.push_back(createLabel(value, pos, dataMinOld, dataMaxOld, animSpeed, noLabel)); } } diff --git a/profile-widget/divecartesianaxis.h b/profile-widget/divecartesianaxis.h index ed5f21807..8b9db59e9 100644 --- a/profile-widget/divecartesianaxis.h +++ b/profile-widget/divecartesianaxis.h @@ -68,7 +68,7 @@ private: QPointF labelPos(double pos) const; QLineF linePos(double pos) const; void updateLabel(Label &label, double opacityEnd, double pos) const; - Label createLabel(double value, double pos, double dataMinOld, double dataMaxOld, int animSpeed); + Label createLabel(double value, double pos, double dataMinOld, double dataMaxOld, int animSpeed, bool noLabel); QString textForValue(double value) const; std::vector