Undo: unify selection behavior in dive-list commands

Some commands tried to retain the current selection on undo/redo,
others set the selection to the modified dives.

The latter was introduced because it was easier in some cases, but
it is probably more user-friendly because the user gets feedback
on the change.

Therefore, unify to always select the affected dives on undo()/redo().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-06-23 11:13:41 +02:00 committed by bstoeger
parent 27944a52b1
commit e1abf9485c
7 changed files with 48 additions and 56 deletions

View file

@ -614,6 +614,9 @@ void ShiftTime::redoit()
emit diveListNotifier.divesTimeChanged(timeChanged, diveList);
emit diveListNotifier.divesChanged(diveList, DiveField::DATETIME);
// Select the changed dives
restoreSelection(diveList.toStdVector(), diveList[0]);
// Negate the time-shift so that the next call does the reverse
timeChanged = -timeChanged;
}
@ -638,6 +641,13 @@ RenumberDives::RenumberDives(const QVector<QPair<dive *, int>> &divesToRenumberI
void RenumberDives::undoit()
{
renumberDives(divesToRenumber);
// Select the changed dives
std::vector<dive *> dives;
dives.reserve(divesToRenumber.size());
for (const QPair<dive *, int> &item: divesToRenumber)
dives.push_back(item.first);
restoreSelection(dives, dives[0]);
}
bool RenumberDives::workToBeDone()
@ -660,6 +670,13 @@ void TripBase::redoit()
{
moveDivesBetweenTrips(divesToMove);
sort_trip_table(&trip_table); // Though unlikely, moving dives may reorder trips
// Select the moved dives
std::vector<dive *> dives;
dives.reserve(divesToMove.divesToMove.size());
for (const DiveToTrip &item: divesToMove.divesToMove)
dives.push_back(item.dive);
restoreSelection(dives, dives[0]);
}
void TripBase::undoit()