aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/undocommands.cpp
diff options
context:
space:
mode:
authorGravatar Grace Karanja <gracie.karanja89@gmail.com>2015-02-11 10:57:56 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-11 08:07:23 -0800
commit60a7404ed4c79398c08a9d83d6575a3381c999a1 (patch)
tree07e6d398f93f5dad7c42da1089cf832e07611fe8 /qt-ui/undocommands.cpp
parent6d996a78742deb349cc1cb66ddea6abfb1b813d5 (diff)
downloadsubsurface-60a7404ed4c79398c08a9d83d6575a3381c999a1.tar.gz
Add option to undo deleted dives
Add ability to undo deleted dives by storing a list of the deleted dives in a QUndoCommand. Signed-off-by: Grace Karanja <gracie.karanja89@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/undocommands.cpp')
-rw-r--r--qt-ui/undocommands.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/qt-ui/undocommands.cpp b/qt-ui/undocommands.cpp
index f76f021b3..8c58c7c96 100644
--- a/qt-ui/undocommands.cpp
+++ b/qt-ui/undocommands.cpp
@@ -1,16 +1,36 @@
#include "undocommands.h"
+#include "mainwindow.h"
+#include "divelist.h"
UndoDeleteDive::UndoDeleteDive(QList<dive *> diveList)
{
-
+ dives = diveList;
+ setText("delete dive");
+ if (dives.count() > 1)
+ setText(QString("delete %1 dives").arg(QString::number(dives.count())));
}
void UndoDeleteDive::undo()
{
-
+ for (int i = 0; i < dives.count(); i++)
+ record_dive(dives.at(i));
+ mark_divelist_changed(true);
+ MainWindow::instance()->refreshDisplay();
}
void UndoDeleteDive::redo()
{
-
+ QList<struct dive*> newList;
+ for (int i = 0; i < dives.count(); i++) {
+ //make a copy of the dive before deleting it
+ struct dive* d = alloc_dive();
+ copy_dive(dives.at(i), d);
+ newList.append(d);
+ //delete the dive
+ delete_single_dive(get_divenr(dives.at(i)));
+ }
+ mark_divelist_changed(true);
+ MainWindow::instance()->refreshDisplay();
+ dives.clear();
+ dives = newList;
}