From dd87350cb7b3ce7da924a01034fcf8149aeb797a Mon Sep 17 00:00:00 2001 From: Jan Mulder Date: Thu, 14 Dec 2017 15:41:47 +0100 Subject: 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 --- qt-models/divelistmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qt-models') 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() -- cgit v1.2.3-70-g09d2