summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2018-10-20 14:12:15 -0400
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-10-21 19:55:09 +0300
commit28e3413ff66552f392fecee25068d634cdfe59fc (patch)
tree5fe303d1e7dc1c371e13b534b85c232e29aea884 /desktop-widgets
parentc9869406301ff72f76b399097f0845fc1102ced1 (diff)
downloadsubsurface-28e3413ff66552f392fecee25068d634cdfe59fc.tar.gz
Add 'location_t' data structure
Instead of having people treat latitude and longitude as separate things, just add a 'location_t' data structure that contains both. Almost all cases want to always act on them together. This is really just prep-work for adding a few more locations that we track: I want to add a entry/exit location to each dive (independent of the dive site) because of how the Garmin Descent gives us the information (and hopefully, some day, other dive computers too). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/divelogexportdialog.cpp4
-rw-r--r--desktop-widgets/locationinformation.cpp46
-rw-r--r--desktop-widgets/locationinformation.h2
-rw-r--r--desktop-widgets/mapwidget.cpp8
-rw-r--r--desktop-widgets/mapwidget.h6
-rw-r--r--desktop-widgets/modeldelegates.cpp7
-rw-r--r--desktop-widgets/subsurfacewebservices.cpp5
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp5
8 files changed, 39 insertions, 44 deletions
diff --git a/desktop-widgets/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp
index 747dc5258..928256df4 100644
--- a/desktop-widgets/divelogexportdialog.cpp
+++ b/desktop-widgets/divelogexportdialog.cpp
@@ -315,8 +315,8 @@ void DiveLogExportDialog::export_TeX(const char *filename, const bool selected_o
put_format(&buf, "\\def\\place{%s}\n", site ? site->name : "");
put_format(&buf, "\\def\\spot{}\n");
put_format(&buf, "\\def\\sitename{%s}\n", site ? site->name : "");
- site ? put_format(&buf, "\\def\\gpslat{%f}\n", site->latitude.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslat{}\n");
- site ? put_format(&buf, "\\def\\gpslon{%f}\n", site->longitude.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslon{}\n");
+ site ? put_format(&buf, "\\def\\gpslat{%f}\n", site->location.lat.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslat{}\n");
+ site ? put_format(&buf, "\\def\\gpslon{%f}\n", site->location.lon.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslon{}\n");
put_format(&buf, "\\def\\computer{%s}\n", dive->dc.model);
put_format(&buf, "\\def\\country{%s}\n", qPrintable(country));
put_format(&buf, "\\def\\time{%u:%02u}\n", FRACTION(dive->duration.seconds, 60));
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp
index 225e7ed78..9d3eccb02 100644
--- a/desktop-widgets/locationinformation.cpp
+++ b/desktop-widgets/locationinformation.cpp
@@ -116,8 +116,8 @@ void LocationInformationWidget::updateLabels()
ui.diveSiteNotes->setPlainText(diveSite->notes);
else
ui.diveSiteNotes->clear();
- if (diveSite->latitude.udeg || diveSite->longitude.udeg) {
- const char *coords = printGPSCoords(diveSite->latitude.udeg, diveSite->longitude.udeg);
+ if (has_location(&diveSite->location)) {
+ const char *coords = printGPSCoords(&diveSite->location);
ui.diveSiteCoordinates->setText(coords);
free((void *)coords);
} else {
@@ -137,12 +137,13 @@ void LocationInformationWidget::clearLabels()
ui.locationTags->clear();
}
-void LocationInformationWidget::updateGpsCoordinates(degrees_t latitude, degrees_t longitude)
+void LocationInformationWidget::updateGpsCoordinates(const location_t &location)
{
QString oldText = ui.diveSiteCoordinates->text();
- const char *coords = printGPSCoords(latitude.udeg, longitude.udeg);
+
+ const char *coords = printGPSCoords(&location);
ui.diveSiteCoordinates->setText(coords);
- enableLocationButtons(latitude.udeg || longitude.udeg);
+ enableLocationButtons(has_location(&location));
free((void *)coords);
if (oldText != ui.diveSiteCoordinates->text())
markChangedWidget(ui.diveSiteCoordinates);
@@ -150,12 +151,11 @@ void LocationInformationWidget::updateGpsCoordinates(degrees_t latitude, degrees
// Parse GPS text into latitude and longitude.
// On error, false is returned and the output parameters are left unmodified.
-bool parseGpsText(const QString &text, degrees_t &latitude, degrees_t &longitude)
+bool parseGpsText(const QString &text, location_t &location)
{
double lat, lon;
if (parseGpsText(text, &lat, &lon)) {
- latitude.udeg = lrint(lat * 1000000.0);
- longitude.udeg = lrint(lon * 1000000.0);
+ location = create_location(lat, lon);
return true;
}
return false;
@@ -204,7 +204,7 @@ void LocationInformationWidget::acceptChanges()
}
if (!ui.diveSiteCoordinates->text().isEmpty())
- parseGpsText(ui.diveSiteCoordinates->text(), diveSite->latitude, diveSite->longitude);
+ parseGpsText(ui.diveSiteCoordinates->text(), diveSite->location);
if (dive_site_is_empty(diveSite)) {
LocationInformationModel::instance()->removeRow(get_divesite_idx(diveSite));
displayed_dive.dive_site_uuid = 0;
@@ -224,7 +224,7 @@ void LocationInformationWidget::initFields(dive_site *ds)
diveSite = ds;
if (ds) {
copy_taxonomy(&ds->taxonomy, &taxonomy);
- filter_model.set(ds->uuid, ds->latitude, ds->longitude);
+ filter_model.set(ds->uuid, ds->location);
updateLabels();
enableLocationButtons(dive_site_has_gps_location(ds));
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(ui.diveSiteListView->model());
@@ -233,7 +233,7 @@ void LocationInformationWidget::initFields(dive_site *ds)
m->invalidate();
} else {
free_taxonomy(&taxonomy);
- filter_model.set(0, degrees_t{ 0 }, degrees_t{ 0 });
+ filter_model.set(0, location_t { degrees_t{ 0 }, degrees_t{ 0 } });
clearLabels();
}
MapWidget::instance()->prepareForGetDiveCoordinates(ds ? ds->uuid : 0);
@@ -276,14 +276,14 @@ void LocationInformationWidget::on_diveSiteCoordinates_textChanged(const QString
{
if (!diveSite)
return;
- degrees_t latitude, longitude;
- bool ok_old = diveSite->latitude.udeg || diveSite->longitude.udeg;
- bool ok = parseGpsText(text, latitude, longitude);
- if (ok != ok_old || latitude.udeg != diveSite->latitude.udeg || longitude.udeg != diveSite->longitude.udeg) {
+ location_t location;
+ bool ok_old = has_location(&diveSite->location);
+ bool ok = parseGpsText(text, location);
+ if (ok != ok_old || !same_location(&location, &diveSite->location)) {
if (ok) {
markChangedWidget(ui.diveSiteCoordinates);
enableLocationButtons(true);
- filter_model.setCoordinates(latitude, longitude);
+ filter_model.setCoordinates(location);
} else {
enableLocationButtons(false);
}
@@ -326,10 +326,10 @@ void LocationInformationWidget::resetPallete()
void LocationInformationWidget::reverseGeocode()
{
- degrees_t latitude, longitude;
- if (!parseGpsText(ui.diveSiteCoordinates->text(), latitude, longitude))
+ location_t location;
+ if (!parseGpsText(ui.diveSiteCoordinates->text(), location))
return;
- reverseGeoLookup(latitude, longitude, &taxonomy);
+ reverseGeoLookup(location.lat, location.lon, &taxonomy);
ui.locationTags->setText(constructLocationTags(&taxonomy, false));
}
@@ -337,11 +337,11 @@ void LocationInformationWidget::updateLocationOnMap()
{
if (!diveSite)
return;
- degrees_t latitude, longitude;
- if (!parseGpsText(ui.diveSiteCoordinates->text(), latitude, longitude))
+ location_t location;
+ if (!parseGpsText(ui.diveSiteCoordinates->text(), location))
return;
- MapWidget::instance()->updateDiveSiteCoordinates(diveSite->uuid, latitude, longitude);
- filter_model.setCoordinates(latitude, longitude);
+ MapWidget::instance()->updateDiveSiteCoordinates(diveSite->uuid, location);
+ filter_model.setCoordinates(location);
}
DiveLocationFilterProxyModel::DiveLocationFilterProxyModel(QObject*)
diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h
index a6141c4fc..a072c4193 100644
--- a/desktop-widgets/locationinformation.h
+++ b/desktop-widgets/locationinformation.h
@@ -24,7 +24,7 @@ protected:
public slots:
void acceptChanges();
void rejectChanges();
- void updateGpsCoordinates(degrees_t latitude, degrees_t longitude);
+ void updateGpsCoordinates(const location_t &);
void markChangedWidget(QWidget *w);
void enableEdition();
void resetState();
diff --git a/desktop-widgets/mapwidget.cpp b/desktop-widgets/mapwidget.cpp
index 945e9fe1c..095565618 100644
--- a/desktop-widgets/mapwidget.cpp
+++ b/desktop-widgets/mapwidget.cpp
@@ -109,16 +109,16 @@ void MapWidget::selectedDivesChanged(QList<int> list)
skipReload = false;
}
-void MapWidget::coordinatesChangedLocal(degrees_t latitude, degrees_t longitude)
+void MapWidget::coordinatesChangedLocal(const location_t &location)
{
CHECK_IS_READY_RETURN_VOID();
- emit coordinatesChanged(latitude, longitude);
+ emit coordinatesChanged(location);
}
-void MapWidget::updateDiveSiteCoordinates(uint32_t uuid, degrees_t latitude, degrees_t longitude)
+void MapWidget::updateDiveSiteCoordinates(uint32_t uuid, const location_t &location)
{
CHECK_IS_READY_RETURN_VOID();
- m_mapHelper->updateDiveSiteCoordinates(uuid, latitude, longitude);
+ m_mapHelper->updateDiveSiteCoordinates(uuid, location);
}
MapWidget::~MapWidget()
diff --git a/desktop-widgets/mapwidget.h b/desktop-widgets/mapwidget.h
index eb7d994aa..aaed93218 100644
--- a/desktop-widgets/mapwidget.h
+++ b/desktop-widgets/mapwidget.h
@@ -25,7 +25,7 @@ public:
void reload();
signals:
- void coordinatesChanged(degrees_t latitude, degrees_t longitude);
+ void coordinatesChanged(const location_t &);
public slots:
void centerOnSelectedDiveSite();
@@ -35,9 +35,9 @@ public slots:
void repopulateLabels();
void prepareForGetDiveCoordinates(uint32_t uuid);
void selectedDivesChanged(QList<int>);
- void coordinatesChangedLocal(degrees_t latitude, degrees_t longitude);
+ void coordinatesChangedLocal(const location_t &);
void doneLoading(QQuickWidget::Status status);
- void updateDiveSiteCoordinates(uint32_t uuid, degrees_t latitude, degrees_t longitude);
+ void updateDiveSiteCoordinates(uint32_t uuid, const location_t &);
private:
static MapWidget *m_instance;
diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp
index 7b9bd8952..842598467 100644
--- a/desktop-widgets/modeldelegates.cpp
+++ b/desktop-widgets/modeldelegates.cpp
@@ -479,7 +479,7 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
}
if (bottomText.isEmpty()) {
- const char *gpsCoords = printGPSCoords(ds->latitude.udeg, ds->longitude.udeg);
+ const char *gpsCoords = printGPSCoords(&ds->location);
bottomText = QString(gpsCoords);
free( (void*) gpsCoords);
}
@@ -487,11 +487,10 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
if (dive_site_has_gps_location(ds) && currentDiveSiteHasGPS) {
// 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
- if (ds->latitude.udeg == currentDiveSite->latitude.udeg &&
- ds->longitude.udeg == currentDiveSite->longitude.udeg) {
+ if (same_location(&ds->location, &currentDiveSite->location)) {
bottomText += tr(" (same GPS fix)");
} else {
- int distanceMeters = get_distance(ds->latitude, ds->longitude, currentDiveSite->latitude, currentDiveSite->longitude);
+ int distanceMeters = get_distance(&ds->location, &currentDiveSite->location);
QString distance = distance_string(distanceMeters);
int nr = nr_of_dives_at_dive_site(ds->uuid, false);
bottomText += tr(" (~%1 away").arg(distance);
diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp
index db2fece76..7e67366eb 100644
--- a/desktop-widgets/subsurfacewebservices.cpp
+++ b/desktop-widgets/subsurfacewebservices.cpp
@@ -204,10 +204,7 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
put_format(&mb, "<divelog><divesites><site uuid='%8x' name='", dive->dive_site_uuid);
put_quoted(&mb, ds->name, 1, 0);
put_format(&mb, "'");
- if (ds->latitude.udeg || ds->longitude.udeg) {
- put_degrees(&mb, ds->latitude, " gps='", " ");
- put_degrees(&mb, ds->longitude, "", "'");
- }
+ put_location(&mb, &ds->location, " gps='", "'");
put_format(&mb, ">\n");
if (ds->taxonomy.nr) {
for (int j = 0; j < ds->taxonomy.nr; j++) {
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index bb8f0d904..6f3691d3d 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -696,9 +696,8 @@ uint32_t MainTab::updateDiveSite(uint32_t pickedUuid, dive *d)
newDs->name = copy_qstring(ui.location->text());
newDs->uuid = pickedUuid;
qDebug() << "Creating and copying dive site";
- } else if (newDs->latitude.udeg == 0 && newDs->longitude.udeg == 0) {
- newDs->latitude.udeg = origDs->latitude.udeg;
- newDs->longitude.udeg = origDs->longitude.udeg;
+ } else if (!has_location(&newDs->location)) {
+ newDs->location = origDs->location;
qDebug() << "Copying GPS information";
}
}