diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp index 270679b74..3e9065692 100644 --- a/commands/command_divelist.cpp +++ b/commands/command_divelist.cpp @@ -16,7 +16,7 @@ static std::unique_ptr remove_trip_from_backend(dive_trip *trip) { if (trip->selected) deselect_trip(trip); - auto [t, idx] = divelog.trips->pull(trip); + auto [t, idx] = divelog.trips.pull(trip); return std::move(t); } @@ -39,7 +39,7 @@ DiveToAdd DiveListBase::removeDive(struct dive *d, std::vectordive_site); res.site = unregister_dive_from_dive_site(d); if (res.trip && res.trip->dives.empty()) { - divelog.trips->sort(); // Removal of dives has changed order of trips! (TODO: remove this) + divelog.trips.sort(); // Removal of dives has changed order of trips! (TODO: remove this) auto trip = remove_trip_from_backend(res.trip); // Remove trip from backend tripsToAdd.push_back(std::move(trip)); // Take ownership of trip } @@ -200,7 +200,7 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd) std::vector addedTrips; addedTrips.reserve(toAdd.trips.size()); for (std::unique_ptr &trip: toAdd.trips) { - auto [t, idx] = divelog.trips->put(std::move(trip)); // Return ownership to backend + auto [t, idx] = divelog.trips.put(std::move(trip)); // Return ownership to backend addedTrips.push_back(t); } toAdd.trips.clear(); @@ -287,7 +287,7 @@ static void moveDivesBetweenTrips(DivesToTrip &dives) // First, bring back the trip(s) for (std::unique_ptr &trip: dives.tripsToAdd) { - auto [t, idx] = divelog.trips->put(std::move(trip)); // Return ownership to backend + auto [t, idx] = divelog.trips.put(std::move(trip)); // Return ownership to backend createdTrips.push_back(t); } dives.tripsToAdd.clear(); @@ -438,7 +438,7 @@ void AddDive::redoit() currentDive = current_dive; divesAndSitesToRemove = addDives(divesToAdd); - divelog.trips->sort(); // Though unlikely, adding a dive may reorder trips + divelog.trips.sort(); // Though unlikely, adding a dive may reorder trips // Select the newly added dive setSelection(divesAndSitesToRemove.dives, divesAndSitesToRemove.dives[0], -1); @@ -448,7 +448,7 @@ void AddDive::undoit() { // Simply remove the dive that was previously added... divesToAdd = removeDives(divesAndSitesToRemove); - divelog.trips->sort(); // Though unlikely, removing a dive may reorder trips + divelog.trips.sort(); // Though unlikely, removing a dive may reorder trips // ...and restore the selection setSelection(selection, currentDive, -1); @@ -583,7 +583,7 @@ bool DeleteDive::workToBeDone() void DeleteDive::undoit() { divesToDelete = addDives(divesToAdd); - divelog.trips->sort(); // Though unlikely, removing a dive may reorder trips + divelog.trips.sort(); // Though unlikely, removing a dive may reorder trips // Select all re-added dives and make the first one current dive *currentDive = !divesToDelete.dives.empty() ? divesToDelete.dives[0] : nullptr; @@ -593,7 +593,7 @@ void DeleteDive::undoit() void DeleteDive::redoit() { divesToAdd = removeDives(divesToDelete); - divelog.trips->sort(); // Though unlikely, adding a dive may reorder trips + divelog.trips.sort(); // Though unlikely, adding a dive may reorder trips // Deselect all dives and select dive that was close to the first deleted dive dive *newCurrent = nullptr; @@ -622,7 +622,7 @@ void ShiftTime::redoit() // Changing times may have unsorted the dive and trip tables divelog.dives.sort(); - divelog.trips->sort(); + divelog.trips.sort(); for (dive_trip *trip: trips) trip->sort_dives(); @@ -690,7 +690,7 @@ bool TripBase::workToBeDone() void TripBase::redoit() { moveDivesBetweenTrips(divesToMove); - divelog.trips->sort(); // Though unlikely, moving dives may reorder trips + divelog.trips.sort(); // Though unlikely, moving dives may reorder trips // Select the moved dives std::vector dives; diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index dfaa0b63a..fd97dc0ec 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -1442,7 +1442,7 @@ void EditDive::exchangeDives() timestamp_t delta = oldDive->when - newDive->when; if (delta != 0) { divelog.dives.sort(); - divelog.trips->sort(); + divelog.trips.sort(); if (newDive->divetrip != oldDive->divetrip) qWarning("Command::EditDive::redo(): This command does not support moving between trips!"); if (oldDive->divetrip) diff --git a/core/divelist.cpp b/core/divelist.cpp index 71ea5dbc7..e2f89f1ce 100644 --- a/core/divelist.cpp +++ b/core/divelist.cpp @@ -727,10 +727,10 @@ struct dive *register_dive(std::unique_ptr d) void process_loaded_dives() { divelog.dives.sort(); - divelog.trips->sort(); + divelog.trips.sort(); /* Autogroup dives if desired by user. */ - autogroup_dives(divelog.dives, *divelog.trips); + autogroup_dives(divelog.dives, divelog.trips); fulltext_populate(); @@ -926,7 +926,7 @@ void add_imported_dives(struct divelog &import_log, int flags) /* Add new trips */ for (auto &trip: trips_to_add) - divelog.trips->put(std::move(trip)); + divelog.trips.put(std::move(trip)); trips_to_add.clear(); /* Add new dive sites */ @@ -960,7 +960,7 @@ static bool try_to_merge_trip(dive_trip &trip_import, struct dive_table &import_ struct dive_table &dives_to_add, std::vector &dives_to_remove, bool &sequence_changed, int &start_renumbering_at) { - for (auto &trip_old: *divelog.trips) { + for (auto &trip_old: divelog.trips) { if (trips_overlap(trip_import, *trip_old)) { sequence_changed |= merge_dive_tables(trip_import.dives, import_table, trip_old->dives, prefer_imported, trip_old.get(), @@ -1044,7 +1044,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, /* Autogroup tripless dives if desired by user. But don't autogroup * if tripless dives should be added to a new trip. */ if (!(flags & IMPORT_ADD_TO_NEW_TRIP)) - autogroup_dives(import_log.dives, *import_log.trips); + autogroup_dives(import_log.dives, import_log.trips); /* If dive sites already exist, use the existing versions. */ for (auto &new_ds: import_log.sites) { @@ -1072,7 +1072,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, * could be smarter here, but realistically not a whole lot of trips * will be imported so do a simple n*m loop until someone complains. */ - for (auto &trip_import: *import_log.trips) { + for (auto &trip_import: import_log.trips) { if ((flags & IMPORT_MERGE_ALL_TRIPS) || trip_import->autogen) { if (try_to_merge_trip(*trip_import, import_log.dives, flags & IMPORT_PREFER_IMPORTED, res.dives_to_add, res.dives_to_remove, @@ -1096,7 +1096,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, /* Finally, add trip to list of trips to add */ res.trips_to_add.put(std::move(trip_import)); } - import_log.trips->clear(); /* All trips were consumed */ + import_log.trips.clear(); /* All trips were consumed */ if ((flags & IMPORT_ADD_TO_NEW_TRIP) && !import_log.dives.empty()) { /* Create a new trip for unassigned dives, if desired. */ diff --git a/core/divelog.cpp b/core/divelog.cpp index f5a59e098..508da5310 100644 --- a/core/divelog.cpp +++ b/core/divelog.cpp @@ -11,7 +11,6 @@ struct divelog divelog; divelog::divelog() : - trips(std::make_unique()), filter_presets(std::make_unique()), autogroup(false) { @@ -34,10 +33,10 @@ void divelog::delete_single_dive(int idx) // Deleting a dive may change the order of trips! if (trip) - trips->sort(); + trips.sort(); if (trip && trip->dives.empty()) - trips->pull(trip); + trips.pull(trip); unregister_dive_from_dive_site(dive); dives.erase(dives.begin() + idx); } @@ -51,7 +50,7 @@ void divelog::delete_multiple_dives(const std::vector &dives_to_delete) struct dive_trip *trip = unregister_dive_from_trip(d); if (trip && trip->dives.empty()) { trips_changed = true; - trips->pull(trip); + trips.pull(trip); } unregister_dive_from_dive_site(d); @@ -60,14 +59,14 @@ void divelog::delete_multiple_dives(const std::vector &dives_to_delete) // Deleting a dive may change the order of trips! if (trips_changed) - trips->sort(); + trips.sort(); } void divelog::clear() { dives.clear(); sites.clear(); - trips->clear(); + trips.clear(); devices.clear(); filter_presets->clear(); } diff --git a/core/divelog.h b/core/divelog.h index 0cecddd54..6a1de2677 100644 --- a/core/divelog.h +++ b/core/divelog.h @@ -5,6 +5,7 @@ #include "divelist.h" #include "divesitetable.h" +#include "triptable.h" #include #include @@ -15,7 +16,7 @@ struct filter_preset_table; struct divelog { dive_table dives; - std::unique_ptr trips; + trip_table trips; dive_site_table sites; std::vector devices; std::unique_ptr filter_presets; diff --git a/core/load-git.cpp b/core/load-git.cpp index 48ef3f0d6..ec85aedd7 100644 --- a/core/load-git.cpp +++ b/core/load-git.cpp @@ -1384,7 +1384,7 @@ static void finish_active_trip(struct git_parser_state *state) auto &trip = state->active_trip; if (trip) - state->log->trips->put(std::move(trip)); + state->log->trips.put(std::move(trip)); } static void finish_active_dive(struct git_parser_state *state) diff --git a/core/parse.cpp b/core/parse.cpp index e427136a8..96352b709 100644 --- a/core/parse.cpp +++ b/core/parse.cpp @@ -288,7 +288,7 @@ void trip_end(struct parser_state *state) { if (!state->cur_trip) return; - state->log->trips->put(std::move(state->cur_trip)); + state->log->trips.put(std::move(state->cur_trip)); } void picture_start(struct parser_state *state) diff --git a/core/save-git.cpp b/core/save-git.cpp index 80aa14c13..49c4e65d6 100644 --- a/core/save-git.cpp +++ b/core/save-git.cpp @@ -985,7 +985,7 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o save_divesites(repo, root); save_filter_presets(repo, root); - for (auto &trip: *divelog.trips) + for (auto &trip: divelog.trips) trip->saved = false; /* save the dives */ diff --git a/core/save-html.cpp b/core/save-html.cpp index c263cf572..1af755ce5 100644 --- a/core/save-html.cpp +++ b/core/save-html.cpp @@ -436,7 +436,7 @@ static void write_trips(struct membuffer *b, const char *photos_dir, bool select char sep_ = ' '; char *sep = &sep_; - for (auto &trip: *divelog.trips) + for (auto &trip: divelog.trips) trip->saved = 0; for (auto &dive: divelog.dives) { diff --git a/core/save-xml.cpp b/core/save-xml.cpp index e9a1e449e..cefa53f5a 100644 --- a/core/save-xml.cpp +++ b/core/save-xml.cpp @@ -678,7 +678,7 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym put_format(b, "\n"); } put_format(b, "\n\n"); - for (auto &trip: *divelog.trips) + for (auto &trip: divelog.trips) trip->saved = 0; /* save the filter presets */ diff --git a/core/selection.cpp b/core/selection.cpp index 1b7707292..a3e4d8562 100644 --- a/core/selection.cpp +++ b/core/selection.cpp @@ -156,7 +156,7 @@ QVector setSelectionCore(const std::vector &selection, dive *cur static void clear_trip_selection() { amount_trips_selected = 0; - for (auto &trip: *divelog.trips) + for (auto &trip: divelog.trips) trip->selected = false; } @@ -202,7 +202,7 @@ void setTripSelection(dive_trip *trip, dive *currentDive) current_dive = currentDive; for (auto &d: divelog.dives) d->selected = d->divetrip == trip; - for (auto &t: *divelog.trips) + for (auto &t: divelog.trips) t->selected = t.get() == trip; amount_selected = static_cast(trip->dives.size()); @@ -291,7 +291,7 @@ struct dive_trip *single_selected_trip() { if (amount_trips_selected != 1) return NULL; - for (auto &trip: *divelog.trips) { + for (auto &trip: divelog.trips) { if (trip->selected) return trip.get(); } diff --git a/desktop-widgets/tripselectiondialog.cpp b/desktop-widgets/tripselectiondialog.cpp index ad6928152..ab98fe366 100644 --- a/desktop-widgets/tripselectiondialog.cpp +++ b/desktop-widgets/tripselectiondialog.cpp @@ -18,8 +18,8 @@ TripSelectionDialog::TripSelectionDialog(QWidget *parent) : QDialog(parent) // We could use a model, but it seems barely worth the hassle. QStringList list; - list.reserve(divelog.trips->size()); - for (auto &trip: *divelog.trips) + list.reserve(divelog.trips.size()); + for (auto &trip: divelog.trips) list.push_back(formatTripTitleWithDives(*trip)); ui.trips->addItems(list); } @@ -37,9 +37,9 @@ dive_trip *TripSelectionDialog::selectedTrip() const if (rows.size() != 1) return nullptr; int idx = rows[0].row(); - if (idx < 0 || static_cast(idx) >= divelog.trips->size()) + if (idx < 0 || static_cast(idx) >= divelog.trips.size()) return nullptr; - return (*divelog.trips)[idx].get(); + return divelog.trips[idx].get(); } dive_trip *TripSelectionDialog::getTrip() diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 687173865..a22b2c611 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -1369,7 +1369,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt void QMLManager::updateTripDetails(QString tripIdString, QString tripLocation, QString tripNotes) { int tripId = tripIdString.toInt(); - dive_trip *trip = divelog.trips->get_by_uniq_id(tripId); + dive_trip *trip = divelog.trips.get_by_uniq_id(tripId); if (!trip) { report_info("updateTripData: cannot find trip for tripId %s", qPrintable(tripIdString)); return; @@ -1428,7 +1428,7 @@ void QMLManager::addDiveToTrip(int id, int tripId) appendTextToLog(QString("Asked to add non-existing dive with id %1 to trip %2.").arg(id).arg(tripId)); return; } - struct dive_trip *dt = divelog.trips->get_by_uniq_id(tripId); + struct dive_trip *dt = divelog.trips.get_by_uniq_id(tripId); if (!dt) { appendTextToLog(QString("Asked to add dive with id %1 to trip with id %2 which cannot be found.").arg(id).arg(tripId)); return;