diff options
-rw-r--r-- | mobile-widgets/qml/DiveDetails.qml | 13 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 25 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.h | 12 |
3 files changed, 50 insertions, 0 deletions
diff --git a/mobile-widgets/qml/DiveDetails.qml b/mobile-widgets/qml/DiveDetails.qml index d562e0a98..262f2042c 100644 --- a/mobile-widgets/qml/DiveDetails.qml +++ b/mobile-widgets/qml/DiveDetails.qml @@ -9,6 +9,7 @@ import org.kde.kirigami 1.0 as Kirigami Kirigami.Page { id: diveDetailsPage property alias currentIndex: diveDetailsListView.currentIndex + property alias currentItem: diveDetailsListView.currentItem property alias dive_id: detailsEdit.dive_id property alias number: detailsEdit.number property alias date: detailsEdit.dateText @@ -25,6 +26,7 @@ Kirigami.Page { property alias startpressure: detailsEdit.startpressureText property alias endpressure: detailsEdit.endpressureText property alias gasmix: detailsEdit.gasmixText + property int updateCurrentIdx: manager.updateSelectedDive title: diveDetailsListView.currentItem ? diveDetailsListView.currentItem.modelData.dive.location : "Dive details" state: "view" @@ -108,6 +110,17 @@ Kirigami.Page { // if we were in view mode, don't accept the event and pop the page } + onUpdateCurrentIdxChanged: { + if (diveDetailsListView.currentIndex != updateCurrentIdx) { + diveDetailsListView.currentIndex = updateCurrentIdx + manager.selectedDiveTimestamp = diveDetailsListView.currentItem.modelData.dive.timestamp + } + } + + onCurrentItemChanged: { + manager.selectedDiveTimestamp = diveDetailsListView.currentItem.modelData.dive.timestamp + } + function showDiveIndex(index) { currentIndex = index; diveDetailsListView.positionViewAtIndex(index, ListView.Beginning); 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; diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index d905fe236..5b8fb6848 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -26,6 +26,8 @@ class QMLManager : public QObject { Q_PROPERTY(credentialStatus_t oldStatus READ oldStatus WRITE setOldStatus NOTIFY oldStatusChanged) Q_PROPERTY(int accessingCloud READ accessingCloud WRITE setAccessingCloud NOTIFY accessingCloudChanged) Q_PROPERTY(bool syncToCloud READ syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged) + Q_PROPERTY(int updateSelectedDive READ updateSelectedDive WRITE setUpdateSelectedDive NOTIFY updateSelectedDiveChanged) + Q_PROPERTY(int selectedDiveTimestamp READ selectedDiveTimestamp WRITE setSelectedDiveTimestamp NOTIFY selectedDiveTimestampChanged) public: QMLManager(); @@ -81,6 +83,12 @@ public: bool syncToCloud() const; void setSyncToCloud(bool status); + int updateSelectedDive() const; + void setUpdateSelectedDive(int idx); + + int selectedDiveTimestamp() const; + void setSelectedDiveTimestamp(int when); + typedef void (QMLManager::*execute_function_type)(); DiveListSortModel *dlSortModel; @@ -144,6 +152,8 @@ private: struct dive_trip *deletedTrip; int m_accessingCloud; bool m_syncToCloud; + int m_updateSelectedDive; + int m_selectedDiveTimestamp; credentialStatus_t m_credentialStatus; credentialStatus_t m_oldStatus; qreal m_lastDevicePixelRatio; @@ -164,6 +174,8 @@ signals: void oldStatusChanged(); void accessingCloudChanged(); void syncToCloudChanged(); + void updateSelectedDiveChanged(); + void selectedDiveTimestampChanged(); void sendScreenChanged(QScreen *screen); }; |