diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-07-14 11:35:04 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-07-14 11:52:17 -0700 |
commit | 8c0d0de2e62356e1bbdad97843d185a37973c5c7 (patch) | |
tree | 0179eee9ba82a843f676551e61b9886930c9ceab | |
parent | e82f8ea565a68aa1fa980cb12c1f136b1d4a57f9 (diff) | |
download | subsurface-8c0d0de2e62356e1bbdad97843d185a37973c5c7.tar.gz |
Location completer: give distance if known
If both the displayed dive and the dive site which is shown as a potential
completion have a GPS fix, indicate the distance.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | divesite.c | 2 | ||||
-rw-r--r-- | divesite.h | 1 | ||||
-rw-r--r-- | qt-ui/modeldelegates.cpp | 12 | ||||
-rw-r--r-- | qthelper.cpp | 18 | ||||
-rw-r--r-- | qthelper.h | 1 | ||||
-rw-r--r-- | units.h | 5 |
6 files changed, 38 insertions, 1 deletions
diff --git a/divesite.c b/divesite.c index 998fe23bf..56479508b 100644 --- a/divesite.c +++ b/divesite.c @@ -37,7 +37,7 @@ uint32_t get_dive_site_uuid_by_gps(degrees_t latitude, degrees_t longitude, stru } // Calculate the distance in meters between two coordinates. -static unsigned int get_distance(degrees_t lat1, degrees_t lon1, degrees_t lat2, degrees_t lon2) +unsigned int get_distance(degrees_t lat1, degrees_t lon1, degrees_t lat2, degrees_t lon2) { double lat1_r = udeg_to_radians(lat1.udeg); double lat2_r = udeg_to_radians(lat2.udeg); diff --git a/divesite.h b/divesite.h index 306272e96..3447d1836 100644 --- a/divesite.h +++ b/divesite.h @@ -59,6 +59,7 @@ uint32_t get_dive_site_uuid_by_gps_proximity(degrees_t latitude, degrees_t longi bool dive_site_is_empty(struct dive_site *ds); void copy_dive_site(struct dive_site *orig, struct dive_site *copy); void clear_dive_site(struct dive_site *ds); +unsigned int get_distance(degrees_t lat1, degrees_t lon1, degrees_t lat2, degrees_t lon2); #ifdef __cplusplus } diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index 3357d3909..3e4c860df 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -517,6 +517,18 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem free( (void*) gpsCoords); } + if (dive_site_has_gps_location(ds) && dive_site_has_gps_location(&displayed_dive_site)) { + // 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 == displayed_dive_site.latitude.udeg && + ds->longitude.udeg == displayed_dive_site.longitude.udeg) { + bottomText += tr(" (same GPS fix)"); + } else { + int distanceMeters = get_distance(ds->latitude, ds->longitude, displayed_dive_site.latitude, displayed_dive_site.longitude); + QString distance = distance_string(distanceMeters); + bottomText += tr(" (~ %1 away)").arg(distance); + } + } fontBigger.setPointSize(fontBigger.pointSize() + 1); fontBigger.setBold(true); diff --git a/qthelper.cpp b/qthelper.cpp index 1d215c62b..1af352742 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -55,6 +55,24 @@ QString weight_string(int weight_in_grams) return (str); } +QString distance_string(int distanceInMeters) +{ + QString str; + if(get_units()->length == units::METERS) { + if (distanceInMeters >= 1000) + str = QString(translate("gettextFromC", "%1km")).arg(distanceInMeters / 1000); + else + str = QString(translate("gettextFromC", "%1m")).arg(distanceInMeters); + } else { + double miles = m_to_mile(distanceInMeters); + if (miles >= 1.0) + str = QString(translate("gettextFromC", "%1mi")).arg((int)miles); + else + str = QString(translate("gettextFromC", "%1yd")).arg((int)(miles * 1760)); + } + return str; +} + extern "C" const char *printGPSCoords(int lat, int lon) { unsigned int latdeg, londeg; diff --git a/qthelper.h b/qthelper.h index 418c2eb31..0f112ff70 100644 --- a/qthelper.h +++ b/qthelper.h @@ -13,6 +13,7 @@ extern QTranslator *qtTranslator, *ssrfTranslator; QString weight_string(int weight_in_grams); +QString distance_string(int distanceInMeters); bool gpsHasChanged(struct dive *dive, struct dive *master, const QString &gps_text, bool *parsed_out = 0); extern "C" const char *printGPSCoords(int lat, int lon); QList<int> getDivesInTrip(dive_trip_t *trip); @@ -149,6 +149,11 @@ static inline double mm_to_feet(int mm) return mm * 0.00328084; } +static inline double m_to_mile(int m) +{ + return m / 1609.344; +} + static inline unsigned long feet_to_mm(double feet) { return rint(feet * 304.8); |