From 56f6e5051f759e614bedb0c16e26945e5495048d Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 9 Oct 2021 10:33:22 +0200 Subject: [PATCH] profile: fix displaying of gas pressures Due to bit-rot the gas pressure and gas type were displayed on top of each other. I don't understand the meaning of the old code [log10(log10(axisRange))] (!). Therefore let's just add the height of the label to separate the labels. Probably needs some fine-tuning. Signed-off-by: Berthold Stoeger --- profile-widget/diveprofileitem.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 33341ffd3..646937213 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -471,8 +471,7 @@ void DiveGasPressureItem::replot(const dive *d, int fromIn, int toIn, bool in_pl QFlags alignVar = Qt::AlignTop; std::vector> align(pInfo->nr_cylinders); - double axisRange = (vAxis.maximum() - vAxis.minimum())/1000; // Convert axis pressure range to bar - double axisLog = log10(log10(axisRange)); + double labelHeight = DiveTextItem::fontHeight(dpr, 1.0); for (int i = from; i < to; i++) { const struct plot_data *entry = pInfo->entry + i; @@ -484,17 +483,11 @@ void DiveGasPressureItem::replot(const dive *d, int fromIn, int toIn, bool in_pl continue; if (!seen_cyl[cyl]) { - double value_y_offset, label_y_offset; - // Magic Y offset depending on whether we're aliging // the top of the text or the bottom of the text to // the pressure line. - value_y_offset = -0.5; - if (alignVar & Qt::AlignTop) { - label_y_offset = 5 * axisLog; - } else { - label_y_offset = -7 * axisLog; - } + double value_y_offset = -0.5; + double label_y_offset = alignVar & Qt::AlignTop ? labelHeight : -labelHeight; plotPressureValue(mbar, entry->sec, alignVar, value_y_offset); plotGasValue(mbar, entry->sec, get_cylinder(d, cyl)->gasmix, alignVar, label_y_offset); seen_cyl[cyl] = true; @@ -523,7 +516,7 @@ void DiveGasPressureItem::plotPressureValue(int mbar, int sec, QFlagsset(QString("%1%2").arg(pressure).arg(unit), getColor(PRESSURE_TEXT)); - text->setPos(hAxis.posAtValue(sec), vAxis.posAtValue(mbar) + pressure_offset ); + text->setPos(hAxis.posAtValue(sec), vAxis.posAtValue(mbar) + pressure_offset); texts.push_back(text); } @@ -532,7 +525,7 @@ void DiveGasPressureItem::plotGasValue(int mbar, int sec, struct gasmix gasmix, QString gas = get_gas_string(gasmix); DiveTextItem *text = new DiveTextItem(dpr, 1.0, align, this); text->set(gas, getColor(PRESSURE_TEXT)); - text->setPos(hAxis.posAtValue(sec), vAxis.posAtValue(mbar) + gasname_offset ); + text->setPos(hAxis.posAtValue(sec), vAxis.posAtValue(mbar) + gasname_offset); texts.push_back(text); }