selection: remove current_dive and dc_number access from tabwidgets

An attempt at limitting accesses to the globals current_dive and
dc_number. These globals do not make sense on mobile.

The parent widget of the tab-widgets remembers the currently
displayer dive and dive computer and the individual widgets
access these values from there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-09-17 16:21:17 +02:00 committed by bstoeger
parent 8cd191c271
commit 6f03fc9689
8 changed files with 125 additions and 96 deletions

View file

@ -26,6 +26,7 @@ static bool paletteIsDark(const QPalette &p)
}
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
currentDive(nullptr),
lastSelectedDive(true),
lastTabSelectedDive(0),
lastTabSelectedDiveTrip(0)
@ -73,11 +74,16 @@ void MainTab::nextInputField(QKeyEvent *event)
void MainTab::settingsChanged()
{
// TODO: remember these
updateDiveInfo(getDiveSelection(), current_dive, dc_number);
updateDiveInfo(getDiveSelection(), currentDive, currentDC);
}
void MainTab::updateDiveInfo(const std::vector<dive *> &selection, dive *currentDive, int currentDC)
void MainTab::updateDiveInfo(const std::vector<dive *> &selection, dive *currentDiveIn, int currentDCIn)
{
// Remember current dive and divecomputer. This is needed to refresh the
// display, for example when the settings change.
currentDive = currentDiveIn;
currentDC = currentDCIn;
// don't execute this while planning a dive
if (DivePlannerPointsModel::instance()->isPlanner())
return;
@ -172,3 +178,15 @@ void MainTab::colorsChanged()
for (TabBase *widget: extraWidgets)
widget->updateUi(colorText);
}
// Called when dives changed. Checks whether the currently displayed
// dive is affected by the change.
bool MainTab::includesCurrentDive(const QVector<dive *> &dives) const
{
return currentDive && dives.contains(currentDive);
}
divecomputer *MainTab::getCurrentDC() const
{
return get_dive_dc(currentDive, currentDC);
}