summaryrefslogtreecommitdiffstats
path: root/mobile-widgets/qmlmanager.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2016-04-14 06:01:36 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-04-14 09:43:33 -0700
commit6e6cce770b671cea58251475546c77c5bc1468be (patch)
treecff3bd7b738bc9e08a0325d8d65bf7b08e4c502d /mobile-widgets/qmlmanager.cpp
parent5909e438c9394f7e831d7d9f912788ade87b6b1f (diff)
downloadsubsurface-6e6cce770b671cea58251475546c77c5bc1468be.tar.gz
QML UI: keep QML manager and the UI in sync about selected dive
The manager can now directly update the index of the selected dive, and the UI tells the manager the timestamp of the currently selected dive. This allows the manager to pick the best possible dive as selected dive if things change (for example if the dive list gets reloaded because it changed in cloud storage). Fixes #1009 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets/qmlmanager.cpp')
-rw-r--r--mobile-widgets/qmlmanager.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 569f1ac80..51a06f0a6 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -385,6 +385,8 @@ void QMLManager::loadDivesWithValidCredentials()
return;
}
appendTextToLog("Cloud sync brought newer data, reloading the dive list");
+ timestamp_t currentDiveTimestamp = selectedDiveTimestamp();
+
clear_dive_file_data();
if (git != dummy_git_repository) {
appendTextToLog(QString("have repository and branch %1").arg(branch));
@@ -414,6 +416,7 @@ void QMLManager::loadDivesWithValidCredentials()
DiveListModel::instance()->clear();
process_dives(false, false);
DiveListModel::instance()->addAllDives();
+ setUpdateSelectedDive(dlSortModel->getIdxForId(get_dive_id_closest_to(currentDiveTimestamp)));
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."));
@@ -1128,6 +1131,28 @@ void QMLManager::setSyncToCloud(bool status)
emit syncToCloudChanged();
}
+int QMLManager::updateSelectedDive() const
+{
+ return m_updateSelectedDive;
+}
+
+void QMLManager::setUpdateSelectedDive(int idx)
+{
+ m_updateSelectedDive = idx;
+ emit updateSelectedDiveChanged();
+}
+
+int QMLManager::selectedDiveTimestamp() const
+{
+ return m_selectedDiveTimestamp;
+}
+
+void QMLManager::setSelectedDiveTimestamp(int when)
+{
+ m_selectedDiveTimestamp = when;
+ emit selectedDiveTimestampChanged();
+}
+
qreal QMLManager::lastDevicePixelRatio()
{
return m_lastDevicePixelRatio;