cleanup: invert control-flow when resetting the core structures

To reset the core data structures, the mobile and desktop UIs
were calling into the dive-list models, which then reset the
core data structures, themselves and the unrelated
locationinformation model. The UI code then reset various other
things, such as the TankInformation model or the map. . This was
unsatisfying from a control-flow perspective, as the models should
display the core data, not act on it. Moreover, this meant lots
of intricate intermodule-dependencies.

Thus, straighten up the control flow: give the C core the
possibility to send a "all data reset" event. And do that
in those functions that reset the core data structures.
Let each module react to this event by itself. This removes
inter-module dependencies. For example, the MainWindow now
doesn't have to reset the TankInfoModel or the MapWidget.

Then, to reset the core data structures, let the UI code
simply directly call the respective core functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-05-05 00:12:36 +02:00 committed by Dirk Hohndel
parent aeee2a0802
commit fb6210a99a
18 changed files with 70 additions and 49 deletions

View file

@ -408,15 +408,12 @@ MainWindow *MainWindow::instance()
void MainWindow::refreshDisplay(bool doRecreateDiveList)
{
mainTab->reload();
TankInfoModel::instance()->update();
if (doRecreateDiveList)
diveList->reload();
MapWidget::instance()->reload();
setApplicationState(ApplicationState::Default);
diveList->setEnabled(true);
diveList->setFocus();
WSInfoModel::instance()->update();
ui.actionAutoGroup->setChecked(autogroup);
}
@ -647,7 +644,7 @@ void MainWindow::closeCurrentFile()
{
/* free the dives and trips */
clear_git_id();
MultiFilterSortModel::instance()->clear(); // this clears all the core data structures
clear_dive_file_data(); // this clears all the core data structures and resets the models
setCurrentFile(nullptr);
diveList->setSortOrder(DiveTripModelBase::NR, Qt::DescendingOrder);
MapWidget::instance()->reload();