core: move divesite_has_gps_information() to struct dive_site

Seems logical in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-30 17:38:36 +02:00 committed by bstoeger
parent c812dd140b
commit 0aa4efb3d9
14 changed files with 20 additions and 21 deletions

View file

@ -173,7 +173,7 @@ AddPictures::AddPictures(const std::vector<PictureListForAddition> &pictures) :
QString name = Command::Base::tr("unnamed dive site"); QString name = Command::Base::tr("unnamed dive site");
sitesToAdd.push_back(std::make_unique<dive_site>(qPrintable(name), it->location)); sitesToAdd.push_back(std::make_unique<dive_site>(qPrintable(name), it->location));
sitesToSet.push_back({ p.d, sitesToAdd.back().get() }); sitesToSet.push_back({ p.d, sitesToAdd.back().get() });
} else if (!dive_site_has_gps_location(ds)) { } else if (!ds->has_gps_location()) {
// This dive has a dive site, but without coordinates. Let's add them. // This dive has a dive site, but without coordinates. Let's add them.
sitesToEdit.push_back({ ds, it->location }); sitesToEdit.push_back({ ds, it->location });
} }

View file

@ -2531,14 +2531,9 @@ const struct divecomputer *get_dive_dc(const struct dive *dive, int nr)
return get_dive_dc((struct dive *)dive, nr); return get_dive_dc((struct dive *)dive, nr);
} }
bool dive_site_has_gps_location(const struct dive_site *ds)
{
return ds && has_location(&ds->location);
}
bool dive::dive_has_gps_location() const bool dive::dive_has_gps_location() const
{ {
return dive_site && dive_site_has_gps_location(dive_site); return dive_site && dive_site->has_gps_location();
} }
/* Extract GPS location of a dive computer stored in the GPS1 /* Extract GPS location of a dive computer stored in the GPS1

View file

@ -167,8 +167,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 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 bool time_during_dive_with_offset(const struct dive *dive, timestamp_t when, timestamp_t offset); extern bool time_during_dive_with_offset(const struct dive *dive, timestamp_t when, timestamp_t offset);
extern int save_dives(const char *filename); extern int save_dives(const char *filename);

View file

@ -1175,7 +1175,7 @@ merge_result dive_table::merge_dives(const struct dive &a_in, const struct dive
/* we take the first dive site, unless it's empty */ /* we take the first dive site, unless it's empty */
res.site = a->dive_site && !a->dive_site->is_empty() ? a->dive_site : b->dive_site; res.site = a->dive_site && !a->dive_site->is_empty() ? a->dive_site : b->dive_site;
if (!dive_site_has_gps_location(res.site) && dive_site_has_gps_location(b->dive_site)) { if (res.site && !res.site->has_gps_location() && b->dive_site && b->dive_site->has_gps_location()) {
/* we picked the first dive site and that didn't have GPS data, but the new dive has /* we picked the first dive site and that didn't have GPS data, but the new dive has
* GPS data (that could be a download from a GPS enabled dive computer). * GPS data (that could be a download from a GPS enabled dive computer).
* Keep the dive site, but add the GPS data */ * Keep the dive site, but add the GPS data */

View file

@ -134,6 +134,11 @@ bool dive_site::is_selected() const
[](dive *dive) { return dive->selected; }); [](dive *dive) { return dive->selected; });
} }
bool dive_site::has_gps_location() const
{
return has_location(&location);
}
/* allocate a new site and add it to the table */ /* allocate a new site and add it to the table */
dive_site *dive_site_table::create(const std::string &name) dive_site *dive_site_table::create(const std::string &name)
{ {

View file

@ -26,6 +26,7 @@ struct dive_site
size_t nr_of_dives() const; size_t nr_of_dives() const;
bool is_selected() const; bool is_selected() const;
bool is_empty() const; bool is_empty() const;
bool has_gps_location() const;
void merge(struct dive_site &b); // Note: b is consumed void merge(struct dive_site &b); // Note: b is consumed
void add_dive(struct dive *d); void add_dive(struct dive *d);
}; };

View file

@ -181,7 +181,7 @@ static void parse_dive_gps(char *line, struct git_parser_state *state)
ds = state->log->sites.create(std::string(), location); ds = state->log->sites.create(std::string(), location);
ds->add_dive(state->active_dive.get()); ds->add_dive(state->active_dive.get());
} else { } else {
if (dive_site_has_gps_location(ds) && ds->location != location) { if (ds->has_gps_location() && ds->location != location) {
std::string coords = printGPSCoordsC(&location); std::string coords = printGPSCoordsC(&location);
// we have a dive site that already has GPS coordinates // we have a dive site that already has GPS coordinates
// note 1: there will be much less copying once the core // note 1: there will be much less copying once the core

View file

@ -36,7 +36,7 @@ static void writeMarkers(struct membuffer *b, bool selected_only)
if (selected_only && !dive->selected) if (selected_only && !dive->selected)
continue; continue;
struct dive_site *ds = get_dive_site_for_dive(dive.get()); struct dive_site *ds = get_dive_site_for_dive(dive.get());
if (!dive_site_has_gps_location(ds)) if (!ds || !ds->has_gps_location())
continue; continue;
put_degrees(b, ds->location.lat, "temp = new google.maps.Marker({position: new google.maps.LatLng(", ""); put_degrees(b, ds->location.lat, "temp = new google.maps.Marker({position: new google.maps.LatLng(", "");
put_degrees(b, ds->location.lon, ",", ")});\n"); put_degrees(b, ds->location.lon, ",", ")});\n");

View file

@ -259,7 +259,7 @@ void LocationInformationWidget::initFields(dive_site *ds)
if (ds) { if (ds) {
filter_model.set(ds, ds->location); filter_model.set(ds, ds->location);
updateLabels(); updateLabels();
enableLocationButtons(dive_site_has_gps_location(ds)); enableLocationButtons(ds->has_gps_location());
DiveFilter::instance()->startFilterDiveSites(std::vector<dive_site *>{ ds }); DiveFilter::instance()->startFilterDiveSites(std::vector<dive_site *>{ ds });
filter_model.invalidate(); filter_model.invalidate();
} else { } else {

View file

@ -61,7 +61,7 @@ void MapWidget::centerOnIndex(const QModelIndex& idx)
{ {
CHECK_IS_READY_RETURN_VOID(); CHECK_IS_READY_RETURN_VOID();
dive_site *ds = idx.model()->index(idx.row(), LocationInformationModel::DIVESITE).data().value<dive_site *>(); dive_site *ds = idx.model()->index(idx.row(), LocationInformationModel::DIVESITE).data().value<dive_site *>();
if (!ds || ds == RECENTLY_ADDED_DIVESITE || !dive_site_has_gps_location(ds)) if (!ds || ds == RECENTLY_ADDED_DIVESITE || !ds->has_gps_location())
m_mapHelper->centerOnSelectedDiveSite(); m_mapHelper->centerOnSelectedDiveSite();
else else
centerOnDiveSite(ds); centerOnDiveSite(ds);

View file

@ -471,7 +471,7 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
if (bottomText.isEmpty()) if (bottomText.isEmpty())
bottomText = printGPSCoords(&ds->location); bottomText = printGPSCoords(&ds->location);
if (dive_site_has_gps_location(ds) && currentDiveHasGPS) { if (ds->has_gps_location() && currentDiveHasGPS) {
// so we are showing a completion and both the current dive site and the completion // so we are showing a completion and both the current dive site and the completion
// have a GPS fix... so let's show the distance // have a GPS fix... so let's show the distance
if (ds->location == currentLocation) { if (ds->location == currentLocation) {

View file

@ -30,14 +30,14 @@ MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
QGeoCoordinate MapWidgetHelper::getCoordinates(struct dive_site *ds) QGeoCoordinate MapWidgetHelper::getCoordinates(struct dive_site *ds)
{ {
if (!dive_site_has_gps_location(ds)) if (!ds || !ds->has_gps_location())
return QGeoCoordinate(0.0, 0.0); return QGeoCoordinate(0.0, 0.0);
return QGeoCoordinate(ds->location.lat.udeg * 0.000001, ds->location.lon.udeg * 0.000001); return QGeoCoordinate(ds->location.lat.udeg * 0.000001, ds->location.lon.udeg * 0.000001);
} }
void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds) void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds)
{ {
if (!dive_site_has_gps_location(ds)) { if (!ds || !ds->has_gps_location()) {
// dive site with no GPS // dive site with no GPS
m_mapLocationModel->setSelected(ds); m_mapLocationModel->setSelected(ds);
QMetaObject::invokeMethod(m_map, "deselectMapLocation"); QMetaObject::invokeMethod(m_map, "deselectMapLocation");
@ -136,7 +136,7 @@ void MapWidgetHelper::selectedLocationChanged(struct dive_site *ds_in)
for (auto [idx, dive]: enumerated_range(divelog.dives)) { for (auto [idx, dive]: enumerated_range(divelog.dives)) {
struct dive_site *ds = get_dive_site_for_dive(dive.get()); struct dive_site *ds = get_dive_site_for_dive(dive.get());
if (!dive_site_has_gps_location(ds)) if (!ds || !ds->has_gps_location())
continue; continue;
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
const qreal latitude = ds->location.lat.udeg * 0.000001; const qreal latitude = ds->location.lat.udeg * 0.000001;
@ -164,7 +164,7 @@ void MapWidgetHelper::selectVisibleLocations()
QList<int> selectedDiveIds; QList<int> selectedDiveIds;
for (auto [idx, dive]: enumerated_range(divelog.dives)) { for (auto [idx, dive]: enumerated_range(divelog.dives)) {
struct dive_site *ds = get_dive_site_for_dive(dive.get()); struct dive_site *ds = get_dive_site_for_dive(dive.get());
if (!dive_site_has_gps_location(ds)) if (!ds || ds->has_gps_location())
continue; continue;
const qreal latitude = ds->location.lat.udeg * 0.000001; const qreal latitude = ds->location.lat.udeg * 0.000001;
const qreal longitude = ds->location.lon.udeg * 0.000001; const qreal longitude = ds->location.lon.udeg * 0.000001;

View file

@ -108,7 +108,7 @@ QVariant LocationInformationModel::getDiveSiteData(const struct dive_site &ds, i
case EDIT: return editIcon(); case EDIT: return editIcon();
case REMOVE: return trashIcon(); case REMOVE: return trashIcon();
#endif #endif
case NAME: return dive_site_has_gps_location(&ds) ? QIcon(":geotag-icon") : QVariant(); case NAME: return ds.has_gps_location() ? QIcon(":geotag-icon") : QVariant();
} }
break; break;
case DIVESITE_ROLE: case DIVESITE_ROLE:

View file

@ -168,7 +168,7 @@ void MapLocationModel::reload(QObject *map)
// Don't show dive sites of hidden dives, unless we're in dive site edit mode. // Don't show dive sites of hidden dives, unless we're in dive site edit mode.
if (!diveSiteMode && !hasVisibleDive(*ds)) if (!diveSiteMode && !hasVisibleDive(*ds))
continue; continue;
if (!dive_site_has_gps_location(ds.get())) { if (!ds->has_gps_location()) {
// Dive sites that do not have a gps location are not shown in normal mode. // Dive sites that do not have a gps location are not shown in normal mode.
// In dive-edit mode, selected sites are placed at the center of the map, // In dive-edit mode, selected sites are placed at the center of the map,
// so that the user can drag them somewhere without having to enter coordinates. // so that the user can drag them somewhere without having to enter coordinates.