2015-02-11 06:28:43 +00:00
|
|
|
#include "undocommands.h"
|
2015-02-11 07:57:56 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "divelist.h"
|
2015-02-11 06:28:43 +00:00
|
|
|
|
2015-03-17 04:48:45 +00:00
|
|
|
UndoDeleteDive::UndoDeleteDive(QList<dive *> deletedDives)
|
|
|
|
: diveList(deletedDives)
|
2015-02-11 06:28:43 +00:00
|
|
|
{
|
2015-02-11 07:57:56 +00:00
|
|
|
setText("delete dive");
|
2015-03-17 04:48:45 +00:00
|
|
|
if (diveList.count() > 1)
|
|
|
|
setText(QString("delete %1 dives").arg(QString::number(diveList.count())));
|
2015-02-11 06:28:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UndoDeleteDive::undo()
|
|
|
|
{
|
2015-03-17 04:48:45 +00:00
|
|
|
for (int i = 0; i < diveList.count(); i++)
|
|
|
|
record_dive(diveList.at(i));
|
2015-02-11 07:57:56 +00:00
|
|
|
mark_divelist_changed(true);
|
|
|
|
MainWindow::instance()->refreshDisplay();
|
2015-02-11 06:28:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UndoDeleteDive::redo()
|
|
|
|
{
|
2015-02-11 07:57:56 +00:00
|
|
|
QList<struct dive*> newList;
|
2015-03-17 04:48:45 +00:00
|
|
|
for (int i = 0; i < diveList.count(); i++) {
|
2015-02-11 07:57:56 +00:00
|
|
|
//make a copy of the dive before deleting it
|
|
|
|
struct dive* d = alloc_dive();
|
2015-03-17 04:48:45 +00:00
|
|
|
copy_dive(diveList.at(i), d);
|
2015-02-11 07:57:56 +00:00
|
|
|
newList.append(d);
|
|
|
|
//delete the dive
|
2015-03-17 04:48:45 +00:00
|
|
|
delete_single_dive(get_divenr(diveList.at(i)));
|
2015-02-11 07:57:56 +00:00
|
|
|
}
|
|
|
|
mark_divelist_changed(true);
|
|
|
|
MainWindow::instance()->refreshDisplay();
|
2015-03-17 04:48:45 +00:00
|
|
|
diveList.clear();
|
|
|
|
diveList = newList;
|
2015-02-11 06:28:43 +00:00
|
|
|
}
|
2015-02-14 17:12:05 +00:00
|
|
|
|
|
|
|
|
2015-03-17 04:48:45 +00:00
|
|
|
UndoShiftTime::UndoShiftTime(QList<int> changedDives, int amount)
|
|
|
|
: diveList(changedDives), timeChanged(amount)
|
2015-02-14 17:12:05 +00:00
|
|
|
{
|
|
|
|
setText("shift time");
|
|
|
|
}
|
|
|
|
|
|
|
|
void UndoShiftTime::undo()
|
|
|
|
{
|
2015-03-17 04:48:45 +00:00
|
|
|
for (int i = 0; i < diveList.count(); i++) {
|
|
|
|
struct dive* d = get_dive_by_uniq_id(diveList.at(i));
|
2015-02-14 17:12:05 +00:00
|
|
|
d->when -= timeChanged;
|
|
|
|
}
|
|
|
|
mark_divelist_changed(true);
|
|
|
|
MainWindow::instance()->refreshDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UndoShiftTime::redo()
|
|
|
|
{
|
2015-03-17 04:48:45 +00:00
|
|
|
for (int i = 0; i < diveList.count(); i++) {
|
|
|
|
struct dive* d = get_dive_by_uniq_id(diveList.at(i));
|
2015-02-14 17:12:05 +00:00
|
|
|
d->when += timeChanged;
|
|
|
|
}
|
|
|
|
mark_divelist_changed(true);
|
|
|
|
MainWindow::instance()->refreshDisplay();
|
|
|
|
}
|
2015-02-28 04:42:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
UndoRenumberDives::UndoRenumberDives(QMap<int, int> originalNumbers, int startNumber)
|
|
|
|
{
|
|
|
|
oldNumbers = originalNumbers;
|
|
|
|
start = startNumber;
|
|
|
|
setText("renumber dive");
|
|
|
|
if (oldNumbers.count() > 1)
|
|
|
|
setText(QString("renumber %1 dives").arg(QString::number(oldNumbers.count())));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UndoRenumberDives::undo()
|
|
|
|
{
|
|
|
|
foreach (int key, oldNumbers.keys()) {
|
|
|
|
struct dive* d = get_dive_by_uniq_id(key);
|
|
|
|
d->number = oldNumbers.value(key);
|
|
|
|
}
|
|
|
|
mark_divelist_changed(true);
|
|
|
|
MainWindow::instance()->refreshDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UndoRenumberDives::redo()
|
|
|
|
{
|
|
|
|
int i = start;
|
|
|
|
foreach (int key, oldNumbers.keys()) {
|
|
|
|
struct dive* d = get_dive_by_uniq_id(key);
|
|
|
|
d->number = i++;
|
|
|
|
}
|
|
|
|
mark_divelist_changed(true);
|
|
|
|
MainWindow::instance()->refreshDisplay();
|
|
|
|
}
|
2015-04-10 06:39:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
UndoRemoveDivesFromTrip::UndoRemoveDivesFromTrip(QMap<dive *, dive_trip *> removedDives)
|
|
|
|
{
|
|
|
|
divesToUndo = removedDives;
|
|
|
|
setText("remove dive(s) from trip");
|
|
|
|
}
|
|
|
|
|
|
|
|
void UndoRemoveDivesFromTrip::undo()
|
|
|
|
{
|
|
|
|
QMapIterator<dive*, dive_trip*> i(divesToUndo);
|
|
|
|
while (i.hasNext()) {
|
|
|
|
i.next();
|
|
|
|
add_dive_to_trip(i.key (), i.value());
|
|
|
|
}
|
|
|
|
mark_divelist_changed(true);
|
|
|
|
MainWindow::instance()->refreshDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UndoRemoveDivesFromTrip::redo()
|
|
|
|
{
|
|
|
|
QMapIterator<dive*, dive_trip*> i(divesToUndo);
|
|
|
|
while (i.hasNext()) {
|
|
|
|
i.next();
|
|
|
|
remove_dive_from_trip(i.key(), false);
|
|
|
|
}
|
|
|
|
mark_divelist_changed(true);
|
|
|
|
MainWindow::instance()->refreshDisplay();
|
|
|
|
}
|