diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-11-15 10:21:57 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-11-15 13:50:35 -0800 |
commit | 2f77716e8f9bef3f9ef26dfdcb99f17e681c4c6f (patch) | |
tree | 7217e2cddf1af4dd3d411babe94673f8eebfcdf9 /qt-models | |
parent | 5e29245e689fe9401ee1c33ebb07c601ce25e8c6 (diff) | |
download | subsurface-2f77716e8f9bef3f9ef26dfdcb99f17e681c4c6f.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/divetripmodel.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
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); |