summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-07-22 09:23:47 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-11 16:22:27 -0700
commitdd9af8e72e169256f2d3ea53cff9d5bbd8feb9fa (patch)
tree2265ef07aa8b4944bac689cf84e5454501e39230
parentba9c35215e88dea0505e0f82531941797fc1ce7d (diff)
downloadsubsurface-dd9af8e72e169256f2d3ea53cff9d5bbd8feb9fa.tar.gz
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 <bstoeger@mail.tuwien.ac.at>
-rw-r--r--desktop-widgets/simplewidgets.cpp15
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp14
-rw-r--r--desktop-widgets/undocommands.cpp7
-rw-r--r--desktop-widgets/undocommands.h4
4 files changed, 16 insertions, 24 deletions
diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp
index 25345551a..b7f985bc9 100644
--- a/desktop-widgets/simplewidgets.cpp
+++ b/desktop-widgets/simplewidgets.cpp
@@ -240,18 +240,13 @@ void ShiftTimesDialog::buttonClicked(QAbstractButton *button)
if (amount != 0) {
// DANGER, DANGER - this could get our dive_table unsorted...
int i;
- struct dive *dive;
- QVector<int> affectedDives;
- for_each_dive (i, dive) {
- if (!dive->selected)
- continue;
-
- affectedDives.append(dive->id);
+ struct dive *d;
+ QVector<dive *> affectedDives;
+ for_each_dive (i, d) {
+ if (d->selected)
+ affectedDives.append(d);
}
MainWindow::instance()->undoStack->push(new UndoShiftTime(affectedDives, amount));
- MainWindow::instance()->dive_list()->rememberSelection();
- MainWindow::instance()->refreshDisplay();
- MainWindow::instance()->dive_list()->restoreSelection();
}
}
}
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index ee0ed9578..7f1e6cbc2 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -864,10 +864,6 @@ void MainTab::acceptChanges()
}
if (displayed_dive.watertemp.mkelvin != cd->watertemp.mkelvin)
MODIFY_DIVES(selectedDives, EDIT_VALUE(watertemp.mkelvin));
- if (displayed_dive.when != cd->when) {
- time_t offset = cd->when - displayed_dive.when;
- MODIFY_DIVES(selectedDives, mydive->when -= offset;);
- }
if (displayed_dive.dive_site_uuid != cd->dive_site_uuid)
MODIFY_DIVES(selectedDives, EDIT_VALUE(dive_site_uuid));
@@ -969,6 +965,12 @@ void MainTab::acceptChanges()
invalidate_dive_cache(d);
}
}
+
+ if (displayed_dive.when != cd->when) {
+ timestamp_t offset = cd->when - displayed_dive.when;
+ if (offset)
+ MainWindow::instance()->undoStack->push(new UndoShiftTime(selectedDives, (int)offset));
+ }
}
if (editMode != TRIP && current_dive->divetrip) {
current_dive->divetrip->when = current_dive->when;
@@ -987,9 +989,6 @@ void MainTab::acceptChanges()
int scrolledBy = MainWindow::instance()->dive_list()->verticalScrollBar()->sliderPosition();
resetPallete();
if (editMode == MANUALLY_ADDED_DIVE) {
- // since a newly added dive could be in the middle of the dive_table we need
- // to resort the dive list and make sure the newly added dive gets selected again
- sort_table(&dive_table);
MainWindow::instance()->dive_list()->reload(DiveTripModel::CURRENT, true);
int newDiveNr = get_divenr(get_dive_by_uniq_id(addedId));
MainWindow::instance()->dive_list()->unselectDives();
@@ -1002,7 +1001,6 @@ void MainTab::acceptChanges()
if (do_replot)
MainWindow::instance()->graphics()->replot();
MainWindow::instance()->dive_list()->rememberSelection();
- sort_table(&dive_table);
MainWindow::instance()->refreshDisplay();
MainWindow::instance()->dive_list()->restoreSelection();
}
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<int> changedDives, int amount)
+UndoShiftTime::UndoShiftTime(const QVector<dive *> &changedDives, int amount)
: diveList(changedDives), timeChanged(amount)
{
setText(tr("delete %n dive(s)", "", changedDives.size()));
@@ -155,10 +155,9 @@ UndoShiftTime::UndoShiftTime(QVector<int> 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);
diff --git a/desktop-widgets/undocommands.h b/desktop-widgets/undocommands.h
index 128c62e51..da30c27a0 100644
--- a/desktop-widgets/undocommands.h
+++ b/desktop-widgets/undocommands.h
@@ -189,13 +189,13 @@ private:
class UndoShiftTime : public QUndoCommand {
Q_DECLARE_TR_FUNCTIONS(Command)
public:
- UndoShiftTime(QVector<int> changedDives, int amount);
+ UndoShiftTime(const QVector<dive *> &changedDives, int amount);
private:
void undo() override;
void redo() override;
// For redo and undo
- QVector<int> diveList;
+ QVector<dive *> diveList;
int timeChanged;
};