summaryrefslogtreecommitdiffstats
path: root/qt-ui/undobuffer.cpp
diff options
context:
space:
mode:
authorGravatar Grace Karanja <gracie.karanja89@gmail.com>2015-02-09 09:44:10 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-09 21:02:19 -0800
commitd60a6201931ed11e019e7582a6d6f72d6f4e0400 (patch)
tree39d99b9267d924ca97bfe8435c56aa640e03fe3e /qt-ui/undobuffer.cpp
parent8d1e4557a96f81a4cf263ea3d4e2228222d99e42 (diff)
downloadsubsurface-d60a6201931ed11e019e7582a6d6f72d6f4e0400.tar.gz
Add ability to undo deleted dives
Before the dive is deleted, a copy is made and passed to the undo buffer. When edit->undo is clicked, this dive is restored to the dive list. Signed-off-by: Grace Karanja <gracie.karanja89@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/undobuffer.cpp')
-rw-r--r--qt-ui/undobuffer.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/qt-ui/undobuffer.cpp b/qt-ui/undobuffer.cpp
index 1812f6f7a..4ee0cf608 100644
--- a/qt-ui/undobuffer.cpp
+++ b/qt-ui/undobuffer.cpp
@@ -1,8 +1,9 @@
#include "undobuffer.h"
+#include "mainwindow.h"
UndoBuffer::UndoBuffer(QObject *parent) : QObject(parent)
{
-
+ curIdx = 0;
}
UndoBuffer::~UndoBuffer()
@@ -12,32 +13,46 @@ UndoBuffer::~UndoBuffer()
bool UndoBuffer::canUndo()
{
-
+ return curIdx > 0;
}
bool UndoBuffer::canRedo()
{
-
+ return curIdx < list.count();
}
void UndoBuffer::redo()
{
-
+ current()->redo();
+ curIdx++;
+ if (curIdx > list.count())
+ curIdx = list.count() - 1;
}
void UndoBuffer::undo()
{
-
+ current()->undo();
+ curIdx = list.indexOf(current());
}
void UndoBuffer::recordbefore(QString commandName, dive *affectedDive)
{
-
+ UndoCommand *cmd = new UndoCommand(commandName, affectedDive);
+ //If we are within the list, clear the extra UndoCommands.
+ if (list.count() > 0) {
+ if (curIdx + 1 < list.count()) {
+ for (int i = curIdx + 1; i < list.count(); i++) {
+ list.removeAt(i);
+ }
+ }
+ }
+ list.append(cmd);
+ curIdx = list.count();
}
void UndoBuffer::recordAfter(dive *affectedDive)
{
-
+ list.at(curIdx - 1)->setStateAfter(affectedDive);
}
@@ -50,10 +65,14 @@ UndoCommand::UndoCommand(QString commandName, dive *affectedDive)
void UndoCommand::undo()
{
-
+ if (name == "Delete Dive") {
+ record_dive(stateBefore);
+ MainWindow::instance()->recreateDiveList();
+ }
}
void UndoCommand::redo()
{
-
+ //To be implemented
}
+