summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/locationinformation.cpp22
-rw-r--r--desktop-widgets/locationinformation.h5
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp7
3 files changed, 26 insertions, 8 deletions
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp
index 825f440ba..a57c6fb30 100644
--- a/desktop-widgets/locationinformation.cpp
+++ b/desktop-widgets/locationinformation.cpp
@@ -252,7 +252,7 @@ void LocationInformationWidget::reverseGeocode()
Command::editDiveSiteTaxonomy(diveSite, taxonomy);
}
-DiveLocationFilterProxyModel::DiveLocationFilterProxyModel(QObject *)
+DiveLocationFilterProxyModel::DiveLocationFilterProxyModel(QObject *) : currentLocation({0, 0})
{
}
@@ -263,6 +263,12 @@ void DiveLocationFilterProxyModel::setFilter(const QString &filterIn)
sort(LocationInformationModel::NAME);
}
+void DiveLocationFilterProxyModel::setCurrentLocation(location_t loc)
+{
+ currentLocation = loc;
+ sort(LocationInformationModel::NAME);
+}
+
bool DiveLocationFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex&) const
{
// We don't want to show the first two entries (add dive site with that name)
@@ -282,6 +288,14 @@ bool DiveLocationFilterProxyModel::lessThan(const QModelIndex &source_left, cons
// The first two entries are special - we never want to change their order
if (source_left.row() <= 1 || source_right.row() <= 1)
return source_left.row() < source_right.row();
+
+ // If there is a current location, sort by that - otherwise use the provided column
+ if (has_location(&currentLocation)) {
+ // The dive sites are -2 because of the first two items.
+ struct dive_site *ds1 = get_dive_site(source_left.row() - 2, &dive_site_table);
+ struct dive_site *ds2 = get_dive_site(source_right.row() - 2, &dive_site_table);
+ return get_distance(&ds1->location, &currentLocation) < get_distance(&ds2->location, &currentLocation);
+ }
return source_left.data().toString().compare(source_right.data().toString(), Qt::CaseInsensitive) < 0;
}
@@ -543,8 +557,9 @@ void DiveLocationLineEdit::fixPopupPosition()
}
}
-void DiveLocationLineEdit::setCurrentDiveSite(struct dive_site *ds)
+void DiveLocationLineEdit::setCurrentDiveSite(struct dive *d)
{
+ struct dive_site *ds = get_dive_site_for_dive(d);
currDs = ds;
if (!currDs) {
currType = NO_DIVE_SITE;
@@ -552,6 +567,9 @@ void DiveLocationLineEdit::setCurrentDiveSite(struct dive_site *ds)
} else {
setText(ds->name);
}
+
+ location_t currentLocation = d ? dive_get_gps_location(d) : location_t{0, 0};
+ proxy->setCurrentLocation(currentLocation);
}
void DiveLocationLineEdit::showPopup()
diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h
index 434da29ae..f3f9f9eea 100644
--- a/desktop-widgets/locationinformation.h
+++ b/desktop-widgets/locationinformation.h
@@ -51,6 +51,9 @@ public:
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override;
void setFilter(const QString &filter);
+ void setCurrentLocation(location_t loc);
+private:
+ location_t currentLocation; // Sort by distance to that location
};
class DiveLocationModel : public QAbstractTableModel {
@@ -88,7 +91,7 @@ public:
DiveSiteType currDiveSiteType() const;
struct dive_site *currDiveSite() const;
void fixPopupPosition();
- void setCurrentDiveSite(struct dive_site *ds);
+ void setCurrentDiveSite(struct dive *d);
signals:
void diveSiteSelected();
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index 0638fbded..e70e79ce2 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -391,15 +391,14 @@ void MainTab::updateDateTime(struct dive *d)
void MainTab::updateDiveSite(struct dive *d)
{
struct dive_site *ds = d->dive_site;
+ ui.location->setCurrentDiveSite(d);
if (ds) {
- ui.location->setCurrentDiveSite(ds);
ui.locationTags->setText(constructLocationTags(&ds->taxonomy, true));
if (ui.locationTags->text().isEmpty() && has_location(&ds->location))
ui.locationTags->setText(printGPSCoords(&ds->location));
ui.editDiveSiteButton->setEnabled(true);
} else {
- ui.location->clear();
ui.locationTags->clear();
ui.editDiveSiteButton->setEnabled(false);
}
@@ -601,9 +600,7 @@ void MainTab::reload()
void MainTab::refreshDisplayedDiveSite()
{
- struct dive_site *ds = get_dive_site_for_dive(current_dive);
- if (ds)
- ui.location->setCurrentDiveSite(ds);
+ ui.location->setCurrentDiveSite(current_dive);
}
void MainTab::acceptChanges()