From 9310d72943390f95d6742c2d5b40f025a40b4008 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 18 Mar 2020 19:35:25 +0100 Subject: [PATCH] models: update divesite-model when clearing/updating dive model When the dive list is cleared or updated, the entries in the divesite-model become stale and therefore the divesite-model (with the actual name LocationInformationModel) also must be updated. This was done manually in some parts of the code and forgotten in others. Therefore, do it directly in the clear() and reset() function of the dive list-model. This might be a bit of a layering violation: why should one model call into another if they are not in parent/child relationship? However, this seems easier than introducing a global "reset dives" function that coordinates the models. Moreover, it does not appear 100% safe: if the clearing of the divesite model causes accesses to the divelist-model, they happen in the midst of a model reset and we had horrible bugs with that kind of things. However, I don't think that should happen. Signed-off-by: Berthold Stoeger --- desktop-widgets/mainwindow.cpp | 1 - desktop-widgets/tab-widgets/maintab.cpp | 1 - qt-models/divetripmodel.cpp | 2 ++ 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index b55002285..8474eee71 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -660,7 +660,6 @@ void MainWindow::closeCurrentFile() setCurrentFile(nullptr); diveList->setSortOrder(DiveTripModelBase::NR, Qt::DescendingOrder); MapWidget::instance()->reload(); - LocationInformationModel::instance()->update(); if (!existing_filename) setTitle(); disableShortcuts(); diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index ca51feb05..252e135a6 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -517,7 +517,6 @@ void MainTab::reload() buddyModel.updateModel(); diveMasterModel.updateModel(); tagModel.updateModel(); - LocationInformationModel::instance()->update(); } void MainTab::refreshDisplayedDiveSite() diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index 677be21fb..e5a1b8cc5 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -474,6 +474,7 @@ void DiveTripModelBase::clear() beginResetModel(); clear_dive_file_data(); clearData(); + LocationInformationModel::instance()->update(); oldCurrent = nullptr; emit diveListNotifier.divesSelected({}); // Inform profile, etc of changed selection endResetModel(); @@ -485,6 +486,7 @@ void DiveTripModelBase::reset() beginResetModel(); clearData(); populate(); + LocationInformationModel::instance()->update(); endResetModel(); initSelection(); emit diveListNotifier.numShownChanged();