profile: factor out updating of visibility from setProfileState()

The plan is to simplify the visibility-control of non-interactive
chart features. As a first step identify those features that
depend on preferences-flags and factor out the setting of their
visibility into a new function updateVisibility().

This commit effectively only reorders the setting of the
visibility and therefore should have not user-visible effect.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-07-12 22:27:58 +02:00 committed by Dirk Hohndel
parent 80fe85067c
commit cab179601f
2 changed files with 34 additions and 34 deletions

View file

@ -1095,6 +1095,38 @@ void ProfileWidget2::setProfileState(const dive *dIn, int dcIn)
setProfileState();
}
// Update visibility of non-interactive chart features according to preferences
void ProfileWidget2::updateVisibility()
{
#ifndef SUBSURFACE_MOBILE
pn2GasItem->setVisible(prefs.pp_graphs.pn2);
po2GasItem->setVisible(prefs.pp_graphs.po2);
pheGasItem->setVisible(prefs.pp_graphs.phe);
const struct divecomputer *currentdc = d ? get_dive_dc_const(d, dc) : nullptr;
bool setpointflag = currentdc && currentdc->divemode == CCR && prefs.pp_graphs.po2;
bool sensorflag = setpointflag && prefs.show_ccr_sensors;
o2SetpointGasItem->setVisible(setpointflag && prefs.show_ccr_setpoint);
ccrsensor1GasItem->setVisible(sensorflag);
ccrsensor2GasItem->setVisible(currentdc && sensorflag && currentdc->no_o2sensors > 1);
ccrsensor3GasItem->setVisible(currentdc && sensorflag && currentdc->no_o2sensors > 2);
ocpo2GasItem->setVisible(currentdc && currentdc->divemode == PSCR && prefs.show_scr_ocpo2);
heartBeatItem->setVisible(prefs.hrgraph);
#endif
diveCeiling->setVisible(prefs.calcceiling);
decoModelParameters->setVisible(prefs.calcceiling);
#ifndef SUBSURFACE_MOBILE
for (DiveCalculatedTissue *tissue: allTissues)
tissue->setVisible(prefs.calcalltissues);
for (DivePercentageItem *percentage: allPercentages)
percentage->setVisible(prefs.percentagegraph);
#endif
meanDepthItem->setVisible(prefs.show_average_depth);
reportedCeiling->setVisible(prefs.dcceiling);
tankItem->setVisible(prefs.tankbar);
}
void ProfileWidget2::setProfileState()
{
// Then starting Empty State, move the background up.
@ -1120,50 +1152,16 @@ void ProfileWidget2::setProfileState()
#ifndef SUBSURFACE_MOBILE
toolTipItem->readPos();
toolTipItem->setVisible(true);
pn2GasItem->setVisible(prefs.pp_graphs.pn2);
po2GasItem->setVisible(prefs.pp_graphs.po2);
pheGasItem->setVisible(prefs.pp_graphs.phe);
const struct divecomputer *currentdc = d ? get_dive_dc_const(d, dc) : nullptr;
bool setpointflag = currentdc && currentdc->divemode == CCR && prefs.pp_graphs.po2;
bool sensorflag = setpointflag && prefs.show_ccr_sensors;
o2SetpointGasItem->setVisible(setpointflag && prefs.show_ccr_setpoint);
ccrsensor1GasItem->setVisible(sensorflag);
ccrsensor2GasItem->setVisible(currentdc && sensorflag && currentdc->no_o2sensors > 1);
ccrsensor3GasItem->setVisible(currentdc && sensorflag && currentdc->no_o2sensors > 2);
ocpo2GasItem->setVisible(currentdc && currentdc->divemode == PSCR && prefs.show_scr_ocpo2);
heartBeatItem->setVisible(prefs.hrgraph);
#endif
diveCeiling->setVisible(prefs.calcceiling);
decoModelParameters->setVisible(prefs.calcceiling);
#ifndef SUBSURFACE_MOBILE
if (prefs.calcalltissues) {
Q_FOREACH (DiveCalculatedTissue *tissue, allTissues) {
tissue->setVisible(true);
}
}
if (prefs.percentagegraph) {
Q_FOREACH (DivePercentageItem *percentage, allPercentages) {
percentage->setVisible(true);
}
}
rulerItem->setVisible(prefs.rulergraph);
#endif
timeAxis->setPos(itemPos.time.pos.on);
timeAxis->setLine(itemPos.time.expanded);
cylinderPressureAxis->setPos(itemPos.cylinder.pos.on);
meanDepthItem->setVisible(prefs.show_average_depth);
diveComputerText->setVisible(true);
diveComputerText->setPos(itemPos.dcLabel.on);
reportedCeiling->setVisible(prefs.dcceiling);
tankItem->setVisible(prefs.tankbar);
tankItem->setPos(itemPos.tankBar.on);
#ifndef SUBSURFACE_MOBILE
@ -1172,6 +1170,7 @@ void ProfileWidget2::setProfileState()
mouseFollowerVertical->setVisible(false);
#endif
hideAll(gases);
updateVisibility();
}
#ifndef SUBSURFACE_MOBILE

View file

@ -127,6 +127,7 @@ slots: // Necessary to call from QAction's signals.
private:
void setProfileState(); // keep currently displayed dive
void updateAxes(); // Update axes according to preferences
void updateVisibility(); // Update visibility of non-interactive chart features according to preferences
void resizeEvent(QResizeEvent *event) override;
#ifndef SUBSURFACE_MOBILE
void wheelEvent(QWheelEvent *event) override;