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>
This commit is contained in:
Berthold Stoeger 2018-10-08 21:16:40 +02:00 committed by Dirk Hohndel
parent 1c8b73b36f
commit 0aef04352a
8 changed files with 41 additions and 33 deletions

View file

@ -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();

View file

@ -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);

View file

@ -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);
}

View file

@ -27,6 +27,7 @@ signals:
void coordinatesChanged();
public slots:
void centerOnSelectedDiveSite();
void centerOnDiveSite(struct dive_site *);
void centerOnIndex(const QModelIndex& idx);
void endGetDiveCoordinates();

View file

@ -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) {

View file

@ -59,7 +59,7 @@ public:
signals:
void addDiveFinished();
void dateTimeChanged();
void diveSiteChanged(struct dive_site * ds);
void diveSiteChanged();
public
slots:
void addCylinder_clicked();

View file

@ -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<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;

View file

@ -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();