From dd9af8e72e169256f2d3ea53cff9d5bbd8feb9fa Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 22 Jul 2018 09:23:47 +0200 Subject: Undo: make editing of dive-time an undoable operation The whole undo system assumes that the indexes in the dive table do not change under its feet. On desktop, there seems only one exception left: editing of the dive time. To circumvent this, hook editing of the dive-time to the already existing UndoShiftTime command. This introduces a temporary UI-inconsistency: this is the only edit that is reflected in the undo-list. This will be fixed in due course, when other edit actions are also made undoable. UndoShiftTime is changed to take pointers to dives (which should be stable by now) instead of uniq-ids. Signed-off-by: Berthold Stoeger --- desktop-widgets/undocommands.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'desktop-widgets/undocommands.cpp') diff --git a/desktop-widgets/undocommands.cpp b/desktop-widgets/undocommands.cpp index 9a56b4e9d..16f87fa23 100644 --- a/desktop-widgets/undocommands.cpp +++ b/desktop-widgets/undocommands.cpp @@ -147,7 +147,7 @@ void UndoDeleteDive::redo() } -UndoShiftTime::UndoShiftTime(QVector changedDives, int amount) +UndoShiftTime::UndoShiftTime(const QVector &changedDives, int amount) : diveList(changedDives), timeChanged(amount) { setText(tr("delete %n dive(s)", "", changedDives.size())); @@ -155,10 +155,9 @@ UndoShiftTime::UndoShiftTime(QVector changedDives, int amount) void UndoShiftTime::undo() { - for (int i = 0; i < diveList.count(); i++) { - dive *d = get_dive_by_uniq_id(diveList.at(i)); + for (dive *d: diveList) d->when -= timeChanged; - } + // Changing times may have unsorted the dive table sort_table(&dive_table); mark_divelist_changed(true); -- cgit v1.2.3-70-g09d2