From 1a6f42e78186418a4faf493a26942d9e229b68cc Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 11 May 2024 18:41:49 +0200 Subject: [PATCH] core: move get_same_dive_site() into dive_site_table class This was the only dive_site_table function that accessed to global divelog, which is odd. Make it consistent with the others. Signed-off-by: Berthold Stoeger --- commands/command_divesite.cpp | 7 +++---- core/divelist.cpp | 2 +- core/divesite.cpp | 6 ++---- core/divesite.h | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/commands/command_divesite.cpp b/commands/command_divesite.cpp index 886820e96..fb5373229 100644 --- a/commands/command_divesite.cpp +++ b/commands/command_divesite.cpp @@ -99,10 +99,9 @@ ImportDiveSites::ImportDiveSites(dive_site_table sites, const QString &source) setText(Command::Base::tr("import dive sites from %1").arg(source)); for (auto &new_ds: sites) { - // Don't import dive sites that already exist. Currently we only check for - // the same name. We might want to be smarter here and merge dive site data, etc. - struct dive_site *old_ds = get_same_dive_site(*new_ds); - if (old_ds) + // 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)) continue; sitesToAdd.push_back(std::move(new_ds)); } diff --git a/core/divelist.cpp b/core/divelist.cpp index b634c3ef7..002d34b68 100644 --- a/core/divelist.cpp +++ b/core/divelist.cpp @@ -1130,7 +1130,7 @@ void process_imported_dives(struct divelog *import_log, int flags, /* If dive sites already exist, use the existing versions. */ for (auto &new_ds: *import_log->sites) { - struct dive_site *old_ds = get_same_dive_site(*new_ds); + struct dive_site *old_ds = divelog.sites->get_same(*new_ds); /* Check if it dive site is actually used by new dives. */ for (j = 0; j < import_log->dives->nr; j++) { diff --git a/core/divesite.cpp b/core/divesite.cpp index f13b2e7d7..8c1ebb8d7 100644 --- a/core/divesite.cpp +++ b/core/divesite.cpp @@ -3,7 +3,6 @@ #include "divesite.h" #include "dive.h" #include "divelist.h" -#include "divelog.h" #include "errorhelper.h" #include "format.h" #include "membuffer.h" @@ -179,10 +178,9 @@ static bool same(const struct dive_site &a, const struct dive_site &b) && a.notes == b.notes; } -struct dive_site *get_same_dive_site(const struct dive_site &site) +dive_site *dive_site_table::get_same(const struct dive_site &site) const { - return get_by_predicate(*divelog.sites, - [site](const auto &ds) { return same(*ds, site); }); + return get_by_predicate(*this, [site](const auto &ds) { return same(*ds, site); }); } void dive_site::merge(dive_site &b) diff --git a/core/divesite.h b/core/divesite.h index 31c2a03c4..fba9cd7f9 100644 --- a/core/divesite.h +++ b/core/divesite.h @@ -52,11 +52,11 @@ public: dive_site *get_by_gps(const location_t *) const; dive_site *get_by_gps_and_name(const std::string &name, const location_t *) const; dive_site *get_by_gps_proximity(location_t, int distance) const; + dive_site *get_same(const struct dive_site &) const; void purge_empty(); }; struct dive_site *unregister_dive_from_dive_site(struct dive *d); -struct dive_site *get_same_dive_site(const struct dive_site &); // accesses global dive list /* Make pointer-to-dive_site a "Qt metatype" so that we can pass it through QVariants */ Q_DECLARE_METATYPE(dive_site *);