summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/simplewidgets.cpp13
-rw-r--r--qt-ui/undocommands.cpp31
-rw-r--r--qt-ui/undocommands.h12
3 files changed, 54 insertions, 2 deletions
diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp
index f7944c90c..003fc053d 100644
--- a/qt-ui/simplewidgets.cpp
+++ b/qt-ui/simplewidgets.cpp
@@ -142,8 +142,17 @@ void RenumberDialog::renumberOnlySelected(bool selected)
void RenumberDialog::buttonClicked(QAbstractButton *button)
{
- if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)
- renumber_dives(ui.spinBox->value(), selectedOnly);
+ if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
+ QMap<int,int> renumberedDives;
+ int i;
+ struct dive *dive = NULL;
+ for_each_dive (i, dive) {
+ if (!selectedOnly || dive->selected)
+ renumberedDives.insert(dive->id, dive->number);
+ }
+ UndoRenumberDives *undoCommand = new UndoRenumberDives(renumberedDives, ui.spinBox->value());
+ MainWindow::instance()->undoStack->push(undoCommand);
+ }
}
RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent), selectedOnly(false)
diff --git a/qt-ui/undocommands.cpp b/qt-ui/undocommands.cpp
index 316def495..6a15f7e03 100644
--- a/qt-ui/undocommands.cpp
+++ b/qt-ui/undocommands.cpp
@@ -62,3 +62,34 @@ void UndoShiftTime::redo()
mark_divelist_changed(true);
MainWindow::instance()->refreshDisplay();
}
+
+
+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();
+}
diff --git a/qt-ui/undocommands.h b/qt-ui/undocommands.h
index addef8138..36c789fee 100644
--- a/qt-ui/undocommands.h
+++ b/qt-ui/undocommands.h
@@ -2,6 +2,7 @@
#define UNDOCOMMANDS_H
#include <QUndoCommand>
+#include <QMap>
#include "dive.h"
class UndoDeleteDive : public QUndoCommand {
@@ -25,4 +26,15 @@ private:
int timeChanged;
};
+class UndoRenumberDives : public QUndoCommand {
+public:
+ UndoRenumberDives(QMap<int,int> originalNumbers, int startNumber);
+ virtual void undo();
+ virtual void redo();
+
+private:
+ QMap<int,int> oldNumbers;
+ int start;
+};
+
#endif // UNDOCOMMANDS_H