mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
6d996a7874
commit
60a7404ed4
2 changed files with 30 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue