From 0aef04352a3210a6024f860758af466ea774dd5e Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 8 Oct 2018 21:16:40 +0200 Subject: Map: zoom on dive sites when flipping through dive site list The dive site list was connected to centerOnDiveSite(). Apparently, the currently selected dive site should have been shown in the map. Yet, this never worked, because the actual dive site of the selected dive had precedence in centerOnDiveSite(). It seems that centerOnDiveSite() had actually to purposes: 1) center on the passed in dive site 2) center on the dive sites of the selected dives Therefore, split this function in two separate functions for each of these use-cases. This allows us to remove some pre-processor magic (mobile vs. desktop) and to remove a parameter from the MainTab::diveSiteChanged() signal. Signed-off-by: Berthold Stoeger --- map-widget/qmlmapwidgethelper.cpp | 52 +++++++++++++++++++-------------------- map-widget/qmlmapwidgethelper.h | 1 + 2 files changed, 27 insertions(+), 26 deletions(-) (limited to 'map-widget') diff --git a/map-widget/qmlmapwidgethelper.cpp b/map-widget/qmlmapwidgethelper.cpp index 0b1f7cb2a..b5fd916cd 100644 --- a/map-widget/qmlmapwidgethelper.cpp +++ b/map-widget/qmlmapwidgethelper.cpp @@ -40,54 +40,54 @@ void MapWidgetHelper::centerOnDiveSiteUUID(QVariant dive_site_uuid) } void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds) +{ + if (!ds || !dive_site_has_gps_location(ds)) { + // dive site with no GPS + m_mapLocationModel->setSelectedUuid(ds ? ds->uuid : 0, false); + QMetaObject::invokeMethod(m_map, "deselectMapLocation"); + } else { + // dive site with GPS + m_mapLocationModel->setSelectedUuid(ds->uuid, false); + QGeoCoordinate dsCoord (ds->latitude.udeg * 0.000001, ds->longitude.udeg * 0.000001); + QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord))); + } +} + +void MapWidgetHelper::centerOnSelectedDiveSite() { QVector selDS; QVector selGC; - QGeoCoordinate dsCoord; -// selection of multiple dives is only possible on the desktop. -// in the case of the mobile version only handle the passed dive_site. -#ifndef SUBSURFACE_MOBILE int idx; struct dive *dive; for_each_dive (idx, dive) { + if (!dive->selected) + continue; struct dive_site *dss = get_dive_site_for_dive(dive); - if (!dive_site_has_gps_location(dss) || !dive->selected) + if (!dive_site_has_gps_location(dss)) continue; // only store dive sites with GPS selDS.append(dss); selGC.append(QGeoCoordinate(dss->latitude.udeg * 0.000001, dss->longitude.udeg * 0.000001)); } -#else - if (dive_site_has_gps_location(ds)) { - selDS.append(ds); - selGC.append(QGeoCoordinate(ds->latitude.udeg * 0.000001, - ds->longitude.udeg * 0.000001)); - } -#endif - if (!dive_site_has_gps_location(ds) && !selDS.size()) { - // only a single dive site with no GPS selected - m_mapLocationModel->setSelectedUuid(ds ? ds->uuid : 0, false); + + if (selDS.isEmpty()) { + // no selected dives with GPS coordinates + m_mapLocationModel->setSelectedUuid(0, false); QMetaObject::invokeMethod(m_map, "deselectMapLocation"); } else if (selDS.size() == 1) { - // a single dive site with GPS selected - ds = selDS.at(0); - m_mapLocationModel->setSelectedUuid(ds->uuid, false); - dsCoord.setLatitude(ds->latitude.udeg * 0.000001); - dsCoord.setLongitude(ds->longitude.udeg * 0.000001); - QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord))); + centerOnDiveSite(selDS[0]); } else if (selDS.size() > 1) { /* more than one dive sites with GPS selected. * find the most top-left and bottom-right dive sites on the map coordinate system. */ - ds = selDS.at(0); - m_mapLocationModel->setSelectedUuid(ds->uuid, false); + m_mapLocationModel->setSelectedUuid(selDS[0]->uuid, false); qreal minLat = 0.0, minLon = 0.0, maxLat = 0.0, maxLon = 0.0; bool start = true; - foreach(QGeoCoordinate gc, selGC) { - qreal lat = gc.latitude(); - qreal lon = gc.longitude(); + for(struct dive_site *dss: selDS) { + qreal lat = dss->latitude.udeg * 0.000001; + qreal lon = dss->longitude.udeg * 0.000001; if (start) { minLat = maxLat = lat; minLon = maxLon = lon; diff --git a/map-widget/qmlmapwidgethelper.h b/map-widget/qmlmapwidgethelper.h index 7b218e9a9..e5c77aa8a 100644 --- a/map-widget/qmlmapwidgethelper.h +++ b/map-widget/qmlmapwidgethelper.h @@ -27,6 +27,7 @@ public: explicit MapWidgetHelper(QObject *parent = NULL); void centerOnDiveSite(struct dive_site *); + void centerOnSelectedDiveSite(); Q_INVOKABLE QGeoCoordinate getCoordinatesForUUID(QVariant dive_site_uuid); Q_INVOKABLE void centerOnDiveSiteUUID(QVariant dive_site_uuid); Q_INVOKABLE void reloadMapLocations(); -- cgit v1.2.3-70-g09d2