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 | |
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>
-rw-r--r-- | desktop-widgets/locationinformation.cpp | 1 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/mapwidget.cpp | 11 | ||||
-rw-r--r-- | desktop-widgets/mapwidget.h | 1 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 4 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.h | 2 | ||||
-rw-r--r-- | map-widget/qmlmapwidgethelper.cpp | 52 | ||||
-rw-r--r-- | map-widget/qmlmapwidgethelper.h | 1 |
8 files changed, 41 insertions, 33 deletions
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index 1216bde89..73d4aeab1 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -360,7 +360,6 @@ bool DiveLocationFilterProxyModel::lessThan(const QModelIndex &source_left, cons return source_left.data().toString() < source_right.data().toString(); } - DiveLocationModel::DiveLocationModel(QObject*) { resetModel(); diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index a7e91732b..fdd73d943 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -229,7 +229,7 @@ MainWindow::MainWindow() : QMainWindow(), connect(DivePlannerPointsModel::instance(), SIGNAL(variationsComputed(QString)), this, SLOT(updateVariations(QString))); connect(plannerDetails->printPlan(), SIGNAL(pressed()), divePlannerWidget(), SLOT(printDecoPlan())); connect(this, SIGNAL(startDiveSiteEdit()), this, SLOT(on_actionDiveSiteEdit_triggered())); - connect(information(), SIGNAL(diveSiteChanged(struct dive_site *)), mapWidget, SLOT(centerOnDiveSite(struct dive_site *))); + connect(information(), &MainTab::diveSiteChanged, mapWidget, &MapWidget::centerOnSelectedDiveSite); connect(this, &MainWindow::showError, ui.mainErrorMessage, &NotificationWidget::showError, Qt::AutoConnection); connect(&windowTitleUpdate, &WindowTitleUpdate::updateTitle, this, &MainWindow::setAutomaticTitle); diff --git a/desktop-widgets/mapwidget.cpp b/desktop-widgets/mapwidget.cpp index 917b1b2c7..a940cdb39 100644 --- a/desktop-widgets/mapwidget.cpp +++ b/desktop-widgets/mapwidget.cpp @@ -50,6 +50,13 @@ void MapWidget::doneLoading(QQuickWidget::Status status) this, SLOT(coordinatesChangedLocal())); } +void MapWidget::centerOnSelectedDiveSite() +{ + CHECK_IS_READY_RETURN_VOID(); + if (!skipReload) + m_mapHelper->centerOnSelectedDiveSite(); +} + void MapWidget::centerOnDiveSite(struct dive_site *ds) { CHECK_IS_READY_RETURN_VOID(); @@ -60,9 +67,9 @@ void MapWidget::centerOnDiveSite(struct dive_site *ds) void MapWidget::centerOnIndex(const QModelIndex& idx) { CHECK_IS_READY_RETURN_VOID(); - struct dive_site *ds = get_dive_site_by_uuid(idx.model()->index(idx.row(), 0).data().toInt()); + struct dive_site *ds = get_dive_site_by_uuid(idx.model()->index(idx.row(), 0).data().toUInt()); if (!ds || !dive_site_has_gps_location(ds)) - centerOnDiveSite(&displayed_dive_site); + centerOnSelectedDiveSite(); else centerOnDiveSite(ds); } diff --git a/desktop-widgets/mapwidget.h b/desktop-widgets/mapwidget.h index 801913594..02b68483d 100644 --- a/desktop-widgets/mapwidget.h +++ b/desktop-widgets/mapwidget.h @@ -27,6 +27,7 @@ signals: void coordinatesChanged(); public slots: + void centerOnSelectedDiveSite(); void centerOnDiveSite(struct dive_site *); void centerOnIndex(const QModelIndex& idx); void endGetDiveCoordinates(); diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 070184a86..b6ac56ed7 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -643,7 +643,7 @@ void MainTab::updateDiveInfo(bool clear) if (verbose) qDebug() << "Set the current dive site:" << displayed_dive.dive_site_uuid; - emit diveSiteChanged(get_dive_site_by_uuid(displayed_dive.dive_site_uuid)); + emit diveSiteChanged(); } void MainTab::addCylinder_clicked() @@ -1384,7 +1384,7 @@ void MainTab::on_location_diveSiteSelected() if (ui.location->text().isEmpty()) { displayed_dive.dive_site_uuid = 0; markChangedWidget(ui.location); - emit diveSiteChanged(0); + emit diveSiteChanged(); return; } else { if (ui.location->currDiveSiteUuid() != displayed_dive.dive_site_uuid) { diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 31e3d14b0..238c060f8 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -59,7 +59,7 @@ public: signals: void addDiveFinished(); void dateTimeChanged(); - void diveSiteChanged(struct dive_site * ds); + void diveSiteChanged(); public slots: void addCylinder_clicked(); 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; 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(); |