summaryrefslogtreecommitdiffstats
path: root/qthelper.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-14 11:35:04 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-14 11:52:17 -0700
commit8c0d0de2e62356e1bbdad97843d185a37973c5c7 (patch)
tree0179eee9ba82a843f676551e61b9886930c9ceab /qthelper.cpp
parente82f8ea565a68aa1fa980cb12c1f136b1d4a57f9 (diff)
downloadsubsurface-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>
Diffstat (limited to 'qthelper.cpp')
-rw-r--r--qthelper.cpp18
1 files changed, 18 insertions, 0 deletions
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;