From 0bef8167d22fc2b213880f4bcde60a781f34889b Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 11 Sep 2021 21:43:53 +0200 Subject: [PATCH] profile: always update axis-positions when plotting dive The placement of the axes was done independently of the plotting, e.g. when settings changed. Presumably, for performance reasons. However, since the axes may depend on whether a dive has heart-rate data or not, this simply is not viable. To make this work, one would have to remember whether the previous dive showed the heart-rate, etc. Not worth it - always reposition the axes. It should not matte performance- wise. Signed-off-by: Berthold Stoeger --- profile-widget/profilescene.cpp | 20 +++++++++----------- profile-widget/profilescene.h | 4 ++-- profile-widget/profilewidget2.cpp | 3 --- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 1cabab5cc..67de05a73 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -142,8 +142,6 @@ ProfileScene::ProfileScene(double dpr, bool printMode, bool isGrayscale) : for (AbstractProfilePolygonItem *item: profileItems) addItem(item); - - updateAxes(true); } ProfileScene::~ProfileScene() @@ -171,7 +169,7 @@ static bool ppGraphsEnabled() } // Update visibility of non-interactive chart features according to preferences -void ProfileScene::updateVisibility() +void ProfileScene::updateVisibility(bool diveHasHeartBeat) { #ifndef SUBSURFACE_MOBILE pn2GasItem->setVisible(prefs.pp_graphs.pn2); @@ -187,7 +185,7 @@ void ProfileScene::updateVisibility() ccrsensor3GasItem->setVisible(currentdc && sensorflag && currentdc->no_o2sensors > 2); ocpo2GasItem->setVisible(currentdc && currentdc->divemode == PSCR && prefs.show_scr_ocpo2); - heartBeatItem->setVisible(prefs.hrgraph); + heartBeatItem->setVisible(prefs.hrgraph && diveHasHeartBeat); #endif diveCeiling->setVisible(prefs.calcceiling); decoModelParameters->setVisible(prefs.decoinfo); @@ -204,7 +202,6 @@ void ProfileScene::updateVisibility() void ProfileScene::resize(QSizeF size) { setSceneRect(QRectF(QPointF(), size)); - updateAxes(true); // disable animations when resizing } // Helper structure for laying out secondary plots. @@ -214,7 +211,7 @@ struct VerticalAxisLayout { bool visible; }; -void ProfileScene::updateAxes(bool instant) +void ProfileScene::updateAxes(bool instant, bool diveHasHeartBeat) { int animSpeed = instant || printMode ? 0 : qPrefDisplay::animation_speed(); @@ -261,7 +258,7 @@ void ProfileScene::updateAxes(bool instant) const double minProfileFraction = 0.5; VerticalAxisLayout secondaryAxes[] = { // Note: axes are listed from bottom to top, since they are added that way. - { heartBeatAxis, 75.0, prefs.hrgraph }, + { heartBeatAxis, 75.0, prefs.hrgraph && diveHasHeartBeat }, { percentageAxis, 50.0, prefs.percentagegraph }, { gasYAxis, 75.0, ppGraphsEnabled() }, { temperatureAxis, 50.0, true }, @@ -342,8 +339,6 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM ccrsensor3GasItem->setVisible(sensorflag && (currentdc->no_o2sensors > 2)); ocpo2GasItem->setVisible((currentdc->divemode == PSCR) && prefs.show_scr_ocpo2); - updateVisibility(); - // A non-null planner_ds signals to create_plot_info_new that the dive is currently planned. struct deco_state *planner_ds = inPlanner && plannerModel ? &plannerModel->final_deco_state : nullptr; @@ -357,6 +352,10 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM */ create_plot_info_new(d, get_dive_dc_const(d, dc), &plotInfo, !calcMax, planner_ds); + bool hasHeartBeat = plotInfo.maxhr; + updateVisibility(hasHeartBeat); + updateAxes(instant, hasHeartBeat); + int newMaxtime = get_maxtime(&plotInfo); if (calcMax || newMaxtime > maxtime) maxtime = newMaxtime; @@ -384,7 +383,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM temperatureAxis->setMinimum(plotInfo.mintemp); temperatureAxis->setMaximum(plotInfo.maxtemp - plotInfo.mintemp > 2000 ? plotInfo.maxtemp : plotInfo.mintemp + 2000); - if (plotInfo.maxhr) { + if (hasHeartBeat) { int heartBeatAxisMin = lrint(plotInfo.minhr / 5.0 - 0.5) * 5; int heartBeatAxisMax, heartBeatAxisTick; if (plotInfo.maxhr - plotInfo.minhr < 40) @@ -401,7 +400,6 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM heartBeatAxis->setTickInterval(heartBeatAxisTick); heartBeatAxis->updateTicks(animSpeed); // this shows the ticks } - heartBeatAxis->setVisible(prefs.hrgraph && plotInfo.maxhr); percentageAxis->setMinimum(0); percentageAxis->setMaximum(100); diff --git a/profile-widget/profilescene.h b/profile-widget/profilescene.h index 8d75ec809..6d3e987c7 100644 --- a/profile-widget/profilescene.h +++ b/profile-widget/profilescene.h @@ -42,7 +42,6 @@ public: ~ProfileScene(); void resize(QSizeF size); - void updateAxes(bool instant); // Update axes according to preferences void clear(); bool isPointOutOfBoundaries(const QPointF &point) const; @@ -60,7 +59,8 @@ private: template T *createItem(const DiveCartesianAxis &vAxis, int vColumn, int z, Args&&... args); PartialPressureGasItem *createPPGas(int column, color_index_t color, color_index_t colorAlert, const double *thresholdSettingsMin, const double *thresholdSettingsMax); - void updateVisibility(); // Update visibility of non-interactive chart features according to preferences + void updateVisibility(bool diveHasHeartBeat); // Update visibility of non-interactive chart features according to preferences + void updateAxes(bool instant, bool diveHasHeartBeat); // Update axes according to preferences friend class ProfileWidget2; // For now, give the ProfileWidget full access to the objects on the scene double dpr; // Device Pixel Ratio. A DPR of one corresponds to a "standard" PC screen. diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index fbc72b07f..4f6ce5f0c 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -263,7 +263,6 @@ void ProfileWidget2::actionRequestedReplot(bool) void ProfileWidget2::settingsChanged() { - profileScene->updateAxes(false); replot(); } @@ -448,8 +447,6 @@ void ProfileWidget2::setProfileState() currentState = PROFILE; setBackgroundBrush(getColor(::BACKGROUND, profileScene->isGrayscale)); - profileScene->updateAxes(true); - #ifndef SUBSURFACE_MOBILE toolTipItem->readPos(); toolTipItem->setVisible(true);