aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/maplocationmodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-05-09 21:33:01 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-05-11 12:06:19 -0700
commit44c65fec8855315d322b84b4c4207713b90328d3 (patch)
tree21ba6e6901fa5e46cebca4e7abadc33292e24d05 /qt-models/maplocationmodel.cpp
parent30d96d37043684a4087f09b7171b1873ec140236 (diff)
downloadsubsurface-44c65fec8855315d322b84b4c4207713b90328d3.tar.gz
Map: automatically update names on the map
Currently, dive site names are only updated on full reload. Instead hook directly into the corresponding signal in the MapLocationModel to set the name. Also to the coordinates directly there instead of going via the MapWidgetHelper. In the MapWidgetHelper, just center on the changed dive site. Hook into the signal directly there and remove the slot from the MapWidget. This makes the whole call-chain at least one call shorter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/maplocationmodel.cpp')
-rw-r--r--qt-models/maplocationmodel.cpp39
1 files changed, 28 insertions, 11 deletions
diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp
index 295f514eb..b1fe16b60 100644
--- a/qt-models/maplocationmodel.cpp
+++ b/qt-models/maplocationmodel.cpp
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include "maplocationmodel.h"
+#include "divelocationmodel.h"
#include "core/divesite.h"
#ifndef SUBSURFACE_MOBILE
#include "qt-models/filtermodels.h"
@@ -68,6 +69,7 @@ MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent)
m_roles[MapLocation::Roles::RoleDivesite] = MapLocation::PROPERTY_NAME_DIVESITE;
m_roles[MapLocation::Roles::RoleCoordinate] = MapLocation::PROPERTY_NAME_COORDINATE;
m_roles[MapLocation::Roles::RoleName] = MapLocation::PROPERTY_NAME_NAME;
+ connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MapLocationModel::diveSiteChanged);
}
MapLocationModel::~MapLocationModel()
@@ -215,18 +217,33 @@ MapLocation *MapLocationModel::getMapLocation(const struct dive_site *ds)
return NULL;
}
-void MapLocationModel::updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord)
+void MapLocationModel::diveSiteChanged(struct dive_site *ds, int field)
{
- MapLocation *location;
- int row = 0;
- foreach(location, m_mapLocations) {
- if (ds == location->divesite()) {
- location->setCoordinateNoEmit(coord);
- emit dataChanged(createIndex(row, 0), createIndex(row, 0));
- return;
+ // Find dive site
+ int row;
+ for (row = 0; row < m_mapLocations.size(); ++row) {
+ if (m_mapLocations[row]->divesite() == ds)
+ break;
+ }
+ if (row == m_mapLocations.size())
+ return;
+
+ switch (field) {
+ case LocationInformationModel::LOCATION:
+ if (has_location(&ds->location)) {
+ const qreal latitude_r = ds->location.lat.udeg * 0.000001;
+ const qreal longitude_r = ds->location.lon.udeg * 0.000001;
+ QGeoCoordinate coord(latitude_r, longitude_r);
+ m_mapLocations[row]->setCoordinateNoEmit(coord);
}
- row++;
+ break;
+ case LocationInformationModel::NAME:
+ m_mapLocations[row]->setProperty("name", ds->name);
+ break;
+ default:
+ break;
}
- // should not happen, as this should be called only when editing an existing marker
- qWarning() << "MapLocationModel::updateMapLocationCoordinates(): cannot find MapLocation for uuid:" << (ds ? ds->uuid : 0);
+
+
+ emit dataChanged(createIndex(row, 0), createIndex(row, 0));
}