From 2f77716e8f9bef3f9ef26dfdcb99f17e681c4c6f Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 15 Nov 2019 10:21:57 +0100 Subject: Dive list: signal correct trip in DiveTripModelTree::topLevelChanged DiveTripModelTree::topLevelChanged() has pretty complex code, as it has to handle the fact that when adding/removing a dive from a trip, the trip can change its position. The code did not account for the fact that when moving an object back in the top level list, one has to subtract one from the new index, because the object was removed somewhere in the front of the list. To make matters worse, when an entry stayed where it was, this was realized by moving the entry right behind itself, which of course means that it stays where it is. But this meant that in the by far most common case (no moving) the wrong entry was updated. Fix this by subtracting 1 from the new index when moving an entry to the back. Signed-off-by: Berthold Stoeger --- qt-models/divetripmodel.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'qt-models') diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index bc64ef211..d8166d2eb 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -759,6 +759,11 @@ void DiveTripModelTree::topLevelChanged(int idx) endMoveRows(); } + // If we moved the object backwards in the array, we have to + // subtract one from the index to account for the removed object. + if (newIdx > idx) + --newIdx; + // Finally, inform UI of changed trip header QModelIndex tripIdx = createIndex(newIdx, 0, noParent); dataChanged(tripIdx, tripIdx); -- cgit v1.2.3-70-g09d2