diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2016-03-02 04:52:44 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-03-02 04:52:44 -0800 |
commit | 880f1c564413649f3fc359efefd34d3bbf01d91a (patch) | |
tree | 7a3ca704a6ec32211e50f11eb907b1fb59920781 /qt-mobile/qmlmanager.cpp | |
parent | 62f54b54a2aa625c9568ae1b3d954489a6cf08c0 (diff) | |
download | subsurface-880f1c564413649f3fc359efefd34d3bbf01d91a.tar.gz |
QML UI: update the correct dive in the model when committing a change
When manually adding a dive and moving it in the dive list (by editing
it's start time) we could create a situation where the dive list
internally was correct, but the dive list model on screen showed an
incorrect dive list with the new dive in two different spots.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-mobile/qmlmanager.cpp')
-rw-r--r-- | qt-mobile/qmlmanager.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp index 39b02e6a9..0ee745933 100644 --- a/qt-mobile/qmlmanager.cpp +++ b/qt-mobile/qmlmanager.cpp @@ -548,6 +548,10 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q free(d->notes); d->notes = strdup(qPrintable(notes)); } + // 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 oldIdx = get_idx_by_uniq_id(d->id); if (needResort) { // we know that the only thing that might happen in a resort is that @@ -556,8 +560,8 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q int newIdx = get_idx_by_uniq_id(d->id); if (newIdx != oldIdx) { DiveObjectHelper *newDive = new DiveObjectHelper(d); - DiveListModel::instance()->removeDive(oldIdx); - DiveListModel::instance()->insertDive(newIdx, newDive); + DiveListModel::instance()->removeDive(oldModelIdx); + DiveListModel::instance()->insertDive(oldModelIdx - (newIdx - oldIdx), newDive); diveChanged = false; // because we already modified things } } @@ -573,7 +577,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(oldIdx, d); + DiveListModel::instance()->updateDive(oldModelIdx, d); } if (diveChanged || needResort) { mark_divelist_changed(true); |