mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
4ac2486a23
commit
512eada468
4 changed files with 7 additions and 10 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 *);
|
||||
|
|
Loading…
Reference in a new issue