From 2c4e4b1e865ae402b555bb50936b4943fab153d8 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 26 Sep 2021 19:30:27 +0200 Subject: [PATCH] profile: move setting of gasYAxis bounds to plotDive() The partial-pressure-axis was the only DiveCartesianAxis child that had its own code to set the bounds. The bounds of all other axes were set in plotDive(). For consistency, do this here as well. Thus, the whole class can be removed. Signed-off-by: Berthold Stoeger --- profile-widget/divecartesianaxis.cpp | 31 ---------------------------- profile-widget/divecartesianaxis.h | 10 --------- profile-widget/profilescene.cpp | 13 ++++++++++-- profile-widget/profilescene.h | 2 +- 4 files changed, 12 insertions(+), 44 deletions(-) diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index 13a54114d..8e2b0aa68 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -407,34 +407,3 @@ QString TimeAxis::textForValue(double value) const return QString("%1:%2").arg(nr).arg((int)value % 60, 2, 10, QChar('0')); return QString::number(nr); } - -PartialGasPressureAxis::PartialGasPressureAxis(const DivePlotDataModel &model, Position position, int integralDigits, int fractionalDigits, - color_index_t gridColor, double dpr, double labelScale, bool printMode, bool isGrayscale, - ProfileScene &scene) : - DiveCartesianAxis(position, integralDigits, fractionalDigits, gridColor, dpr, labelScale, printMode, isGrayscale, scene), - model(model) -{ -} - -void PartialGasPressureAxis::update(int animSpeed) -{ - bool showPhe = prefs.pp_graphs.phe; - bool showPn2 = prefs.pp_graphs.pn2; - bool showPo2 = prefs.pp_graphs.po2; - setVisible(showPhe || showPn2 || showPo2); - if (!model.rowCount()) - return; - - double max = showPhe ? model.pheMax() : -1; - if (showPn2 && model.pn2Max() > max) - max = model.pn2Max(); - if (showPo2 && model.po2Max() > max) - max = model.po2Max(); - - qreal pp = floor(max * 10.0) / 10.0 + 0.2; - if (IS_FP_SAME(maximum(), pp)) - return; - - setBounds(0.0, pp); - updateTicks(animSpeed); -} diff --git a/profile-widget/divecartesianaxis.h b/profile-widget/divecartesianaxis.h index 479dc0513..2d9115cba 100644 --- a/profile-widget/divecartesianaxis.h +++ b/profile-widget/divecartesianaxis.h @@ -110,14 +110,4 @@ public: using DiveCartesianAxis::DiveCartesianAxis; }; -class PartialGasPressureAxis : public DiveCartesianAxis { - Q_OBJECT -public: - PartialGasPressureAxis(const DivePlotDataModel &model, Position position, int integralDigits, int fractionalDigits, - color_index_t gridColor, double dpr, double labelScale, bool printMode, bool isGrayscale, ProfileScene &scene); - void update(int animSpeed); -private: - const DivePlotDataModel &model; -}; - #endif // DIVECARTESIANAXIS_H diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 761a6dffc..ad8441250 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -48,7 +48,7 @@ ProfileScene::ProfileScene(double dpr, bool printMode, bool isGrayscale) : maxdepth(-1), dataModel(new DivePlotDataModel(this)), profileYAxis(new DepthAxis(DiveCartesianAxis::Position::Left, 3, 0, TIME_GRID, dpr, 1.0, printMode, isGrayscale, *this)), - gasYAxis(new PartialGasPressureAxis(*dataModel, DiveCartesianAxis::Position::Right, 1, 2, TIME_GRID, dpr, 0.7, printMode, isGrayscale, *this)), + gasYAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, 1, 2, TIME_GRID, dpr, 0.7, printMode, isGrayscale, *this)), temperatureAxis(new TemperatureAxis(DiveCartesianAxis::Position::Right, 3, 0, TIME_GRID, dpr, 1.0, printMode, isGrayscale, *this)), timeAxis(new TimeAxis(DiveCartesianAxis::Position::Bottom, 2, 2, TIME_GRID, dpr, 1.0, printMode, isGrayscale, *this)), cylinderPressureAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, 4, 0, TIME_GRID, dpr, 1.0, printMode, isGrayscale, *this)), @@ -450,7 +450,16 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM #endif tankItem->setData(&plotInfo, d); - gasYAxis->update(animSpeed); + if (ppGraphsEnabled()) { + double max = prefs.pp_graphs.phe ? dataModel->pheMax() : -1; + if (prefs.pp_graphs.pn2) + max = std::max(dataModel->pn2Max(), max); + if (prefs.pp_graphs.po2) + max = std::max(dataModel->po2Max(), max); + + gasYAxis->setBounds(0.0, max); + gasYAxis->updateTicks(animSpeed); + } // Replot dive items for (AbstractProfilePolygonItem *item: profileItems) diff --git a/profile-widget/profilescene.h b/profile-widget/profilescene.h index 6d3e987c7..81856a141 100644 --- a/profile-widget/profilescene.h +++ b/profile-widget/profilescene.h @@ -72,7 +72,7 @@ private: DivePlotDataModel *dataModel; struct plot_info plotInfo; DepthAxis *profileYAxis; - PartialGasPressureAxis *gasYAxis; + DiveCartesianAxis *gasYAxis; TemperatureAxis *temperatureAxis; TimeAxis *timeAxis; DiveCartesianAxis *cylinderPressureAxis;