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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-09-11 21:57:49 +02:00 committed by Dirk Hohndel
parent 0bef8167d2
commit 89d9105209
4 changed files with 13 additions and 28 deletions

View file

@ -17,20 +17,11 @@ void DiveCartesianAxis::setFontLabelScale(qreal scale)
changed = true; changed = true;
} }
void DiveCartesianAxis::setMaximum(double maximum) void DiveCartesianAxis::setBounds(double minimum, double maximum)
{ {
if (IS_FP_SAME(max, maximum)) changed = !IS_FP_SAME(max, maximum) || !IS_FP_SAME(min, minimum);
return;
max = maximum;
changed = true;
}
void DiveCartesianAxis::setMinimum(double minimum)
{
if (IS_FP_SAME(min, minimum))
return;
min = minimum; min = minimum;
changed = true; max = maximum;
} }
DiveCartesianAxis::DiveCartesianAxis(Position position, color_index_t gridColor, double dpr, 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)) if (IS_FP_SAME(maximum(), pp))
return; return;
setMaximum(pp); setBounds(0.0, pp);
setTickInterval(pp > 4 ? 0.5 : 0.25); setTickInterval(pp > 4 ? 0.5 : 0.25);
updateTicks(animSpeed); updateTicks(animSpeed);
} }

View file

@ -35,8 +35,7 @@ public:
DiveCartesianAxis(Position position, color_index_t gridColor, double dpr, DiveCartesianAxis(Position position, color_index_t gridColor, double dpr,
bool printMode, bool isGrayscale, ProfileScene &scene); bool printMode, bool isGrayscale, ProfileScene &scene);
~DiveCartesianAxis(); ~DiveCartesianAxis();
void setMinimum(double minimum); void setBounds(double min, double max);
void setMaximum(double maximum);
void setTickInterval(double interval); void setTickInterval(double interval);
void setOrientation(Orientation orientation); void setOrientation(Orientation orientation);
void setFontLabelScale(qreal scale); void setFontLabelScale(qreal scale);

View file

@ -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? // Initialize axes. Perhaps part of this should be moved down to the axes code?
profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom); profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom);
profileYAxis->setMinimum(0);
profileYAxis->setTickInterval(M_OR_FT(10, 30)); profileYAxis->setTickInterval(M_OR_FT(10, 30));
gasYAxis->setOrientation(DiveCartesianAxis::BottomToTop); gasYAxis->setOrientation(DiveCartesianAxis::BottomToTop);
gasYAxis->setTickInterval(1); gasYAxis->setTickInterval(1);
gasYAxis->setMinimum(0);
gasYAxis->setFontLabelScale(0.7); gasYAxis->setFontLabelScale(0.7);
#ifndef SUBSURFACE_MOBILE #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 // 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. // 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); profileYAxis->updateTicks(animSpeed);
temperatureAxis->setMinimum(plotInfo.mintemp); temperatureAxis->setBounds(plotInfo.mintemp,
temperatureAxis->setMaximum(plotInfo.maxtemp - plotInfo.mintemp > 2000 ? plotInfo.maxtemp : plotInfo.mintemp + 2000); plotInfo.maxtemp - plotInfo.mintemp > 2000 ? plotInfo.maxtemp : plotInfo.mintemp + 2000);
if (hasHeartBeat) { if (hasHeartBeat) {
int heartBeatAxisMin = lrint(plotInfo.minhr / 5.0 - 0.5) * 5; 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 else
heartBeatAxisTick = 50; heartBeatAxisTick = 50;
for (heartBeatAxisMax = heartBeatAxisMin; heartBeatAxisMax < plotInfo.maxhr; heartBeatAxisMax += heartBeatAxisTick); for (heartBeatAxisMax = heartBeatAxisMin; heartBeatAxisMax < plotInfo.maxhr; heartBeatAxisMax += heartBeatAxisTick);
heartBeatAxis->setMinimum(heartBeatAxisMin); heartBeatAxis->setBounds(heartBeatAxisMin, heartBeatAxisMax + 1);
heartBeatAxis->setMaximum(heartBeatAxisMax + 1);
heartBeatAxis->setTickInterval(heartBeatAxisTick); heartBeatAxis->setTickInterval(heartBeatAxisTick);
heartBeatAxis->updateTicks(animSpeed); // this shows the ticks heartBeatAxis->updateTicks(animSpeed); // this shows the ticks
} }
percentageAxis->setMinimum(0); percentageAxis->setBounds(0, 100);
percentageAxis->setMaximum(100);
percentageAxis->setVisible(false); percentageAxis->setVisible(false);
percentageAxis->updateTicks(animSpeed); percentageAxis->updateTicks(animSpeed);
if (calcMax) if (calcMax)
timeAxis->setMaximum(maxtime); timeAxis->setBounds(0.0, maxtime);
int i, incr; int i, incr;
static int increments[8] = { 10, 20, 30, 60, 5 * 60, 10 * 60, 15 * 60, 30 * 60 }; 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; incr *= 2;
timeAxis->setTickInterval(incr); timeAxis->setTickInterval(incr);
timeAxis->updateTicks(animSpeed); timeAxis->updateTicks(animSpeed);
cylinderPressureAxis->setMinimum(plotInfo.minpressure); cylinderPressureAxis->setBounds(plotInfo.minpressure, plotInfo.maxpressure);
cylinderPressureAxis->setMaximum(plotInfo.maxpressure);
#ifdef SUBSURFACE_MOBILE #ifdef SUBSURFACE_MOBILE
if (currentdc->divemode == CCR) { if (currentdc->divemode == CCR) {

View file

@ -970,7 +970,7 @@ void ProfileWidget2::divePlannerHandlerMoved()
// Grow the time axis if necessary. // Grow the time axis if necessary.
int minutes = lrint(profileScene->timeAxis->valueAt(activeHandler->pos()) / 60); int minutes = lrint(profileScene->timeAxis->valueAt(activeHandler->pos()) / 60);
if (minutes * 60 > profileScene->timeAxis->maximum() * 0.9) 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); divedatapoint data = plannerModel->at(index);
data.depth.mm = lrint(profileScene->profileYAxis->valueAt(activeHandler->pos()) / M_OR_FT(1, 1)) * M_OR_FT(1, 1); data.depth.mm = lrint(profileScene->profileYAxis->valueAt(activeHandler->pos()) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);