mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
core: move dive_[has|get]_gps_location() to struct dive
Feel natural in a C++ code base. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
286d8fe21c
commit
e90251b0cf
7 changed files with 16 additions and 20 deletions
|
@ -381,7 +381,7 @@ static struct dive_site *createDiveSite(const std::string &name)
|
|||
|
||||
// If the current dive has a location, use that as location for the new dive site
|
||||
if (current_dive) {
|
||||
location_t loc = dive_get_gps_location(current_dive);
|
||||
location_t loc = current_dive->get_gps_location();
|
||||
if (has_location(&loc))
|
||||
ds->location = loc;
|
||||
}
|
||||
|
|
|
@ -2538,20 +2538,18 @@ bool dive_site_has_gps_location(const struct dive_site *ds)
|
|||
return ds && has_location(&ds->location);
|
||||
}
|
||||
|
||||
int dive_has_gps_location(const struct dive *dive)
|
||||
bool dive::dive_has_gps_location() const
|
||||
{
|
||||
if (!dive)
|
||||
return false;
|
||||
return dive_site_has_gps_location(dive->dive_site);
|
||||
return dive_site && dive_site_has_gps_location(dive_site);
|
||||
}
|
||||
|
||||
/* Extract GPS location of a dive computer stored in the GPS1
|
||||
* or GPS2 extra data fields */
|
||||
static location_t dc_get_gps_location(const struct divecomputer *dc)
|
||||
static location_t dc_get_gps_location(const struct divecomputer &dc)
|
||||
{
|
||||
location_t res;
|
||||
|
||||
for (const auto &data: dc->extra_data) {
|
||||
for (const auto &data: dc.extra_data) {
|
||||
if (data.key == "GPS1") {
|
||||
parse_location(data.value.c_str(), &res);
|
||||
/* If we found a valid GPS1 field exit early since
|
||||
|
@ -2573,10 +2571,10 @@ static location_t dc_get_gps_location(const struct divecomputer *dc)
|
|||
* This function is potentially slow, therefore only call sparingly
|
||||
* and remember the result.
|
||||
*/
|
||||
location_t dive_get_gps_location(const struct dive *d)
|
||||
location_t dive::get_gps_location() const
|
||||
{
|
||||
for (const struct divecomputer &dc: d->dcs) {
|
||||
location_t res = dc_get_gps_location(&dc);
|
||||
for (const struct divecomputer &dc: dcs) {
|
||||
location_t res = dc_get_gps_location(dc);
|
||||
if (has_location(&res))
|
||||
return res;
|
||||
}
|
||||
|
@ -2584,10 +2582,7 @@ location_t dive_get_gps_location(const struct dive *d)
|
|||
/* No libdivecomputer generated GPS data found.
|
||||
* Let's use the location of the current dive site.
|
||||
*/
|
||||
if (d->dive_site)
|
||||
return d->dive_site->location;
|
||||
|
||||
return location_t();
|
||||
return dive_site ? dive_site->location : location_t();
|
||||
}
|
||||
|
||||
gasmix_loop::gasmix_loop(const struct dive &d, const struct divecomputer &dc) :
|
||||
|
|
|
@ -118,6 +118,9 @@ struct dive {
|
|||
depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, int roundto) const;
|
||||
depth_t gas_mnd(struct gasmix mix, depth_t end, int roundto) const;
|
||||
|
||||
bool dive_has_gps_location() const;
|
||||
location_t get_gps_location() const;
|
||||
|
||||
/* Don't call directly, use dive_table::merge_dives()! */
|
||||
static std::unique_ptr<dive> create_merged_dive(const struct dive &a, const struct dive &b, int offset, bool prefer_downloaded);
|
||||
};
|
||||
|
@ -166,8 +169,6 @@ extern const struct divecomputer *get_dive_dc(const struct dive *dive, int nr);
|
|||
extern std::unique_ptr<dive> clone_make_first_dc(const struct dive &d, int dc_number);
|
||||
|
||||
extern bool dive_site_has_gps_location(const struct dive_site *ds);
|
||||
extern int dive_has_gps_location(const struct dive *dive);
|
||||
extern location_t dive_get_gps_location(const struct dive *d);
|
||||
|
||||
extern bool time_during_dive_with_offset(const struct dive *dive, timestamp_t when, timestamp_t offset);
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ dive_site *dive_site_table::get_by_gps_proximity(location_t loc, int distance) c
|
|||
struct dive_site *res = nullptr;
|
||||
unsigned int cur_distance, min_distance = distance;
|
||||
for (const auto &ds: *this) {
|
||||
if (dive_site_has_gps_location(ds.get()) &&
|
||||
if (ds->has_gps_location() &&
|
||||
(cur_distance = get_distance(ds->location, loc)) < min_distance) {
|
||||
min_distance = cur_distance;
|
||||
res = ds.get();
|
||||
|
|
|
@ -1207,7 +1207,7 @@ static void gps_in_dive(const char *buffer, struct dive *dive, struct parser_sta
|
|||
}
|
||||
ds->add_dive(dive);
|
||||
} else {
|
||||
if (dive_site_has_gps_location(ds) &&
|
||||
if (ds->has_gps_location() &&
|
||||
has_location(&location) && ds->location != location) {
|
||||
// Houston, we have a problem
|
||||
report_info("dive site uuid in dive, but gps location (%10.6f/%10.6f) different from dive location (%10.6f/%10.6f)",
|
||||
|
|
|
@ -667,7 +667,7 @@ void DiveLocationLineEdit::setCurrentDiveSite(struct dive *d)
|
|||
location_t currentLocation;
|
||||
if (d) {
|
||||
currDs = get_dive_site_for_dive(d);
|
||||
currentLocation = dive_get_gps_location(d);
|
||||
currentLocation = d->get_gps_location();
|
||||
} else {
|
||||
currDs = nullptr;
|
||||
}
|
||||
|
|
|
@ -371,7 +371,7 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role)
|
|||
case COUNTRY:
|
||||
return QVariant();
|
||||
case LOCATION:
|
||||
if (dive_has_gps_location(d))
|
||||
if (d->dive_has_gps_location())
|
||||
return getGlobeIcon();
|
||||
break;
|
||||
case PHOTOS:
|
||||
|
|
Loading…
Reference in a new issue