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 /desktop-widgets/command_divelist.cpp | |
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>
Diffstat (limited to 'desktop-widgets/command_divelist.cpp')
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
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; } } |