mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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>
This commit is contained in:
parent
e82f8ea565
commit
8c0d0de2e6
6 changed files with 38 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
18
qthelper.cpp
18
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;
|
||||
|
|
|
@ -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);
|
||||
|
|
5
units.h
5
units.h
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue