summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/simplewidgets.cpp8
-rw-r--r--qt-ui/undocommands.cpp11
-rw-r--r--qt-ui/undocommands.h5
3 files changed, 12 insertions, 12 deletions
diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp
index 430609c7b..d060e3892 100644
--- a/qt-ui/simplewidgets.cpp
+++ b/qt-ui/simplewidgets.cpp
@@ -143,14 +143,16 @@ void RenumberDialog::renumberOnlySelected(bool selected)
void RenumberDialog::buttonClicked(QAbstractButton *button)
{
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
- QMap<int,int> renumberedDives;
+ // we remember a map from dive uuid to a pair of old number / new number
+ QMap<int,QPair<int, int> > renumberedDives;
int i;
+ int newNr = ui.spinBox->value();
struct dive *dive = NULL;
for_each_dive (i, dive) {
if (!selectedOnly || dive->selected)
- renumberedDives.insert(dive->id, dive->number);
+ renumberedDives.insert(dive->id, QPair<int,int>(dive->number, newNr++));
}
- UndoRenumberDives *undoCommand = new UndoRenumberDives(renumberedDives, ui.spinBox->value());
+ UndoRenumberDives *undoCommand = new UndoRenumberDives(renumberedDives);
MainWindow::instance()->undoStack->push(undoCommand);
}
}
diff --git a/qt-ui/undocommands.cpp b/qt-ui/undocommands.cpp
index aad264e24..d7bae75a9 100644
--- a/qt-ui/undocommands.cpp
+++ b/qt-ui/undocommands.cpp
@@ -63,20 +63,20 @@ void UndoShiftTime::redo()
}
-UndoRenumberDives::UndoRenumberDives(QMap<int, int> originalNumbers, int startNumber)
+UndoRenumberDives::UndoRenumberDives(QMap<int, QPair<int, int> > originalNumbers)
{
oldNumbers = originalNumbers;
- start = startNumber;
- setText("renumber dive");
if (oldNumbers.count() > 1)
setText(QString("renumber %1 dives").arg(QString::number(oldNumbers.count())));
+ else
+ setText("renumber dive");
}
void UndoRenumberDives::undo()
{
foreach (int key, oldNumbers.keys()) {
struct dive* d = get_dive_by_uniq_id(key);
- d->number = oldNumbers.value(key);
+ d->number = oldNumbers.value(key).first;
}
mark_divelist_changed(true);
MainWindow::instance()->refreshDisplay();
@@ -84,10 +84,9 @@ void UndoRenumberDives::undo()
void UndoRenumberDives::redo()
{
- int i = start;
foreach (int key, oldNumbers.keys()) {
struct dive* d = get_dive_by_uniq_id(key);
- d->number = i++;
+ d->number = oldNumbers.value(key).second;
}
mark_divelist_changed(true);
MainWindow::instance()->refreshDisplay();
diff --git a/qt-ui/undocommands.h b/qt-ui/undocommands.h
index bd8530d77..62fb2d22b 100644
--- a/qt-ui/undocommands.h
+++ b/qt-ui/undocommands.h
@@ -28,13 +28,12 @@ private:
class UndoRenumberDives : public QUndoCommand {
public:
- UndoRenumberDives(QMap<int,int> originalNumbers, int startNumber);
+ UndoRenumberDives(QMap<int, QPair<int, int> > originalNumbers);
virtual void undo();
virtual void redo();
private:
- QMap<int,int> oldNumbers;
- int start;
+ QMap<int,QPair<int, int> > oldNumbers;
};
class UndoRemoveDivesFromTrip : public QUndoCommand {