diff --git a/backend-shared/exportfuncs.cpp b/backend-shared/exportfuncs.cpp index d0f0a2ec9..eabc4a91b 100644 --- a/backend-shared/exportfuncs.cpp +++ b/backend-shared/exportfuncs.cpp @@ -309,8 +309,8 @@ std::vector getDiveSitesToExport(bool selectedOnly) return res; } - res.reserve(divelog.sites->size()); - for (const auto &ds: *divelog.sites) { + res.reserve(divelog.sites.size()); + for (const auto &ds: divelog.sites) { if (ds->is_empty()) continue; if (selectedOnly && !ds->is_selected()) @@ -319,7 +319,7 @@ std::vector getDiveSitesToExport(bool selectedOnly) } #else /* walk the dive site list */ - for (const auto &ds: *divelog.sites) + for (const auto &ds: divelog.sites) res.push_back(ds.get()); #endif return res; diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp index 492a7b5a7..a2a9bacc5 100644 --- a/commands/command_divelist.cpp +++ b/commands/command_divelist.cpp @@ -132,7 +132,7 @@ DivesAndTripsToAdd DiveListBase::removeDives(DivesAndSitesToRemove &divesAndSite divesAndSitesToDelete.dives.clear(); for (dive_site *ds: divesAndSitesToDelete.sites) { - auto res = divelog.sites->pull(ds); + auto res = divelog.sites.pull(ds); sitesToAdd.push_back(std::move(res.ptr)); emit diveListNotifier.diveSiteDeleted(ds, res.idx); } @@ -207,7 +207,7 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd) // Finally, add any necessary dive sites for (std::unique_ptr &ds: toAdd.sites) { - auto res = divelog.sites->register_site(std::move(ds)); + auto res = divelog.sites.register_site(std::move(ds)); sites.push_back(res.ptr); emit diveListNotifier.diveSiteAdded(sites.back(), res.idx); } diff --git a/commands/command_divesite.cpp b/commands/command_divesite.cpp index fb5373229..fd706007c 100644 --- a/commands/command_divesite.cpp +++ b/commands/command_divesite.cpp @@ -30,7 +30,7 @@ static std::vector addDiveSites(std::vectorput(std::move(ds)); // Return ownership to backend. + auto add_res = divelog.sites.put(std::move(ds)); // Return ownership to backend. res.push_back(add_res.ptr); emit diveListNotifier.diveSiteAdded(res.back(), add_res.idx); // Inform frontend of new dive site. } @@ -60,7 +60,7 @@ static std::vector> removeDiveSites(std::vectorpull(ds); + auto pull_res = divelog.sites.pull(ds); res.push_back(std::move(pull_res.ptr)); emit diveListNotifier.diveSiteDeleted(ds, pull_res.idx); // Inform frontend of removed dive site. } @@ -101,7 +101,7 @@ ImportDiveSites::ImportDiveSites(dive_site_table sites, const QString &source) for (auto &new_ds: sites) { // Don't import dive sites that already exist. // We might want to be smarter here and merge dive site data, etc. - if (divelog.sites->get_same(*new_ds)) + if (divelog.sites.get_same(*new_ds)) continue; sitesToAdd.push_back(std::move(new_ds)); } @@ -145,7 +145,7 @@ void DeleteDiveSites::undo() PurgeUnusedDiveSites::PurgeUnusedDiveSites() { setText(Command::Base::tr("purge unused dive sites")); - for (const auto &ds: *divelog.sites) { + for (const auto &ds: divelog.sites) { if (ds->dives.empty()) sitesToRemove.push_back(ds.get()); } @@ -382,7 +382,7 @@ ApplyGPSFixes::ApplyGPSFixes(const std::vector &fixes) siteLocations.push_back({ ds, dl.location }); } } else { - ds = divelog.sites->create(dl.name.toStdString()); + ds = divelog.sites.create(dl.name.toStdString()); ds->location = dl.location; ds->add_dive(dl.d); dl.d->dive_site = nullptr; // This will be set on redo() diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index ac7bcea1c..dfaa0b63a 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -400,7 +400,7 @@ EditDiveSiteNew::EditDiveSiteNew(const QString &newName, bool currentDiveOnly) : void EditDiveSiteNew::undo() { EditDiveSite::undo(); - auto res = divelog.sites->pull(diveSiteToRemove); + auto res = divelog.sites.pull(diveSiteToRemove); diveSiteToAdd = std::move(res.ptr); emit diveListNotifier.diveSiteDeleted(diveSiteToRemove, res.idx); // Inform frontend of removed dive site. diveSiteToRemove = nullptr; @@ -408,7 +408,7 @@ void EditDiveSiteNew::undo() void EditDiveSiteNew::redo() { - auto res = divelog.sites->register_site(std::move(diveSiteToAdd)); // Return ownership to backend. + auto res = divelog.sites.register_site(std::move(diveSiteToAdd)); // Return ownership to backend. diveSiteToRemove = res.ptr; emit diveListNotifier.diveSiteAdded(diveSiteToRemove, res.idx); // Inform frontend of new dive site. EditDiveSite::redo(); @@ -1394,7 +1394,7 @@ EditDive::EditDive(dive *oldDiveIn, dive *newDiveIn, dive_site *createDs, dive_s void EditDive::undo() { if (siteToRemove) { - auto res = divelog.sites->pull(siteToRemove); + auto res = divelog.sites.pull(siteToRemove); siteToAdd = std::move(res.ptr); emit diveListNotifier.diveSiteDeleted(siteToRemove, res.idx); // Inform frontend of removed dive site. } @@ -1406,7 +1406,7 @@ void EditDive::undo() void EditDive::redo() { if (siteToAdd) { - auto res = divelog.sites->register_site(std::move(siteToAdd)); // Return ownership to backend. + auto res = divelog.sites.register_site(std::move(siteToAdd)); // Return ownership to backend. siteToRemove = res.ptr; emit diveListNotifier.diveSiteAdded(siteToRemove, res.idx); // Inform frontend of new dive site. } diff --git a/commands/command_pictures.cpp b/commands/command_pictures.cpp index 78067e6b7..09a6259ea 100644 --- a/commands/command_pictures.cpp +++ b/commands/command_pictures.cpp @@ -217,7 +217,7 @@ void AddPictures::undo() // Remove dive sites for (dive_site *siteToRemove: sitesToRemove) { - auto res = divelog.sites->pull(siteToRemove); + auto res = divelog.sites.pull(siteToRemove); sitesToAdd.push_back(std::move(res.ptr)); emit diveListNotifier.diveSiteDeleted(siteToRemove, res.idx); // Inform frontend of removed dive site. } @@ -228,7 +228,7 @@ void AddPictures::redo() { // Add dive sites for (std::unique_ptr &siteToAdd: sitesToAdd) { - auto res = divelog.sites->register_site(std::move(siteToAdd)); // Return ownership to backend. + auto res = divelog.sites.register_site(std::move(siteToAdd)); // Return ownership to backend. sitesToRemove.push_back(res.ptr); emit diveListNotifier.diveSiteAdded(sitesToRemove.back(), res.idx); // Inform frontend of new dive site. } diff --git a/core/datatrak.cpp b/core/datatrak.cpp index 3cdd36a4c..7a32d006f 100644 --- a/core/datatrak.cpp +++ b/core/datatrak.cpp @@ -212,9 +212,9 @@ static char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, struct */ { std::string buffer2 = std::string((char *)locality) + " " + (char *)dive_point; - struct dive_site *ds = log->sites->get_by_name(buffer2); + struct dive_site *ds = log->sites.get_by_name(buffer2); if (!ds) - ds = log->sites->create(buffer2); + ds = log->sites.create(buffer2); ds->add_dive(dt_dive); } free(locality); diff --git a/core/divelist.cpp b/core/divelist.cpp index 14e129c0b..4244f5a7c 100644 --- a/core/divelist.cpp +++ b/core/divelist.cpp @@ -931,7 +931,7 @@ void add_imported_dives(struct divelog &import_log, int flags) /* Add new dive sites */ for (auto &ds: dive_sites_to_add) - divelog.sites->register_site(std::move(ds)); + divelog.sites.register_site(std::move(ds)); /* Add new devices */ for (auto &dev: devices_to_add) @@ -1047,13 +1047,13 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, autogroup_dives(import_log.dives, *import_log.trips); /* If dive sites already exist, use the existing versions. */ - for (auto &new_ds: *import_log.sites) { + for (auto &new_ds: import_log.sites) { /* Check if it dive site is actually used by new dives. */ if (std::none_of(import_log.dives.begin(), import_log.dives.end(), [ds=new_ds.get()] (auto &d) { return d->dive_site == ds; })) continue; - struct dive_site *old_ds = divelog.sites->get_same(*new_ds); + struct dive_site *old_ds = divelog.sites.get_same(*new_ds); if (!old_ds) { /* Dive site doesn't exist. Add it to list of dive sites to be added. */ new_ds->dives.clear(); /* Caller is responsible for adding dives to site */ @@ -1066,7 +1066,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log, } } } - import_log.sites->clear(); + import_log.sites.clear(); /* Merge overlapping trips. Since both trip tables are sorted, we * could be smarter here, but realistically not a whole lot of trips diff --git a/core/divelog.cpp b/core/divelog.cpp index b19785dec..f5a59e098 100644 --- a/core/divelog.cpp +++ b/core/divelog.cpp @@ -12,7 +12,6 @@ struct divelog divelog; divelog::divelog() : trips(std::make_unique()), - sites(std::make_unique()), filter_presets(std::make_unique()), autogroup(false) { @@ -67,7 +66,7 @@ void divelog::delete_multiple_dives(const std::vector &dives_to_delete) void divelog::clear() { dives.clear(); - sites->clear(); + sites.clear(); trips->clear(); devices.clear(); filter_presets->clear(); diff --git a/core/divelog.h b/core/divelog.h index 18017d84e..0cecddd54 100644 --- a/core/divelog.h +++ b/core/divelog.h @@ -4,19 +4,19 @@ #define DIVELOG_H #include "divelist.h" +#include "divesitetable.h" #include #include struct trip_table; -class dive_site_table; struct device; struct filter_preset_table; struct divelog { dive_table dives; std::unique_ptr trips; - std::unique_ptr sites; + dive_site_table sites; std::vector devices; std::unique_ptr filter_presets; bool autogroup; diff --git a/core/import-cobalt.cpp b/core/import-cobalt.cpp index 4c599301c..cec124b2c 100644 --- a/core/import-cobalt.cpp +++ b/core/import-cobalt.cpp @@ -181,7 +181,7 @@ static int cobalt_dive(void *param, int, char **data, char **) if (location && location_site) { std::string tmp = std::string(location) + " / " + location_site; - state->log->sites->find_or_create(tmp)->add_dive(state->cur_dive.get()); + state->log->sites.find_or_create(tmp)->add_dive(state->cur_dive.get()); } free(location); free(location_site); diff --git a/core/import-divinglog.cpp b/core/import-divinglog.cpp index 578c13904..6e356972f 100644 --- a/core/import-divinglog.cpp +++ b/core/import-divinglog.cpp @@ -276,7 +276,7 @@ static int divinglog_dive(void *param, int, char **data, char **) state->cur_dive->when = (time_t)(atol(data[1])); if (data[2]) - state->log->sites->find_or_create(std::string(data[2]))->add_dive(state->cur_dive.get()); + state->log->sites.find_or_create(std::string(data[2]))->add_dive(state->cur_dive.get()); if (data[3]) utf8_string_std(data[3], &state->cur_dive->buddy); diff --git a/core/libdivecomputer.cpp b/core/libdivecomputer.cpp index 29cb4a1d1..5ab8c5920 100644 --- a/core/libdivecomputer.cpp +++ b/core/libdivecomputer.cpp @@ -617,7 +617,7 @@ static void parse_string_field(device_data_t *devdata, struct dive *dive, dc_fie if (location.lat.udeg && location.lon.udeg) { unregister_dive_from_dive_site(dive); - devdata->log->sites->create(std::string(str->value), location)->add_dive(dive); + devdata->log->sites.create(std::string(str->value), location)->add_dive(dive); } } } diff --git a/core/liquivision.cpp b/core/liquivision.cpp index 6403b46a8..a5a656a32 100644 --- a/core/liquivision.cpp +++ b/core/liquivision.cpp @@ -437,7 +437,7 @@ int try_to_open_liquivision(const char *, std::string &mem, struct divelog *log) } ptr += 4; - parse_dives(log_version, buf + ptr, buf_size - ptr, log->dives, *log->sites); + parse_dives(log_version, buf + ptr, buf_size - ptr, log->dives, log->sites); return 1; } diff --git a/core/load-git.cpp b/core/load-git.cpp index e8cbc6d3a..9e525cd19 100644 --- a/core/load-git.cpp +++ b/core/load-git.cpp @@ -175,9 +175,9 @@ static void parse_dive_gps(char *line, struct git_parser_state *state) parse_location(line, &location); if (!ds) { - ds = state->log->sites->get_by_gps(&location); + ds = state->log->sites.get_by_gps(&location); if (!ds) - ds = state->log->sites->create(std::string(), location); + ds = state->log->sites.create(std::string(), location); ds->add_dive(state->active_dive.get()); } else { if (dive_site_has_gps_location(ds) && ds->location != location) { @@ -221,9 +221,9 @@ static void parse_dive_location(char *, struct git_parser_state *state) std::string name = get_first_converted_string(state); struct dive_site *ds = get_dive_site_for_dive(state->active_dive.get()); if (!ds) { - ds = state->log->sites->get_by_name(name); + ds = state->log->sites.get_by_name(name); if (!ds) - ds = state->log->sites->create(name); + ds = state->log->sites.create(name); ds->add_dive(state->active_dive.get()); } else { // we already had a dive site linked to the dive @@ -252,7 +252,7 @@ static void parse_dive_notes(char *, struct git_parser_state *state) { state->active_dive->notes = get_first_converted_string(state); } static void parse_dive_divesiteid(char *line, struct git_parser_state *state) -{ state->log->sites->get_by_uuid(get_hex(line))->add_dive(state->active_dive.get()); } +{ state->log->sites.get_by_uuid(get_hex(line))->add_dive(state->active_dive.get()); } /* * We can have multiple tags. @@ -1694,7 +1694,7 @@ static int parse_site_entry(struct git_parser_state *state, const git_tree_entry if (*suffix == '\0') return report_error("Dive site without uuid"); uint32_t uuid = strtoul(suffix, NULL, 16); - state->active_site = state->log->sites->alloc_or_get(uuid); + state->active_site = state->log->sites.alloc_or_get(uuid); git_blob *blob = git_tree_entry_blob(state->repo, entry); if (!blob) return report_error("Unable to read dive site file"); diff --git a/core/parse-xml.cpp b/core/parse-xml.cpp index ab3e87357..995314a36 100644 --- a/core/parse-xml.cpp +++ b/core/parse-xml.cpp @@ -560,7 +560,7 @@ static void dive_site(const char *buffer, struct dive *d, struct parser_state *s { uint32_t uuid; hex_value(buffer, &uuid); - state->log->sites->get_by_uuid(uuid)->add_dive(d); + state->log->sites.get_by_uuid(uuid)->add_dive(d); } static void get_notrip(const char *buffer, bool *notrip) @@ -977,9 +977,9 @@ static void divinglog_place(const char *place, struct dive *d, struct parser_sta !state->city.empty() ? state->city.c_str() : "", !state->country.empty() ? ", " : "", !state->country.empty() ? state->country.c_str() : ""); - ds = state->log->sites->get_by_name(buffer); + ds = state->log->sites.get_by_name(buffer); if (!ds) - ds = state->log->sites->create(buffer); + ds = state->log->sites.create(buffer); ds->add_dive(d); // TODO: capture the country / city info in the taxonomy instead @@ -1147,7 +1147,7 @@ static void gps_lat(const char *buffer, struct dive *dive, struct parser_state * location.lat = parse_degrees(buffer, &end); if (!ds) { - state->log->sites->create(std::string(), location)->add_dive(dive); + state->log->sites.create(std::string(), location)->add_dive(dive); } else { if (ds->location.lat.udeg && ds->location.lat.udeg != location.lat.udeg) report_info("Oops, changing the latitude of existing dive site id %8x name %s; not good", ds->uuid, @@ -1164,7 +1164,7 @@ static void gps_long(const char *buffer, struct dive *dive, struct parser_state location.lon = parse_degrees(buffer, &end); if (!ds) { - state->log->sites->create(std::string(), location)->add_dive(dive); + state->log->sites.create(std::string(), location)->add_dive(dive); } else { if (ds->location.lon.udeg && ds->location.lon.udeg != location.lon.udeg) report_info("Oops, changing the longitude of existing dive site id %8x name %s; not good", ds->uuid, @@ -1195,14 +1195,14 @@ static void gps_in_dive(const char *buffer, struct dive *dive, struct parser_sta parse_location(buffer, &location); if (!ds) { // check if we have a dive site within 20 meters of that gps fix - ds = state->log->sites->get_by_gps_proximity(location, 20); + ds = state->log->sites.get_by_gps_proximity(location, 20); if (ds) { // found a site nearby; in case it turns out this one had a different name let's // remember the original coordinates so we can create the correct dive site later state->cur_location = location; } else { - ds = state->log->sites->create(std::string(), location); + ds = state->log->sites.create(std::string(), location); } ds->add_dive(dive); } else { @@ -2226,7 +2226,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log) /* Measure GPS */ state.cur_location.lat.udeg = (int)((ptr[7] << 24) + (ptr[6] << 16) + (ptr[5] << 8) + (ptr[4] << 0)); state.cur_location.lon.udeg = (int)((ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0)); - state.log->sites->create("DLF imported"s, state.cur_location)->add_dive(state.cur_dive.get()); + state.log->sites.create("DLF imported"s, state.cur_location)->add_dive(state.cur_dive.get()); break; default: break; diff --git a/core/parse.cpp b/core/parse.cpp index 5aef2d0c9..e427136a8 100644 --- a/core/parse.cpp +++ b/core/parse.cpp @@ -184,7 +184,7 @@ void dive_site_end(struct parser_state *state) if (!state->cur_dive_site) return; - struct dive_site *ds = state->log->sites->alloc_or_get(state->cur_dive_site->uuid); + struct dive_site *ds = state->log->sites.alloc_or_get(state->cur_dive_site->uuid); ds->merge(*state->cur_dive_site); if (verbose > 3) @@ -428,7 +428,7 @@ void add_dive_site(const char *ds_name, struct dive *dive, struct parser_state * struct dive_site *ds = dive->dive_site; if (!ds) { // if the dive doesn't have a dive site, check if there's already a dive site by this name - ds = state->log->sites->get_by_name(trimmed); + ds = state->log->sites.get_by_name(trimmed); } if (ds) { // we have a dive site, let's hope there isn't a different name @@ -439,12 +439,12 @@ void add_dive_site(const char *ds_name, struct dive *dive, struct parser_state * // but wait, we could have gotten this one based on GPS coords and could // have had two different names for the same site... so let's search the other // way around - struct dive_site *exact_match = state->log->sites->get_by_gps_and_name(trimmed, ds->location); + struct dive_site *exact_match = state->log->sites.get_by_gps_and_name(trimmed, ds->location); if (exact_match) { unregister_dive_from_dive_site(dive); exact_match->add_dive(dive); } else { - struct dive_site *newds = state->log->sites->create(trimmed.c_str()); + struct dive_site *newds = state->log->sites.create(trimmed.c_str()); unregister_dive_from_dive_site(dive); newds->add_dive(dive); if (has_location(&state->cur_location)) { @@ -462,7 +462,7 @@ void add_dive_site(const char *ds_name, struct dive *dive, struct parser_state * ds->add_dive(dive); } } else { - state->log->sites->create(trimmed)->add_dive(dive); + state->log->sites.create(trimmed)->add_dive(dive); } } } diff --git a/core/save-git.cpp b/core/save-git.cpp index a8e1e6c8e..80aa14c13 100644 --- a/core/save-git.cpp +++ b/core/save-git.cpp @@ -886,8 +886,8 @@ static void save_divesites(git_repository *repo, struct dir *tree) put_format(&dirname, "01-Divesites"); subdir = new_directory(repo, tree, &dirname); - divelog.sites->purge_empty(); - for (const auto &ds: *divelog.sites) { + divelog.sites.purge_empty(); + for (const auto &ds: divelog.sites) { membuffer b; membuffer site_file_name; put_format(&site_file_name, "Site-%08x", ds->uuid); diff --git a/core/save-xml.cpp b/core/save-xml.cpp index 40b64850a..e9a1e449e 100644 --- a/core/save-xml.cpp +++ b/core/save-xml.cpp @@ -653,7 +653,7 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym /* save the dive sites */ put_format(b, "\n"); - for (const auto &ds: *divelog.sites) { + for (const auto &ds: divelog.sites) { /* Don't export empty dive sites */ if (ds->is_empty()) continue; diff --git a/core/uemis-downloader.cpp b/core/uemis-downloader.cpp index c2f583cf4..1b9210148 100644 --- a/core/uemis-downloader.cpp +++ b/core/uemis-downloader.cpp @@ -918,7 +918,7 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, std::s } else if (non_owned_dive && tag == "divespot_id") { int divespot_id; if (from_chars(val, divespot_id).ec != std::errc::invalid_argument) { - struct dive_site *ds = devdata->log->sites->create("from Uemis"s); + struct dive_site *ds = devdata->log->sites.create("from Uemis"s); unregister_dive_from_dive_site(non_owned_dive); ds->add_dive(non_owned_dive); uemis_obj.mark_divelocation(non_owned_dive->dcs[0].diveid, divespot_id, ds); @@ -1094,19 +1094,19 @@ static void get_uemis_divespot(device_data_t *devdata, const std::string &mountp * we search all existing divesites if we have one with the same name already. The function * returns the first found which is luckily not the newly created. */ - struct dive_site *ods = devdata->log->sites->get_by_name(nds->name); + struct dive_site *ods = devdata->log->sites.get_by_name(nds->name); if (ods && nds->uuid != ods->uuid) { /* if the uuid's are the same, the new site is a duplicate and can be deleted */ unregister_dive_from_dive_site(dive); ods->add_dive(dive); - devdata->log->sites->pull(nds); + devdata->log->sites.pull(nds); } divespot_mapping[divespot_id] = dive->dive_site; } else { /* if we can't load the dive site details, delete the site we * created in process_raw_buffer */ - devdata->log->sites->pull(dive->dive_site); + devdata->log->sites.pull(dive->dive_site); dive->dive_site = nullptr; } } diff --git a/desktop-widgets/divesitelistview.cpp b/desktop-widgets/divesitelistview.cpp index c9b86c9b4..a15c01aaa 100644 --- a/desktop-widgets/divesitelistview.cpp +++ b/desktop-widgets/divesitelistview.cpp @@ -97,7 +97,7 @@ void DiveSiteListView::diveSiteAdded(struct dive_site *, int idx) void DiveSiteListView::diveSiteChanged(struct dive_site *ds, int field) { - size_t idx = divelog.sites->get_idx(ds); + size_t idx = divelog.sites.get_idx(ds); if (idx == std::string::npos) return; QModelIndex globalIdx = LocationInformationModel::instance()->index(static_cast(idx), field); diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index 4136a9db8..4bd640649 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -388,8 +388,8 @@ bool DiveLocationFilterProxyModel::lessThan(const QModelIndex &source_left, cons // If there is a current location, sort by that - otherwise use the provided column if (has_location(¤tLocation)) { // The dive sites are -2 because of the first two items. - auto loc1 = (*divelog.sites)[source_left.row() - 2]->location; - auto loc2 = (*divelog.sites)[source_right.row() - 2]->location; + auto loc1 = (divelog.sites)[source_left.row() - 2]->location; + auto loc2 = (divelog.sites)[source_right.row() - 2]->location; return get_distance(loc1, currentLocation) < get_distance(loc2, currentLocation); } return source_left.data().toString().compare(source_right.data().toString(), Qt::CaseInsensitive) < 0; @@ -411,7 +411,7 @@ QVariant DiveLocationModel::data(const QModelIndex &index, int role) const static const QIcon plusIcon(":list-add-icon"); static const QIcon geoCode(":geotag-icon"); - if (index.row() < 0 || index.row() >= (int)divelog.sites->size() + 2) + if (index.row() < 0 || index.row() >= (int)divelog.sites.size() + 2) return QVariant(); if (index.row() <= 1) { // two special cases. @@ -431,7 +431,7 @@ QVariant DiveLocationModel::data(const QModelIndex &index, int role) const } // The dive sites are -2 because of the first two items. - const auto &ds = (*divelog.sites)[index.row() - 2]; + const auto &ds = (divelog.sites)[index.row() - 2]; return LocationInformationModel::getDiveSiteData(*ds, index.column(), role); } @@ -442,7 +442,7 @@ int DiveLocationModel::columnCount(const QModelIndex&) const int DiveLocationModel::rowCount(const QModelIndex&) const { - return (int)divelog.sites->size() + 2; + return (int)divelog.sites.size() + 2; } Qt::ItemFlags DiveLocationModel::flags(const QModelIndex &index) const @@ -563,7 +563,7 @@ void DiveLocationLineEdit::refreshDiveSiteCache() static struct dive_site *get_dive_site_name_start_which_str(const QString &str) { - for (const auto &ds: *divelog.sites) { + for (const auto &ds: divelog.sites) { QString dsName = QString::fromStdString(ds->name); if (dsName.toLower().startsWith(str.toLower())) return ds.get(); diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 17acd5acf..15caf35cb 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -1408,12 +1408,12 @@ void MainWindow::on_actionImportDiveSites_triggered() parse_file(fileNamePtr.data(), &log); } // The imported dive sites still have pointers to imported dives - remove them - for (const auto &ds: *log.sites) + for (const auto &ds: log.sites) ds->dives.clear(); QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files"); - DivesiteImportDialog divesiteImport(std::move(*log.sites), source, this); + DivesiteImportDialog divesiteImport(std::move(log.sites), source, this); divesiteImport.exec(); } diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index b8292c7ea..687173865 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -1070,7 +1070,7 @@ bool QMLManager::checkLocation(DiveSiteChange &res, struct dive *d, QString loca bool changed = false; QString oldLocation = QString::fromStdString(get_dive_location(d)); if (oldLocation != location) { - ds = divelog.sites->get_by_name(location.toStdString()); + ds = divelog.sites.get_by_name(location.toStdString()); if (!ds && !location.isEmpty()) { res.createdDs = std::make_unique(qPrintable(location)); res.changed = true; @@ -1808,7 +1808,7 @@ QString QMLManager::getVersion() const QString QMLManager::getGpsFromSiteName(const QString &siteName) { - struct dive_site *ds = divelog.sites->get_by_name(siteName.toStdString()); + struct dive_site *ds = divelog.sites.get_by_name(siteName.toStdString()); if (!ds) return QString(); return printGPSCoords(&ds->location); diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index 45a528fab..ae539c01a 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -37,7 +37,7 @@ int LocationInformationModel::columnCount(const QModelIndex &) const int LocationInformationModel::rowCount(const QModelIndex &) const { - return (int)divelog.sites->size(); + return (int)divelog.sites.size(); } QVariant LocationInformationModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -119,10 +119,10 @@ QVariant LocationInformationModel::getDiveSiteData(const struct dive_site &ds, i QVariant LocationInformationModel::data(const QModelIndex &index, int role) const { - if (!index.isValid() || index.row() >= (int)divelog.sites->size()) + if (!index.isValid() || index.row() >= (int)divelog.sites.size()) return QVariant(); - const auto &ds = (*divelog.sites)[index.row()].get(); + const auto &ds = (divelog.sites)[index.row()].get(); return getDiveSiteData(*ds, index.column(), role); } @@ -134,7 +134,7 @@ void LocationInformationModel::update() void LocationInformationModel::diveSiteDiveCountChanged(dive_site *ds) { - size_t idx = divelog.sites->get_idx(ds); + size_t idx = divelog.sites.get_idx(ds); if (idx != std::string::npos) dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES)); } @@ -159,7 +159,7 @@ void LocationInformationModel::diveSiteDeleted(struct dive_site *, int idx) void LocationInformationModel::diveSiteChanged(struct dive_site *ds, int field) { - size_t idx = divelog.sites->get_idx(ds); + size_t idx = divelog.sites.get_idx(ds); if (idx == std::string::npos) return; dataChanged(createIndex(idx, field), createIndex(idx, field)); @@ -167,7 +167,7 @@ void LocationInformationModel::diveSiteChanged(struct dive_site *ds, int field) void LocationInformationModel::diveSiteDivesChanged(struct dive_site *ds) { - size_t idx = divelog.sites->get_idx(ds); + size_t idx = divelog.sites.get_idx(ds); if (idx == std::string::npos) return; dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES)); @@ -178,9 +178,9 @@ bool DiveSiteSortedModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou if (fullText.isEmpty()) return true; - if (sourceRow < 0 || sourceRow > (int)divelog.sites->size()) + if (sourceRow < 0 || sourceRow > (int)divelog.sites.size()) return false; - const auto &ds = (*divelog.sites)[sourceRow]; + const auto &ds = (divelog.sites)[sourceRow]; QString text = QString::fromStdString(ds->name + ds->description + ds->notes); return text.contains(fullText, Qt::CaseInsensitive); } @@ -192,13 +192,13 @@ bool DiveSiteSortedModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) // Kind of dirty, but less effort. // Be careful to respect proper ordering when sites are invalid. - bool valid1 = i1.row() >= 0 && i1.row() < (int)divelog.sites->size(); - bool valid2 = i2.row() >= 0 && i2.row() < (int)divelog.sites->size(); + bool valid1 = i1.row() >= 0 && i1.row() < (int)divelog.sites.size(); + bool valid2 = i2.row() >= 0 && i2.row() < (int)divelog.sites.size(); if (!valid1 || !valid2) return valid1 < valid2; - const auto &ds1 = (*divelog.sites)[i1.row()]; - const auto &ds2 = (*divelog.sites)[i2.row()]; + const auto &ds1 = (divelog.sites)[i1.row()]; + const auto &ds2 = (divelog.sites)[i2.row()]; switch (i1.column()) { case LocationInformationModel::NAME: default: @@ -232,11 +232,11 @@ QStringList DiveSiteSortedModel::allSiteNames() const // This shouldn't happen, but if model and core get out of sync, // (more precisely: the core has more sites than the model is aware of), // we might get an invalid index. - if (idx < 0 || idx > (int)divelog.sites->size()) { + if (idx < 0 || idx > (int)divelog.sites.size()) { report_info("DiveSiteSortedModel::allSiteNames(): invalid index"); continue; } - locationNames << QString::fromStdString((*divelog.sites)[idx]->name); + locationNames << QString::fromStdString((divelog.sites)[idx]->name); } return locationNames; } @@ -244,7 +244,7 @@ QStringList DiveSiteSortedModel::allSiteNames() const struct dive_site *DiveSiteSortedModel::getDiveSite(const QModelIndex &idx_source) { auto idx = mapToSource(idx_source).row(); - return idx >= 0 && idx < (int)divelog.sites->size() ? (*divelog.sites)[idx].get() : NULL; + return idx >= 0 && idx < (int)divelog.sites.size() ? (divelog.sites)[idx].get() : NULL; } #ifndef SUBSURFACE_MOBILE diff --git a/qt-models/divesiteimportmodel.cpp b/qt-models/divesiteimportmodel.cpp index 7408ebcdc..9847dacdd 100644 --- a/qt-models/divesiteimportmodel.cpp +++ b/qt-models/divesiteimportmodel.cpp @@ -11,7 +11,7 @@ DivesiteImportedModel::DivesiteImportedModel(dive_site_table &table, QObject *o) { checkStates.resize(importedSitesTable.size()); for (const auto &[row, item]: enumerated_range(importedSitesTable)) - checkStates[row] = !divelog.sites->get_by_gps(&item->location); + checkStates[row] = !divelog.sites.get_by_gps(&item->location); } int DivesiteImportedModel::columnCount(const QModelIndex &) const @@ -69,7 +69,7 @@ QVariant DivesiteImportedModel::data(const QModelIndex &index, int role) const case NEAREST: { // 40075000 is circumference of the earth in meters struct dive_site *nearest_ds = - divelog.sites->get_by_gps_proximity(ds->location, 40075000); + divelog.sites.get_by_gps_proximity(ds->location, 40075000); if (nearest_ds) return QString::fromStdString(nearest_ds->name); else @@ -78,7 +78,7 @@ QVariant DivesiteImportedModel::data(const QModelIndex &index, int role) const case DISTANCE: { unsigned int distance = 0; struct dive_site *nearest_ds = - divelog.sites->get_by_gps_proximity(ds->location, 40075000); + divelog.sites.get_by_gps_proximity(ds->location, 40075000); if (nearest_ds) distance = get_distance(ds->location, nearest_ds->location); return distance_string(distance); diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp index 9b096ac23..c1f5a2e1f 100644 --- a/qt-models/maplocationmodel.cpp +++ b/qt-models/maplocationmodel.cpp @@ -162,7 +162,7 @@ void MapLocationModel::reload(QObject *map) if (diveSiteMode) m_selectedDs = DiveFilter::instance()->filteredDiveSites(); #endif - for (const auto &ds: *divelog.sites) { + for (const auto &ds: divelog.sites) { QGeoCoordinate dsCoord; // Don't show dive sites of hidden dives, unless we're in dive site edit mode. diff --git a/smtk-import/smartrak.cpp b/smtk-import/smartrak.cpp index 43ce9ef07..7c1efeec1 100644 --- a/smtk-import/smartrak.cpp +++ b/smtk-import/smartrak.cpp @@ -403,12 +403,12 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, struct dive_site **lo concat(str, ", ", table.get_string_view(1)); // Locality concat(str, ", ", site); - ds = log->sites->get_by_name(str); + ds = log->sites.get_by_name(str); if (!ds) { if (!has_location(&loc)) - ds = log->sites->create(str); + ds = log->sites.create(str); else - ds = log->sites->create(str, loc); + ds = log->sites.create(str, loc); } *location = ds; diff --git a/tests/testdivesiteduplication.cpp b/tests/testdivesiteduplication.cpp index af5e798ac..e52a75314 100644 --- a/tests/testdivesiteduplication.cpp +++ b/tests/testdivesiteduplication.cpp @@ -9,7 +9,7 @@ void TestDiveSiteDuplication::testReadV2() { prefs.cloud_base_url = strdup(default_prefs.cloud_base_url); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &divelog), 0); - QCOMPARE(divelog.sites->size(), 2); + QCOMPARE(divelog.sites.size(), 2); } QTEST_GUILESS_MAIN(TestDiveSiteDuplication) diff --git a/tests/testparse.cpp b/tests/testparse.cpp index 39c753f4f..9167282b8 100644 --- a/tests/testparse.cpp +++ b/tests/testparse.cpp @@ -92,7 +92,7 @@ int TestParse::parseCSV(int units, std::string file) int TestParse::parseDivingLog() { // Parsing of DivingLog import from SQLite database - struct dive_site *ds = divelog.sites->alloc_or_get(0xdeadbeef); + struct dive_site *ds = divelog.sites.alloc_or_get(0xdeadbeef); ds->name = "Suomi - - Hälvälä"; int ret = sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql", &_sqlite3_handle);