mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-29 13:40:20 +00:00
87ee8e8aef
Adds the ability to undo shifting of dive times. The change is captured at simplewidgets.cpp and an undo command is created. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
64 lines
1.4 KiB
C++
64 lines
1.4 KiB
C++
#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;
|
|
}
|
|
|
|
|
|
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();
|
|
}
|