From 690b77cc22e122537491ccf67b6bd344ef5cb45f Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Wed, 20 May 2015 12:25:46 +0200 Subject: [PATCH] Add option to display GPS coordinates as decimals This adds a field to the units preferences to have GPS coordinates show as decimals (as for example Google maps does it). Signed-off-by: Robert C. Helling --- pref.h | 1 + qt-ui/preferences.cpp | 4 + qt-ui/preferences.ui | 283 ++++++++++++++++++++++++++++---------------------- qthelper.cpp | 30 +++--- subsurfacestartup.c | 1 + 5 files changed, 183 insertions(+), 136 deletions(-) diff --git a/pref.h b/pref.h index afc5373..2e5bf83 100644 --- a/pref.h +++ b/pref.h @@ -48,6 +48,7 @@ struct preferences { short display_invalid_dives; short unit_system; struct units units; + bool coordinates_traditional; short show_sac; short display_unused_tanks; short show_average_depth; diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index e4f9700..aeccc96 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -146,6 +146,8 @@ void PreferencesDialog::setUiFromPrefs() ui.imperial->setChecked(true); else ui.personalize->setChecked(true); + ui.gpsTraditional->setChecked(prefs.coordinates_traditional); + ui.gpsDecimal->setChecked(!prefs.coordinates_traditional); ui.celsius->setChecked(prefs.units.temperature == units::CELSIUS); ui.fahrenheit->setChecked(prefs.units.temperature == units::FAHRENHEIT); @@ -306,6 +308,7 @@ void PreferencesDialog::syncSettings() s.setValue("volume", ui.cuft->isChecked() ? units::CUFT : units::LITER); s.setValue("weight", ui.lbs->isChecked() ? units::LBS : units::KG); s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); + s.setValue("coordinates", ui.gpsTraditional->isChecked()); s.endGroup(); // Defaults @@ -384,6 +387,7 @@ void PreferencesDialog::loadSettings() GET_UNIT("weight", weight, units::LBS, units::KG); } GET_UNIT("vertical_speed_time", vertical_speed_time, units::MINUTES, units::SECONDS); + GET_BOOL("coordinates", coordinates_traditional); s.endGroup(); s.beginGroup("TecDetails"); GET_BOOL("po2graph", pp_graphs.po2); diff --git a/qt-ui/preferences.ui b/qt-ui/preferences.ui index e67925f..84c90d7 100644 --- a/qt-ui/preferences.ui +++ b/qt-ui/preferences.ui @@ -22,127 +22,6 @@ - - - - 0 - 0 - - - - - 80 - 0 - - - - - 80 - 16777215 - - - - - 40 - 40 - - - - Qt::ElideNone - - - QListView::Static - - - true - - - QListView::Batched - - - 0 - - - - 70 - 60 - - - - QListView::IconMode - - - false - - - true - - - -1 - - - - Defaults - - - - :/subsurface-icon - - - - - - Units - - - - :/units - - - - - - Graph - - - - :/graph - - - - - - Language - - - - :/advanced - - - - - - Network - - - - :/network - - - - - - Facebook - - - - :/facebook - - - - - - @@ -585,6 +464,42 @@ + + + GPS coordinates + + + + + + Location Display + + + + + + + traditional (dms) + + + buttonGroup_7 + + + + + + + decimal + + + buttonGroup_7 + + + + + + + Qt::Vertical @@ -1077,6 +992,127 @@ + + + + + 0 + 0 + + + + + 80 + 0 + + + + + 80 + 16777215 + + + + + 40 + 40 + + + + Qt::ElideNone + + + QListView::Static + + + true + + + QListView::Batched + + + 0 + + + + 70 + 60 + + + + QListView::IconMode + + + false + + + true + + + -1 + + + + Defaults + + + + :/subsurface-icon + + + + + + Units + + + + :/units + + + + + + Graph + + + + :/graph + + + + + + Language + + + + :/advanced + + + + + + Network + + + + :/network + + + + + + Facebook + + + + :/facebook + + + + + @@ -1431,12 +1467,13 @@ - + + - + diff --git a/qthelper.cpp b/qthelper.cpp index 030ed94..bbe908e 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -84,19 +84,23 @@ extern "C" const char *printGPSCoords(int lat, int lon) if (!lat && !lon) return strdup(""); - lath = lat >= 0 ? translate("gettextFromC", "N") : translate("gettextFromC", "S"); - lonh = lon >= 0 ? translate("gettextFromC", "E") : translate("gettextFromC", "W"); - lat = abs(lat); - lon = abs(lon); - latdeg = lat / 1000000U; - londeg = lon / 1000000U; - latmin = (lat % 1000000U) * 60U; - lonmin = (lon % 1000000U) * 60U; - latsec = (latmin % 1000000) * 60; - lonsec = (lonmin % 1000000) * 60; - result.sprintf("%u%s%02d\'%06.3f\"%s %u%s%02d\'%06.3f\"%s", - latdeg, UTF8_DEGREE, latmin / 1000000, latsec / 1000000, lath.toUtf8().data(), - londeg, UTF8_DEGREE, lonmin / 1000000, lonsec / 1000000, lonh.toUtf8().data()); + if (prefs.coordinates_traditional) { + lath = lat >= 0 ? translate("gettextFromC", "N") : translate("gettextFromC", "S"); + lonh = lon >= 0 ? translate("gettextFromC", "E") : translate("gettextFromC", "W"); + lat = abs(lat); + lon = abs(lon); + latdeg = lat / 1000000U; + londeg = lon / 1000000U; + latmin = (lat % 1000000U) * 60U; + lonmin = (lon % 1000000U) * 60U; + latsec = (latmin % 1000000) * 60; + lonsec = (lonmin % 1000000) * 60; + result.sprintf("%u%s%02d\'%06.3f\"%s %u%s%02d\'%06.3f\"%s", + latdeg, UTF8_DEGREE, latmin / 1000000, latsec / 1000000, lath.toUtf8().data(), + londeg, UTF8_DEGREE, lonmin / 1000000, lonsec / 1000000, lonh.toUtf8().data()); + } else { + result.sprintf("%f %f", (double) lat / 1000000.0, (double) lon / 1000000.0); + } return strdup(result.toUtf8().data()); } diff --git a/subsurfacestartup.c b/subsurfacestartup.c index d7a7ede..886365a 100644 --- a/subsurfacestartup.c +++ b/subsurfacestartup.c @@ -7,6 +7,7 @@ struct preferences prefs; struct preferences default_prefs = { .units = SI_UNITS, .unit_system = METRIC, + .coordinates_traditional = true, .pp_graphs = { .po2 = false, .pn2 = false, -- 2.3.2 (Apple Git-55)