mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
5909e438c9
commit
6e6cce770b
3 changed files with 50 additions and 0 deletions
|
@ -9,6 +9,7 @@ import org.kde.kirigami 1.0 as Kirigami
|
||||||
Kirigami.Page {
|
Kirigami.Page {
|
||||||
id: diveDetailsPage
|
id: diveDetailsPage
|
||||||
property alias currentIndex: diveDetailsListView.currentIndex
|
property alias currentIndex: diveDetailsListView.currentIndex
|
||||||
|
property alias currentItem: diveDetailsListView.currentItem
|
||||||
property alias dive_id: detailsEdit.dive_id
|
property alias dive_id: detailsEdit.dive_id
|
||||||
property alias number: detailsEdit.number
|
property alias number: detailsEdit.number
|
||||||
property alias date: detailsEdit.dateText
|
property alias date: detailsEdit.dateText
|
||||||
|
@ -25,6 +26,7 @@ Kirigami.Page {
|
||||||
property alias startpressure: detailsEdit.startpressureText
|
property alias startpressure: detailsEdit.startpressureText
|
||||||
property alias endpressure: detailsEdit.endpressureText
|
property alias endpressure: detailsEdit.endpressureText
|
||||||
property alias gasmix: detailsEdit.gasmixText
|
property alias gasmix: detailsEdit.gasmixText
|
||||||
|
property int updateCurrentIdx: manager.updateSelectedDive
|
||||||
|
|
||||||
title: diveDetailsListView.currentItem ? diveDetailsListView.currentItem.modelData.dive.location : "Dive details"
|
title: diveDetailsListView.currentItem ? diveDetailsListView.currentItem.modelData.dive.location : "Dive details"
|
||||||
state: "view"
|
state: "view"
|
||||||
|
@ -108,6 +110,17 @@ Kirigami.Page {
|
||||||
// if we were in view mode, don't accept the event and pop the 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) {
|
function showDiveIndex(index) {
|
||||||
currentIndex = index;
|
currentIndex = index;
|
||||||
diveDetailsListView.positionViewAtIndex(index, ListView.Beginning);
|
diveDetailsListView.positionViewAtIndex(index, ListView.Beginning);
|
||||||
|
|
|
@ -385,6 +385,8 @@ void QMLManager::loadDivesWithValidCredentials()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
appendTextToLog("Cloud sync brought newer data, reloading the dive list");
|
appendTextToLog("Cloud sync brought newer data, reloading the dive list");
|
||||||
|
timestamp_t currentDiveTimestamp = selectedDiveTimestamp();
|
||||||
|
|
||||||
clear_dive_file_data();
|
clear_dive_file_data();
|
||||||
if (git != dummy_git_repository) {
|
if (git != dummy_git_repository) {
|
||||||
appendTextToLog(QString("have repository and branch %1").arg(branch));
|
appendTextToLog(QString("have repository and branch %1").arg(branch));
|
||||||
|
@ -414,6 +416,7 @@ void QMLManager::loadDivesWithValidCredentials()
|
||||||
DiveListModel::instance()->clear();
|
DiveListModel::instance()->clear();
|
||||||
process_dives(false, false);
|
process_dives(false, false);
|
||||||
DiveListModel::instance()->addAllDives();
|
DiveListModel::instance()->addAllDives();
|
||||||
|
setUpdateSelectedDive(dlSortModel->getIdxForId(get_dive_id_closest_to(currentDiveTimestamp)));
|
||||||
appendTextToLog(QStringLiteral("%1 dives loaded").arg(dive_table.nr));
|
appendTextToLog(QStringLiteral("%1 dives loaded").arg(dive_table.nr));
|
||||||
if (dive_table.nr == 0)
|
if (dive_table.nr == 0)
|
||||||
setStartPageText(tr("Cloud storage open successfully. No dives in dive list."));
|
setStartPageText(tr("Cloud storage open successfully. No dives in dive list."));
|
||||||
|
@ -1128,6 +1131,28 @@ void QMLManager::setSyncToCloud(bool status)
|
||||||
emit syncToCloudChanged();
|
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()
|
qreal QMLManager::lastDevicePixelRatio()
|
||||||
{
|
{
|
||||||
return m_lastDevicePixelRatio;
|
return m_lastDevicePixelRatio;
|
||||||
|
|
|
@ -26,6 +26,8 @@ class QMLManager : public QObject {
|
||||||
Q_PROPERTY(credentialStatus_t oldStatus READ oldStatus WRITE setOldStatus NOTIFY oldStatusChanged)
|
Q_PROPERTY(credentialStatus_t oldStatus READ oldStatus WRITE setOldStatus NOTIFY oldStatusChanged)
|
||||||
Q_PROPERTY(int accessingCloud READ accessingCloud WRITE setAccessingCloud NOTIFY accessingCloudChanged)
|
Q_PROPERTY(int accessingCloud READ accessingCloud WRITE setAccessingCloud NOTIFY accessingCloudChanged)
|
||||||
Q_PROPERTY(bool syncToCloud READ syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged)
|
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:
|
public:
|
||||||
QMLManager();
|
QMLManager();
|
||||||
|
@ -81,6 +83,12 @@ public:
|
||||||
bool syncToCloud() const;
|
bool syncToCloud() const;
|
||||||
void setSyncToCloud(bool status);
|
void setSyncToCloud(bool status);
|
||||||
|
|
||||||
|
int updateSelectedDive() const;
|
||||||
|
void setUpdateSelectedDive(int idx);
|
||||||
|
|
||||||
|
int selectedDiveTimestamp() const;
|
||||||
|
void setSelectedDiveTimestamp(int when);
|
||||||
|
|
||||||
typedef void (QMLManager::*execute_function_type)();
|
typedef void (QMLManager::*execute_function_type)();
|
||||||
DiveListSortModel *dlSortModel;
|
DiveListSortModel *dlSortModel;
|
||||||
|
|
||||||
|
@ -144,6 +152,8 @@ private:
|
||||||
struct dive_trip *deletedTrip;
|
struct dive_trip *deletedTrip;
|
||||||
int m_accessingCloud;
|
int m_accessingCloud;
|
||||||
bool m_syncToCloud;
|
bool m_syncToCloud;
|
||||||
|
int m_updateSelectedDive;
|
||||||
|
int m_selectedDiveTimestamp;
|
||||||
credentialStatus_t m_credentialStatus;
|
credentialStatus_t m_credentialStatus;
|
||||||
credentialStatus_t m_oldStatus;
|
credentialStatus_t m_oldStatus;
|
||||||
qreal m_lastDevicePixelRatio;
|
qreal m_lastDevicePixelRatio;
|
||||||
|
@ -164,6 +174,8 @@ signals:
|
||||||
void oldStatusChanged();
|
void oldStatusChanged();
|
||||||
void accessingCloudChanged();
|
void accessingCloudChanged();
|
||||||
void syncToCloudChanged();
|
void syncToCloudChanged();
|
||||||
|
void updateSelectedDiveChanged();
|
||||||
|
void selectedDiveTimestampChanged();
|
||||||
void sendScreenChanged(QScreen *screen);
|
void sendScreenChanged(QScreen *screen);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue