diff options
author | Jan Mulder <jlmulder@xs4all.nl> | 2017-12-14 15:41:47 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-12-14 08:53:06 -0800 |
commit | dd87350cb7b3ce7da924a01034fcf8149aeb797a (patch) | |
tree | 38c7354d076040aaa51533b40647c50384f39fc5 /qt-models | |
parent | 62ef78b5e8db4fb95a915c15e3fe117f99df7f65 (diff) | |
download | subsurface-dd87350cb7b3ce7da924a01034fcf8149aeb797a.tar.gz |
mobile: stay on same dive after edit
See issue #875. In hindsight the reason for this bug is easy to
understand. When updating a dive, the dive was first removed
from the model, and added in its new state again. This does seems
resonable, but the delete in the model causes the internal (QML)
state to be changed, and the previous state (like the currentIndex
that was pointing to the just deleted row, so that one is changed to
something valid internally) is not restored at recreation of
the edited dive. The QML engine has no way to understand that
the remove and subsequent add are in fact one atomic operation.
This can be solved by simply updating the underlying data in
place, and notifying the change using a dataChanged emitted
signal. The dataChanged signal takes care of the repaint of
the screen, and there is no need for removeRow/insertRow pairs.
Fixes: #875
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/divelistmodel.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp index a0f181405..ba99e47bb 100644 --- a/qt-models/divelistmodel.cpp +++ b/qt-models/divelistmodel.cpp @@ -93,8 +93,8 @@ void DiveListModel::removeDiveById(int id) void DiveListModel::updateDive(int i, dive *d) { DiveObjectHelper *newDive = new DiveObjectHelper(d); - removeDive(i); - insertDive(i, newDive); + m_dives.replace(i, newDive); + emit dataChanged(createIndex(i, 0), createIndex(i, 0)); } void DiveListModel::clear() |