From e0f44237cc3a3f41bf03ca3e06ac89010bb3c127 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 3 Dec 2021 14:18:31 +0100 Subject: [PATCH] profile: move max_gas() from DivePlotDataModel to ProfileScene There is only one user of this - let's remove complex interdependencies. Note: there seem to be two independent plot_infos: in the ProfileScene and in the DivePlotDataModel. To avoid behavioral change, this keeps using the DivePlotDataModel's version. In any case, this has to be unified. Signed-off-by: Berthold Stoeger --- profile-widget/profilescene.cpp | 15 +++++++++++++-- qt-models/diveplotdatamodel.cpp | 25 ------------------------- qt-models/diveplotdatamodel.h | 3 --- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 9b2f3dec5..948956153 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -349,6 +349,16 @@ bool ProfileScene::pointOnProfile(const QPointF &point) const return timeAxis->pointInRange(point.x()) && profileYAxis->pointInRange(point.y()); } +static double max_gas(const plot_info &pi, double gas_pressures::*gas) +{ + double ret = -1; + for (int i = 0; i < pi.nr; ++i) { + if (pi.entry[i].pressures.*gas > ret) + ret = pi.entry[i].pressures.*gas; + } + return ret; +} + void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsModel *plannerModel, bool inPlanner, bool instant, bool keepPlotInfo, bool calcMax, double zoom, double zoomedPosition) { @@ -471,10 +481,11 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM tankItem->setData(d, firstSecond, lastSecond); if (ppGraphsEnabled(currentdc, simplified)) { + double max = prefs.pp_graphs.phe ? max_gas(dataModel->data(), &gas_pressures::he) : -1; if (prefs.pp_graphs.pn2) - max = std::max(dataModel->pn2Max(), max); + max = std::max(max_gas(dataModel->data(), &gas_pressures::n2), max); if (prefs.pp_graphs.po2) - max = std::max(dataModel->po2Max(), max); + max = std::max(max_gas(dataModel->data(), &gas_pressures::o2), max); gasYAxis->setBounds(0.0, max); gasYAxis->updateTicks(animSpeed); diff --git a/qt-models/diveplotdatamodel.cpp b/qt-models/diveplotdatamodel.cpp index 4db1cebdd..65aa0bc92 100644 --- a/qt-models/diveplotdatamodel.cpp +++ b/qt-models/diveplotdatamodel.cpp @@ -178,28 +178,3 @@ void DivePlotDataModel::setDive(const plot_info &info) memcpy(pInfo.pressures, info.pressures, sizeof(plot_pressure_data) * pInfo.nr_cylinders * pInfo.nr); endResetModel(); } - -static double max_gas(const plot_info &pi, double gas_pressures::*gas) -{ - double ret = -1; - for (int i = 0; i < pi.nr; ++i) { - if (pi.entry[i].pressures.*gas > ret) - ret = pi.entry[i].pressures.*gas; - } - return ret; -} - -double DivePlotDataModel::pheMax() const -{ - return max_gas(pInfo, &gas_pressures::he); -} - -double DivePlotDataModel::pn2Max() const -{ - return max_gas(pInfo, &gas_pressures::n2); -} - -double DivePlotDataModel::po2Max() const -{ - return max_gas(pInfo, &gas_pressures::o2); -} diff --git a/qt-models/diveplotdatamodel.h b/qt-models/diveplotdatamodel.h index b48c315ad..2cc59b976 100644 --- a/qt-models/diveplotdatamodel.h +++ b/qt-models/diveplotdatamodel.h @@ -63,9 +63,6 @@ public: void clear(); void setDive(const plot_info &pInfo); const plot_info &data() const; - double pheMax() const; - double pn2Max() const; - double po2Max() const; private: struct plot_info pInfo;