aboutsummaryrefslogtreecommitdiffstats
path: root/map-widget
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-05-08 22:26:28 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-05-11 12:06:19 -0700
commit30d96d37043684a4087f09b7171b1873ec140236 (patch)
tree03d477271e651cbeeda242ae1d57c0573376c28a /map-widget
parent0da86dfd8601edd33c47c787d42e4a687fff8aaf (diff)
downloadsubsurface-30d96d37043684a4087f09b7171b1873ec140236.tar.gz
Map: ignore dive sites without location in centerOnSelectedDiveSite()
Don't zoom onto (0,0) for selected dive sites that have no location. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'map-widget')
-rw-r--r--map-widget/qmlmapwidgethelper.cpp62
1 files changed, 33 insertions, 29 deletions
diff --git a/map-widget/qmlmapwidgethelper.cpp b/map-widget/qmlmapwidgethelper.cpp
index 9aba7f27a..ccc5a6e7a 100644
--- a/map-widget/qmlmapwidgethelper.cpp
+++ b/map-widget/qmlmapwidgethelper.cpp
@@ -48,45 +48,49 @@ void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds)
void MapWidgetHelper::centerOnSelectedDiveSite()
{
QVector<struct dive_site *> selDS = m_mapLocationModel->selectedDs();
- QVector<QGeoCoordinate> selGC;
if (selDS.isEmpty()) {
// no selected dives with GPS coordinates
QMetaObject::invokeMethod(m_map, "deselectMapLocation");
- } else if (selDS.size() == 1) {
+ return;
+ }
+
+ // find the most top-left and bottom-right dive sites on the map coordinate system.
+ qreal minLat = 0.0, minLon = 0.0, maxLat = 0.0, maxLon = 0.0;
+ int count = 0;
+ for(struct dive_site *dss: selDS) {
+ if (!has_location(&dss->location))
+ continue;
+ qreal lat = dss->location.lat.udeg * 0.000001;
+ qreal lon = dss->location.lon.udeg * 0.000001;
+ if (++count == 1) {
+ minLat = maxLat = lat;
+ minLon = maxLon = lon;
+ continue;
+ }
+ if (lat < minLat)
+ minLat = lat;
+ else if (lat > maxLat)
+ maxLat = lat;
+ if (lon < minLon)
+ minLon = lon;
+ else if (lon > maxLon)
+ maxLon = lon;
+ }
+
+ // Pass coordinates to QML, either as a point or as a rectangle.
+ // If we didn't find any coordinates, do nothing.
+ if (count == 1) {
QGeoCoordinate dsCoord (selDS[0]->location.lat.udeg * 0.000001, selDS[0]->location.lon.udeg * 0.000001);
QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord)));
- } else {
- /* more than one dive sites with GPS selected.
- * find the most top-left and bottom-right dive sites on the map coordinate system. */
- qreal minLat = 0.0, minLon = 0.0, maxLat = 0.0, maxLon = 0.0;
- bool start = true;
- for(struct dive_site *dss: selDS) {
- qreal lat = dss->location.lat.udeg * 0.000001;
- qreal lon = dss->location.lon.udeg * 0.000001;
- if (start) {
- minLat = maxLat = lat;
- minLon = maxLon = lon;
- start = false;
- continue;
- }
- if (lat < minLat)
- minLat = lat;
- else if (lat > maxLat)
- maxLat = lat;
- if (lon < minLon)
- minLon = lon;
- else if (lon > maxLon)
- maxLon = lon;
- }
- // pass rectangle coordinates to QML
+ } else if (count > 1) {
QGeoCoordinate coordTopLeft(minLat, minLon);
QGeoCoordinate coordBottomRight(maxLat, maxLon);
QGeoCoordinate coordCenter(minLat + (maxLat - minLat) * 0.5, minLon + (maxLon - minLon) * 0.5);
QMetaObject::invokeMethod(m_map, "centerOnRectangle",
- Q_ARG(QVariant, QVariant::fromValue(coordTopLeft)),
- Q_ARG(QVariant, QVariant::fromValue(coordBottomRight)),
- Q_ARG(QVariant, QVariant::fromValue(coordCenter)));
+ Q_ARG(QVariant, QVariant::fromValue(coordTopLeft)),
+ Q_ARG(QVariant, QVariant::fromValue(coordBottomRight)),
+ Q_ARG(QVariant, QVariant::fromValue(coordCenter)));
}
}