summaryrefslogtreecommitdiffstats
path: root/mobile-widgets/qmlmanager.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-05-05 00:12:36 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-05-07 08:43:27 -0700
commitfb6210a99a1eda0f7f7197ed57f3c61a82132dff (patch)
tree7562feb3291d06173b971437d1bd3395b2722eff /mobile-widgets/qmlmanager.cpp
parentaeee2a08027b177495635262114374f085351ce7 (diff)
downloadsubsurface-fb6210a99a1eda0f7f7197ed57f3c61a82132dff.tar.gz
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>
Diffstat (limited to 'mobile-widgets/qmlmanager.cpp')
-rw-r--r--mobile-widgets/qmlmanager.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 8e614ec2b..36394364b 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -339,7 +339,7 @@ void QMLManager::applicationStateChanged(Qt::ApplicationState state)
void QMLManager::openLocalThenRemote(QString url)
{
// clear out the models and the fulltext index
- MobileModels::instance()->clear();
+ clear_dive_file_data();
setDiveListProcessing(true);
setNotificationText(tr("Open local dive data file"));
appendTextToLog(QString("Open dive data file %1 - git_local only is %2").arg(url).arg(git_local_only));
@@ -383,7 +383,6 @@ void QMLManager::openLocalThenRemote(QString url)
// the following steps can take a long time, so provide updates
setNotificationText(tr("Processing %1 dives").arg(dive_table.nr));
process_loaded_dives();
- MobileModels::instance()->reset();
setNotificationText(tr("%1 dives loaded from local dive data file").arg(dive_table.nr));
}
if (qPrefCloudStorage::cloud_verification_status() == qPrefCloudStorage::CS_NEED_TO_VERIFY) {
@@ -612,8 +611,7 @@ void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &ne
syncLoadFromCloud();
manager()->clearAccessCache(); // remove any chached credentials
clear_git_id(); // invalidate our remembered GIT SHA
- MobileModels::instance()->clear();
- GpsListModel::instance()->clear();
+ clear_dive_file_data();
setStartPageText(tr("Attempting to open cloud storage with new credentials"));
// since we changed credentials, we need to try to connect to the cloud, regardless
// of whether we're in offline mode or not, to make sure the repository is synced
@@ -687,7 +685,7 @@ void QMLManager::loadDivesWithValidCredentials()
// if we aren't switching from no-cloud mode, let's clear the dive data
if (!noCloudToCloud) {
appendTextToLog("Clear out in memory dive data");
- MobileModels::instance()->clear();
+ clear_dive_file_data();
} else {
appendTextToLog("Switching from no cloud mode; keep in memory dive data");
}
@@ -717,7 +715,6 @@ void QMLManager::loadDivesWithValidCredentials()
if (noCloudToCloud) {
git_storage_update_progress(qPrintable(tr("Loading dives from local storage ('no cloud' mode)")));
mergeLocalRepo();
- MobileModels::instance()->reset();
appendTextToLog(QStringLiteral("%1 dives loaded after importing nocloud local storage").arg(dive_table.nr));
noCloudToCloud = false;
mark_divelist_changed(true);
@@ -779,7 +776,6 @@ void QMLManager::consumeFinishedLoad()
prefs.show_ccr_sensors = git_prefs.show_ccr_sensors;
prefs.pp_graphs.po2 = git_prefs.pp_graphs.po2;
process_loaded_dives();
- MobileModels::instance()->reset();
appendTextToLog(QStringLiteral("%1 dives loaded").arg(dive_table.nr));
if (dive_table.nr == 0)
setStartPageText(tr("Cloud storage open successfully. No dives in dive list."));
@@ -787,7 +783,7 @@ void QMLManager::consumeFinishedLoad()
void QMLManager::refreshDiveList()
{
- MobileModels::instance()->reset();
+ MobileModels::instance()->invalidate();
}
// Ouch. Editing a dive might create a dive site or change an existing dive site.