From 20f525ceddbeee225c444c8cc0158004562b20df Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 15 Apr 2017 19:06:46 -0700 Subject: [PATCH] QML UI: correctly update dive list after editing timestamp Once we re-inserted the dive in the list we aren't done, quite the contrary - we now need to make sure that we handle any other changes and mark the dive list as updated. Signed-off-by: Dirk Hohndel --- mobile-widgets/qmlmanager.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index d53e5357a..1b5521e33 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -906,7 +906,7 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q // now that we have it all figured out, let's see what we need // to update DiveListModel *dm = DiveListModel::instance(); - int oldModelIdx = dm->getDiveIdx(d->id); + int modelIdx = dm->getDiveIdx(d->id); int oldIdx = get_idx_by_uniq_id(d->id); if (needResort) { // we know that the only thing that might happen in a resort is that @@ -914,9 +914,10 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q sort_table(&dive_table); int newIdx = get_idx_by_uniq_id(d->id); if (newIdx != oldIdx) { - DiveListModel::instance()->removeDive(oldModelIdx); - DiveListModel::instance()->insertDive(oldModelIdx - (newIdx - oldIdx), myDive); - diveChanged = false; // because we already modified things + DiveListModel::instance()->removeDive(modelIdx); + modelIdx += (newIdx - oldIdx); + DiveListModel::instance()->insertDive(modelIdx, myDive); + diveChanged = true; // because we already modified things } } if (diveChanged) { @@ -931,7 +932,7 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q d->meandepth.mm = d->dc.meandepth.mm = 0; d->dc = *fake_dc(&d->dc, true); } - DiveListModel::instance()->updateDive(oldModelIdx, d); + DiveListModel::instance()->updateDive(modelIdx, d); invalidate_dive_cache(d); mark_divelist_changed(true); }