From 4db5e840bf3662e84cc76f3ef3df4fa30e4f7dfc Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 5 Jan 2016 22:57:40 -0800 Subject: QML UI: refresh the dive list after edit This fixes two issues. In general, after edits the dive list wasn't updated so it showed data inconsistent with what the dive details showed (clearly bogus). Even more annoyingly, when we change the date or time of a dive it could obviously move around in the dive list. So we need to resort the dive table and recreate the dive list. For really long dive lists this is possibly overkill, but in my testing this seemed very quick and much easier than trying to manually get this right, even in the case where the list wasn't resorted. Signed-off-by: Dirk Hohndel --- qt-mobile/qmlmanager.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp index 9b6911b3a..439490b8d 100644 --- a/qt-mobile/qmlmanager.cpp +++ b/qt-mobile/qmlmanager.cpp @@ -314,9 +314,10 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q return; } bool diveChanged = false; + bool needResort = false; if (date != get_dive_date_string(d->when)) { - diveChanged = true; + needResort = true; QDateTime newDate; // what a pain - Qt will not parse dates if the day of the week is incorrect // so if the user changed the date but didn't update the day of the week (most likely behavior, actually), @@ -438,8 +439,14 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q free(d->notes); d->notes = strdup(qPrintable(notes)); } - if (diveChanged) { - DiveListModel::instance()->updateDive(d); + if (needResort) + sort_table(&dive_table); + if (diveChanged || needResort) { + int i; + DiveListModel::instance()->clear(); + for_each_dive(i, d) { + DiveListModel::instance()->addDive(d); + } mark_divelist_changed(true); } } -- cgit v1.2.3-70-g09d2