On Mon, Mar 9, 2015 at 2:51 PM, Grace Karanja <[email protected]> wrote: > > > See the attached patch, which implements undo/redo of when merging dives. >
The next attached patch implements undo/redo when downloading from dive computers. > > >> >> /D >> > >
From 3217288dfdd60b84fd6cc182b85b7e5cd213b80e Mon Sep 17 00:00:00 2001 From: Grace Karanja <[email protected]> Date: Tue, 10 Mar 2015 23:04:46 +0300 Subject: [PATCH 2/2] Add ability to undo download from dive computer Capture dives downloaded from dive computer, and add the ability to undo/redo the download. Signed-off-by: Grace Karanja <[email protected]> --- qt-ui/downloadfromdivecomputer.cpp | 6 +++++- qt-ui/undocommands.cpp | 35 +++++++++++++++++++++++++++++++++++ qt-ui/undocommands.h | 10 ++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp index c57aa1e..994f67d 100644 --- a/qt-ui/downloadfromdivecomputer.cpp +++ b/qt-ui/downloadfromdivecomputer.cpp @@ -3,6 +3,7 @@ #include "mainwindow.h" #include "divelistview.h" #include "display.h" +#include "undocommands.h" #include <QTimer> #include <QFileDialog> @@ -426,11 +427,14 @@ void DownloadFromDCWidget::on_ok_clicked() return; // record all the dives in the 'real' dive_table + QList<struct dive*> diveList; for (int i = 0; i < downloadTable.nr; i++) { if (diveImportedModel->data(diveImportedModel->index(i, 0),Qt::CheckStateRole) == Qt::Checked) - record_dive(downloadTable.dives[i]); + diveList.append(downloadTable.dives[i]); downloadTable.dives[i] = NULL; } + UndoDownloadDives *undoCommand = new UndoDownloadDives(diveList); + MainWindow::instance()->undoStack->push(undoCommand); downloadTable.nr = 0; int uniqId, idx; diff --git a/qt-ui/undocommands.cpp b/qt-ui/undocommands.cpp index 012faaf..758b5eb 100644 --- a/qt-ui/undocommands.cpp +++ b/qt-ui/undocommands.cpp @@ -154,3 +154,38 @@ void UndoMergeDives::redo() mark_divelist_changed(true); MainWindow::instance()->refreshDisplay(); } + + +UndoDownloadDives::UndoDownloadDives(QList<dive *> downloadedDives) +{ + dives = downloadedDives; + setText("download dives"); +} + +void UndoDownloadDives::undo() +{ + 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; +} + +void UndoDownloadDives::redo() +{ + for (int i = 0; i < dives.count(); i++) { + struct dive* d = alloc_dive(); + copy_dive(dives.at(i), d); + record_dive(d); + } + mark_divelist_changed(true); + MainWindow::instance()->refreshDisplay(); +} diff --git a/qt-ui/undocommands.h b/qt-ui/undocommands.h index a3ff9c2..63293b2 100644 --- a/qt-ui/undocommands.h +++ b/qt-ui/undocommands.h @@ -47,4 +47,14 @@ private: struct dive* mainDive; }; +class UndoDownloadDives : public QUndoCommand { +public: + UndoDownloadDives(QList<struct dive*> downloadedDives); + virtual void undo(); + virtual void redo(); + +private: + QList<struct dive*> dives; +}; + #endif // UNDOCOMMANDS_H -- 2.1.0
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
