diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-10-08 21:16:40 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-08 13:29:51 -0700 |
commit | 0aef04352a3210a6024f860758af466ea774dd5e (patch) | |
tree | 8758b8080f172bb010f249950c3ebc7e225f8819 /map-widget/qmlmapwidgethelper.cpp | |
parent | 1c8b73b36f528bf8d2765a1c064980b1e2022650 (diff) | |
download | subsurface-0aef04352a3210a6024f860758af466ea774dd5e.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'map-widget/qmlmapwidgethelper.cpp')
-rw-r--r-- | map-widget/qmlmapwidgethelper.cpp | 52 |
1 files changed, 26 insertions, 26 deletions
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 @@ -41,53 +41,53 @@ 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<struct dive_site *> selDS; QVector<QGeoCoordinate> 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; |