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>
This commit is contained in:
Jan Mulder 2017-12-14 15:41:47 +01:00 committed by Dirk Hohndel
parent 62ef78b5e8
commit dd87350cb7

View file

@ -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()