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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-12-04 21:45:46 +01:00 committed by Dirk Hohndel
parent 725fda3cd1
commit 3579e36b7d
2 changed files with 14 additions and 8 deletions

View file

@ -220,24 +220,24 @@ QLineF DiveCartesianAxis::linePos(double pos) const
void DiveCartesianAxis::updateLabel(Label &label, double opacityEnd, double pos) const void DiveCartesianAxis::updateLabel(Label &label, double opacityEnd, double pos) const
{ {
label.opacityStart = textVisibility ? label.label->opacity() label.opacityStart = label.label ? label.label->opacity()
: label.line->opacity(); : label.line->opacity();
label.opacityEnd = opacityEnd; label.opacityEnd = opacityEnd;
if (textVisibility) { if (label.label) {
label.labelPosStart = label.label->pos(); label.labelPosStart = label.label->pos();
label.labelPosEnd = labelPos(pos); label.labelPosEnd = labelPos(pos);
} }
if (lineVisibility) { if (label.line) {
label.lineStart = label.line->line(); label.lineStart = label.line->line();
label.lineEnd = linePos(pos); 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 }; Label label { value, 0.0, 1.0 };
double posStart = posAtValue(value, dataMaxOld, dataMinOld); double posStart = posAtValue(value, dataMaxOld, dataMinOld);
if (textVisibility) { if (textVisibility && !noLabel) {
label.labelPosStart = labelPos(posStart); label.labelPosStart = labelPos(posStart);
label.labelPosEnd = labelPos(pos); label.labelPosEnd = labelPos(pos);
int alignFlags = position == Position::Bottom ? Qt::AlignTop | Qt::AlignHCenter : int alignFlags = position == Position::Bottom ? Qt::AlignTop | Qt::AlignHCenter :
@ -271,6 +271,7 @@ void DiveCartesianAxis::updateLabels(int numTicks, double firstPosScreen, double
newLabels.reserve(numTicks); newLabels.reserve(numTicks);
auto actOld = labels.begin(); auto actOld = labels.begin();
double value = firstValue; double value = firstValue;
for (int i = 0; i < numTicks; i++, value += stepValue) { 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. // 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)); newLabels.push_back(std::move(*actOld));
++actOld; ++actOld;
} else { } 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 // Create new label
newLabels.push_back(createLabel(value, pos, dataMinOld, dataMaxOld, animSpeed)); newLabels.push_back(createLabel(value, pos, dataMinOld, dataMaxOld, animSpeed, noLabel));
} }
} }

View file

@ -68,7 +68,7 @@ private:
QPointF labelPos(double pos) const; QPointF labelPos(double pos) const;
QLineF linePos(double pos) const; QLineF linePos(double pos) const;
void updateLabel(Label &label, double opacityEnd, 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; QString textForValue(double value) const;
std::vector<Label> labels; std::vector<Label> labels;
double dataMin, dataMax; double dataMin, dataMax;