diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-07-30 15:55:29 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:22:27 -0700 |
commit | 96d87273995a6af35d90efb1190ff653e4c03d02 (patch) | |
tree | f115a9ccd821cab753f2863fa86f9f08cd20bbd4 | |
parent | 26901a8dbd91a18689199361541f9d1f90d56e4e (diff) | |
download | subsurface-96d87273995a6af35d90efb1190ff653e4c03d02.tar.gz |
Undo: use dive * instead of unique index in renumber-dives
Now, that pointers to dives are stable, we might just as well
use dive * instead of the unique-id. This also affects the
merge-dive command, as this uses the same renumbering machinery.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | desktop-widgets/command.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/command.h | 2 | ||||
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 10 | ||||
-rw-r--r-- | desktop-widgets/command_divelist.h | 6 | ||||
-rw-r--r-- | desktop-widgets/simplewidgets.cpp | 12 |
5 files changed, 16 insertions, 16 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp index fe16f1898..54ca2d39f 100644 --- a/desktop-widgets/command.cpp +++ b/desktop-widgets/command.cpp @@ -21,7 +21,7 @@ void shiftTime(const QVector<dive *> &changedDives, int amount) execute(new ShiftTime(changedDives, amount)); } -void renumberDives(const QVector<QPair<int, int>> &divesToRenumber) +void renumberDives(const QVector<QPair<dive *, int>> &divesToRenumber) { execute(new RenumberDives(divesToRenumber)); } diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h index 924365806..9a8ccfd6d 100644 --- a/desktop-widgets/command.h +++ b/desktop-widgets/command.h @@ -18,7 +18,7 @@ QAction *redoAction(QObject *parent); // Create an redo action. void addDive(dive *d, bool autogroup); void deleteDive(const QVector<struct dive*> &divesToDelete); void shiftTime(const QVector<dive *> &changedDives, int amount); -void renumberDives(const QVector<QPair<int, int>> &divesToRenumber); +void renumberDives(const QVector<QPair<dive *, int>> &divesToRenumber); void removeDivesFromTrip(const QVector<dive *> &divesToRemove); void removeAutogenTrips(); void addDivesToTrip(const QVector<dive *> &divesToAddIn, dive_trip *trip); diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index 732932de3..17d5f00e4 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -151,10 +151,10 @@ static std::vector<dive *> addDives(std::vector<DiveToAdd> &divesToAdd) // This helper function renumbers dives according to an array of id/number pairs. // The old numbers are stored in the array, thus calling this function twice has no effect. // TODO: switch from uniq-id to indexes once all divelist-actions are controlled by undo-able commands -static void renumberDives(QVector<QPair<int, int>> &divesToRenumber) +static void renumberDives(QVector<QPair<dive *, int>> &divesToRenumber) { for (auto &pair: divesToRenumber) { - dive *d = get_dive_by_uniq_id(pair.first); + dive *d = pair.first; if (!d) continue; std::swap(d->number, pair.second); @@ -165,7 +165,7 @@ static void renumberDives(QVector<QPair<int, int>> &divesToRenumber) std::vector<std::pair<dive_trip *, dive *>> dives; dives.reserve(divesToRenumber.size()); for (const auto &pair: divesToRenumber) { - dive *d = get_dive_by_uniq_id(pair.first); + dive *d = pair.first; dives.push_back({ d->divetrip, d }); } @@ -413,7 +413,7 @@ void ShiftTime::undo() } -RenumberDives::RenumberDives(const QVector<QPair<int, int>> &divesToRenumberIn) : divesToRenumber(divesToRenumberIn) +RenumberDives::RenumberDives(const QVector<QPair<dive *, int>> &divesToRenumberIn) : divesToRenumber(divesToRenumberIn) { setText(tr("renumber %n dive(s)", "", divesToRenumber.count())); } @@ -641,7 +641,7 @@ MergeDives::MergeDives(const QVector <dive *> &dives) // Stop renumbering if stuff isn't in order (see also core/divelist.c) if (newnr <= previousnr) break; - divesToRenumber.append(QPair<int,int>(dive_table.dives[i]->id, newnr)); + divesToRenumber.append(QPair<dive *,int>(dive_table.dives[i], newnr)); previousnr = newnr; } } diff --git a/desktop-widgets/command_divelist.h b/desktop-widgets/command_divelist.h index 69824ce9f..e679369af 100644 --- a/desktop-widgets/command_divelist.h +++ b/desktop-widgets/command_divelist.h @@ -85,14 +85,14 @@ private: class RenumberDives : public Base { public: - RenumberDives(const QVector<QPair<int, int>> &divesToRenumber); + RenumberDives(const QVector<QPair<dive *, int>> &divesToRenumber); private: void undo() override; void redo() override; bool workToBeDone() override; // For redo and undo: pairs of dive-id / new number - QVector<QPair<int, int>> divesToRenumber; + QVector<QPair<dive *, int>> divesToRenumber; }; // The classes RemoveDivesFromTrip, RemoveAutogenTrips, CreateTrip, AutogroupDives @@ -166,7 +166,7 @@ private: std::vector<DiveToAdd> unmergedDives; // For undo and redo - QVector<QPair<int, int>> divesToRenumber; + QVector<QPair<dive *, int>> divesToRenumber; }; } // namespace Command diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index 1df69e7bb..6d15da475 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -161,14 +161,14 @@ void RenumberDialog::buttonClicked(QAbstractButton *button) if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { MainWindow::instance()->dive_list()->rememberSelection(); // we remember a list from dive uuid to a new number - QVector<QPair<int, int>> renumberedDives; + QVector<QPair<dive *, int>> renumberedDives; int i; int newNr = ui.spinBox->value(); - struct dive *dive = NULL; - for_each_dive (i, dive) { - if (!selectedOnly || dive->selected) { - invalidate_dive_cache(dive); - renumberedDives.append(QPair<int, int>(dive->id, newNr++)); + struct dive *d; + for_each_dive (i, d) { + if (!selectedOnly || d->selected) { + invalidate_dive_cache(d); + renumberedDives.append({ d, newNr++ }); } } Command::renumberDives(renumberedDives); |