From 464721b2ecf27e4ecd7e3a29b78e626838ef82b8 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 18 Feb 2019 21:30:11 +0100 Subject: Undo: select dives on undo of editing commands Save selected dives when generating an edit-command. Restore the selection and current dive in undo()/redo(). Signed-off-by: Berthold Stoeger --- desktop-widgets/command_edit.cpp | 14 +++++++++++--- desktop-widgets/command_edit.h | 6 +++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/desktop-widgets/command_edit.cpp b/desktop-widgets/command_edit.cpp index b8727bfb6..f92d045aa 100644 --- a/desktop-widgets/command_edit.cpp +++ b/desktop-widgets/command_edit.cpp @@ -8,7 +8,7 @@ namespace Command { -static std::vector getSelectedDives(bool currentDiveOnly) +static std::vector getDives(bool currentDiveOnly) { if (currentDiveOnly) return current_dive ? std::vector { current_dive } @@ -27,7 +27,8 @@ static std::vector getSelectedDives(bool currentDiveOnly) template EditBase::EditBase(T newValue, bool currentDiveOnly) : value(std::move(newValue)), - dives(getSelectedDives(currentDiveOnly)), + dives(getDives(currentDiveOnly)), + selectedDives(getDiveSelection()), current(current_dive) { } @@ -88,6 +89,9 @@ void EditBase::undo() emit diveListNotifier.divesChanged(trip, divesInTrip, id); }); + if (setSelection(selectedDives, current)) + emit diveListNotifier.selectionChanged(); // If the selection changed -> tell the frontend + mark_divelist_changed(true); } @@ -404,7 +408,8 @@ DiveField EditMode::fieldId() const // ***** Tag based commands ***** EditTagsBase::EditTagsBase(const QStringList &newListIn, bool currentDiveOnly) : - dives(getSelectedDives(currentDiveOnly)), + dives(getDives(currentDiveOnly)), + selectedDives(getDiveSelection()), current(current_dive), newList(newListIn) { @@ -498,6 +503,9 @@ void EditTagsBase::undo() emit diveListNotifier.divesChanged(trip, divesInTrip, id); }); + if (setSelection(selectedDives, current)) + emit diveListNotifier.selectionChanged(); // If the selection changed -> tell the frontend + mark_divelist_changed(true); } diff --git a/desktop-widgets/command_edit.h b/desktop-widgets/command_edit.h index 4363cb9bd..9b5923af2 100644 --- a/desktop-widgets/command_edit.h +++ b/desktop-widgets/command_edit.h @@ -34,7 +34,9 @@ protected: bool workToBeDone() override; std::vector dives; // Dives to be edited. - struct dive *current; // On undo, we set the current dive at the time of the operation. + // On undo, we set the selection and current dive at the time of the operation. + std::vector selectedDives; + struct dive *current; public: EditBase(T newValue, bool currentDiveOnly); @@ -162,6 +164,8 @@ class EditTagsBase : public Base { // the active dive when the user initialized the action. This dive // will be made the current dive on redo / undo. std::vector dives; + // On undo, we set the selection and current dive at the time of the operation. + std::vector selectedDives; struct dive *current; QStringList newList; // Temporary until initialized public: -- cgit v1.2.3-70-g09d2