diff options
-rw-r--r-- | qt-ui/simplewidgets.cpp | 12 | ||||
-rw-r--r-- | qt-ui/undocommands.cpp | 28 | ||||
-rw-r--r-- | qt-ui/undocommands.h | 11 |
3 files changed, 50 insertions, 1 deletions
diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp index 27050f6e2..eda567abd 100644 --- a/qt-ui/simplewidgets.cpp +++ b/qt-ui/simplewidgets.cpp @@ -15,6 +15,7 @@ #include "divelistview.h" #include "display.h" #include "profile/profilewidget2.h" +#include "undocommands.h" class MinMaxAvgWidgetPrivate { public: @@ -201,7 +202,16 @@ void ShiftTimesDialog::buttonClicked(QAbstractButton *button) amount *= -1; if (amount != 0) { // DANGER, DANGER - this could get our dive_table unsorted... - shift_times(amount); + int i; + struct dive *dive; + QList<int> affectedDives; + for_each_dive (i, dive) { + if (!dive->selected) + continue; + + affectedDives.append(dive->id); + } + MainWindow::instance()->undoStack->push(new UndoShiftTime(affectedDives, amount)); sort_table(&dive_table); mark_divelist_changed(true); MainWindow::instance()->dive_list()->rememberSelection(); diff --git a/qt-ui/undocommands.cpp b/qt-ui/undocommands.cpp index 8c58c7c96..316def495 100644 --- a/qt-ui/undocommands.cpp +++ b/qt-ui/undocommands.cpp @@ -34,3 +34,31 @@ void UndoDeleteDive::redo() dives.clear(); dives = newList; } + + +UndoShiftTime::UndoShiftTime(QList<int> diveList, int amount) +{ + setText("shift time"); + dives = diveList; + timeChanged = amount; +} + +void UndoShiftTime::undo() +{ + for (int i = 0; i < dives.count(); i++) { + struct dive* d = get_dive_by_uniq_id(dives.at(i)); + d->when -= timeChanged; + } + mark_divelist_changed(true); + MainWindow::instance()->refreshDisplay(); +} + +void UndoShiftTime::redo() +{ + for (int i = 0; i < dives.count(); i++) { + struct dive* d = get_dive_by_uniq_id(dives.at(i)); + d->when += timeChanged; + } + mark_divelist_changed(true); + MainWindow::instance()->refreshDisplay(); +} diff --git a/qt-ui/undocommands.h b/qt-ui/undocommands.h index 9a7803f9e..addef8138 100644 --- a/qt-ui/undocommands.h +++ b/qt-ui/undocommands.h @@ -14,4 +14,15 @@ private: QList<struct dive*> dives; }; +class UndoShiftTime : public QUndoCommand { +public: + UndoShiftTime(QList<int> diveList, int amount); + virtual void undo(); + virtual void redo(); + +private: + QList<int> dives; + int timeChanged; +}; + #endif // UNDOCOMMANDS_H |