aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--divesite.c2
-rw-r--r--divesite.h2
-rw-r--r--qt-ui/modeldelegates.cpp36
-rw-r--r--qthelper.cpp18
-rw-r--r--qthelper.h1
-rw-r--r--units.h5
6 files changed, 58 insertions, 6 deletions
diff --git a/divesite.c b/divesite.c
index 800ccc9bd..b72672177 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 8801ddce9..fd590eb2c 100644
--- a/divesite.h
+++ b/divesite.h
@@ -59,7 +59,9 @@ 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);
uint32_t find_or_create_dive_site_with_name(const char *name);
+
#ifdef __cplusplus
}
#endif
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 953c16b87..8e296d412 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -11,6 +11,9 @@
#include "weightmodel.h"
#include "divetripmodel.h"
#include "qthelper.h"
+#ifndef NO_MARBLE
+#include "globe.h"
+#endif
#include <QCompleter>
#include <QKeyEvent>
@@ -511,12 +514,15 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
if (!ds)
return;
- for (int i = 0; i < ds->taxonomy.nr; i++) {
- if(ds->taxonomy.category[i].category == TC_NONE)
+ for (int i = 0; i < 3; i++) {
+ if (prefs.geocoding.category[i] == TC_NONE)
+ continue;
+ int idx = taxonomy_index_for_category(&ds->taxonomy, prefs.geocoding.category[i]);
+ if (idx == -1)
continue;
if(!bottomText.isEmpty())
- bottomText += " ";
- bottomText += QString(ds->taxonomy.category[i].value) + " ";
+ bottomText += " / ";
+ bottomText += QString(ds->taxonomy.category[idx].value);
}
if (bottomText.isEmpty()) {
@@ -525,7 +531,27 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
free( (void*) gpsCoords);
}
- print_part:
+#ifndef NO_MARBLE
+ if ((option.state & QStyle::State_HasFocus) && dive_site_has_gps_location(ds)) {
+ qDebug() << "center on" << ds->name;
+ MainWindow::instance()->globe()->centerOnDiveSite(ds->uuid);
+ }
+#endif
+
+ 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);
+ }
+ }
+print_part:
+
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);
diff --git a/units.h b/units.h
index 0baf2ffa5..1273bd9bb 100644
--- a/units.h
+++ b/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);