diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-04-25 09:35:46 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-05-11 12:35:11 -0700 |
commit | e76298a8a7fbbd3ccc252bf7c4a904db7c3423d6 (patch) | |
tree | ea2f1cbf3c008ed75f2a1f868a33818cbfe69842 | |
parent | c7e1c40b0e9ff1c9152f06b7f1c134f232297fe7 (diff) | |
download | subsurface-e76298a8a7fbbd3ccc252bf7c4a904db7c3423d6.tar.gz |
Dive site: show distance to current dive using extra data
Currently, in the dive-site selection widget the distance to
the dive site of the current dive is shown. Instead, use the
recently introduced dive_get_gps_location() function. Thus,
the actual GPS coordinates extracted by libdivecomputer are
used.
The function is only called when the current dive changes
and the location is stored in the item delegate.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | desktop-widgets/locationinformation.cpp | 3 | ||||
-rw-r--r-- | desktop-widgets/locationinformation.h | 2 | ||||
-rw-r--r-- | desktop-widgets/modeldelegates.cpp | 18 | ||||
-rw-r--r-- | desktop-widgets/modeldelegates.h | 5 |
4 files changed, 20 insertions, 8 deletions
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index a57c6fb30..5872089a4 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -371,7 +371,7 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) : QLineEdit(parent), view->setModel(proxy); view->setModelColumn(LocationInformationModel::NAME); - view->setItemDelegate(new LocationFilterDelegate()); + view->setItemDelegate(&delegate); view->setEditTriggers(QAbstractItemView::NoEditTriggers); view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setSelectionBehavior(QAbstractItemView::SelectRows); @@ -570,6 +570,7 @@ void DiveLocationLineEdit::setCurrentDiveSite(struct dive *d) location_t currentLocation = d ? dive_get_gps_location(d) : location_t{0, 0}; proxy->setCurrentLocation(currentLocation); + delegate.setCurrentLocation(currentLocation); } void DiveLocationLineEdit::showPopup() diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h index f3f9f9eea..0f7470af6 100644 --- a/desktop-widgets/locationinformation.h +++ b/desktop-widgets/locationinformation.h @@ -5,6 +5,7 @@ #include "core/units.h" #include "core/divesite.h" #include "ui_locationinformation.h" +#include "modeldelegates.h" #include "qt-models/divelocationmodel.h" #include <stdint.h> #include <QAbstractListModel> @@ -108,6 +109,7 @@ private: DiveLocationFilterProxyModel *proxy; DiveLocationModel *model; DiveLocationListView *view; + LocationFilterDelegate delegate; DiveSiteType currType; struct dive_site *currDs; }; diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index 3e9fd513f..770a828cd 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -441,10 +441,15 @@ QWidget *DoubleSpinBoxDelegate::createEditor(QWidget *parent, const QStyleOption return w; } -LocationFilterDelegate::LocationFilterDelegate(QObject*) +LocationFilterDelegate::LocationFilterDelegate(QObject *) : currentLocation({0, 0}) { } +void LocationFilterDelegate::setCurrentLocation(location_t loc) +{ + currentLocation = loc; +} + void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &origIdx) const { QFont fontBigger = qApp->font(); @@ -461,8 +466,7 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem QIcon icon = index.data(Qt::DecorationRole).value<QIcon>(); struct dive_site *ds = index.model()->data(index.model()->index(index.row(), LocationInformationModel::DIVESITE)).value<dive_site *>(); - struct dive_site *currentDiveSite = current_dive ? get_dive_site_for_dive(current_dive) : nullptr; - bool currentDiveSiteHasGPS = currentDiveSite && dive_site_has_gps_location(currentDiveSite); + bool currentDiveHasGPS = has_location(¤tLocation); //Special case: do not show name, but instead, show if (index.row() < 2) { diveSiteName = index.data().toString(); @@ -487,13 +491,13 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem if (bottomText.isEmpty()) bottomText = printGPSCoords(&ds->location); - if (dive_site_has_gps_location(ds) && currentDiveSiteHasGPS) { + if (dive_site_has_gps_location(ds) && currentDiveHasGPS) { // 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 (same_location(&ds->location, ¤tDiveSite->location)) { + if (same_location(&ds->location, ¤tLocation)) { bottomText += tr(" (same GPS fix)"); } else { - int distanceMeters = get_distance(&ds->location, ¤tDiveSite->location); + int distanceMeters = get_distance(&ds->location, ¤tLocation); QString distance = distance_string(distanceMeters); int nr = nr_of_dives_at_dive_site(ds); bottomText += tr(" (~%1 away").arg(distance); @@ -501,7 +505,7 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem } } if (bottomText.isEmpty()) { - if (currentDiveSiteHasGPS) + if (currentDiveHasGPS) bottomText = tr("(no existing GPS data, add GPS fix from this dive)"); else bottomText = tr("(no GPS data)"); diff --git a/desktop-widgets/modeldelegates.h b/desktop-widgets/modeldelegates.h index ae1292030..e2baa1582 100644 --- a/desktop-widgets/modeldelegates.h +++ b/desktop-widgets/modeldelegates.h @@ -2,6 +2,8 @@ #ifndef MODELDELEGATES_H #define MODELDELEGATES_H +#include "core/units.h" + #include <QStyledItemDelegate> #include <QComboBox> class QPainter; @@ -130,6 +132,9 @@ public: LocationFilterDelegate(QObject *parent = 0); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; + void setCurrentLocation(location_t loc); +private: + location_t currentLocation; }; #endif // MODELDELEGATES_H |