From 89d9105209ecb13972db48ad35fde452766fc2a7 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 11 Sep 2021 21:57:49 +0200 Subject: [PATCH] profile: set minimum/maximum of axes with a single call This is bike-shedding: Instead of two setMinimum()/setMaximum() calls, use a single setBounds() call. A few axes (notably depth and time) always have a 0 as lower bound. However, this will change once there is a proper zooming functionality. Signed-off-by: Berthold Stoeger --- profile-widget/divecartesianaxis.cpp | 17 ++++------------- profile-widget/divecartesianaxis.h | 3 +-- profile-widget/profilescene.cpp | 19 +++++++------------ profile-widget/profilewidget2.cpp | 2 +- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index acbd6d1bc..1045ced18 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -17,20 +17,11 @@ void DiveCartesianAxis::setFontLabelScale(qreal scale) changed = true; } -void DiveCartesianAxis::setMaximum(double maximum) +void DiveCartesianAxis::setBounds(double minimum, double maximum) { - if (IS_FP_SAME(max, maximum)) - return; - max = maximum; - changed = true; -} - -void DiveCartesianAxis::setMinimum(double minimum) -{ - if (IS_FP_SAME(min, minimum)) - return; + changed = !IS_FP_SAME(max, maximum) || !IS_FP_SAME(min, minimum); min = minimum; - changed = true; + max = maximum; } DiveCartesianAxis::DiveCartesianAxis(Position position, color_index_t gridColor, double dpr, @@ -431,7 +422,7 @@ void PartialGasPressureAxis::update(int animSpeed) if (IS_FP_SAME(maximum(), pp)) return; - setMaximum(pp); + setBounds(0.0, pp); setTickInterval(pp > 4 ? 0.5 : 0.25); updateTicks(animSpeed); } diff --git a/profile-widget/divecartesianaxis.h b/profile-widget/divecartesianaxis.h index 9837014e9..41cc6591e 100644 --- a/profile-widget/divecartesianaxis.h +++ b/profile-widget/divecartesianaxis.h @@ -35,8 +35,7 @@ public: DiveCartesianAxis(Position position, color_index_t gridColor, double dpr, bool printMode, bool isGrayscale, ProfileScene &scene); ~DiveCartesianAxis(); - void setMinimum(double minimum); - void setMaximum(double maximum); + void setBounds(double min, double max); void setTickInterval(double interval); void setOrientation(Orientation orientation); void setFontLabelScale(qreal scale); diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 67de05a73..522541b0c 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -82,12 +82,10 @@ ProfileScene::ProfileScene(double dpr, bool printMode, bool isGrayscale) : // Initialize axes. Perhaps part of this should be moved down to the axes code? profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom); - profileYAxis->setMinimum(0); profileYAxis->setTickInterval(M_OR_FT(10, 30)); gasYAxis->setOrientation(DiveCartesianAxis::BottomToTop); gasYAxis->setTickInterval(1); - gasYAxis->setMinimum(0); gasYAxis->setFontLabelScale(0.7); #ifndef SUBSURFACE_MOBILE @@ -377,11 +375,11 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM // It seems that I'll have a lot of boilerplate setting the model / axis for // each item, I'll mostly like to fix this in the future, but I'll keep at this for now. - profileYAxis->setMaximum(maxdepth); + profileYAxis->setBounds(0.0, maxdepth); profileYAxis->updateTicks(animSpeed); - temperatureAxis->setMinimum(plotInfo.mintemp); - temperatureAxis->setMaximum(plotInfo.maxtemp - plotInfo.mintemp > 2000 ? plotInfo.maxtemp : plotInfo.mintemp + 2000); + temperatureAxis->setBounds(plotInfo.mintemp, + plotInfo.maxtemp - plotInfo.mintemp > 2000 ? plotInfo.maxtemp : plotInfo.mintemp + 2000); if (hasHeartBeat) { int heartBeatAxisMin = lrint(plotInfo.minhr / 5.0 - 0.5) * 5; @@ -395,19 +393,17 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM else heartBeatAxisTick = 50; for (heartBeatAxisMax = heartBeatAxisMin; heartBeatAxisMax < plotInfo.maxhr; heartBeatAxisMax += heartBeatAxisTick); - heartBeatAxis->setMinimum(heartBeatAxisMin); - heartBeatAxis->setMaximum(heartBeatAxisMax + 1); + heartBeatAxis->setBounds(heartBeatAxisMin, heartBeatAxisMax + 1); heartBeatAxis->setTickInterval(heartBeatAxisTick); heartBeatAxis->updateTicks(animSpeed); // this shows the ticks } - percentageAxis->setMinimum(0); - percentageAxis->setMaximum(100); + percentageAxis->setBounds(0, 100); percentageAxis->setVisible(false); percentageAxis->updateTicks(animSpeed); if (calcMax) - timeAxis->setMaximum(maxtime); + timeAxis->setBounds(0.0, maxtime); int i, incr; static int increments[8] = { 10, 20, 30, 60, 5 * 60, 10 * 60, 15 * 60, 30 * 60 }; @@ -426,8 +422,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM incr *= 2; timeAxis->setTickInterval(incr); timeAxis->updateTicks(animSpeed); - cylinderPressureAxis->setMinimum(plotInfo.minpressure); - cylinderPressureAxis->setMaximum(plotInfo.maxpressure); + cylinderPressureAxis->setBounds(plotInfo.minpressure, plotInfo.maxpressure); #ifdef SUBSURFACE_MOBILE if (currentdc->divemode == CCR) { diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 4f6ce5f0c..d1371b146 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -970,7 +970,7 @@ void ProfileWidget2::divePlannerHandlerMoved() // Grow the time axis if necessary. int minutes = lrint(profileScene->timeAxis->valueAt(activeHandler->pos()) / 60); if (minutes * 60 > profileScene->timeAxis->maximum() * 0.9) - profileScene->timeAxis->setMaximum(profileScene->timeAxis->maximum() * 1.02); + profileScene->timeAxis->setBounds(0.0, profileScene->timeAxis->maximum() * 1.02); divedatapoint data = plannerModel->at(index); data.depth.mm = lrint(profileScene->profileYAxis->valueAt(activeHandler->pos()) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);