diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-07-27 23:55:35 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-07-28 07:31:11 -0700 |
commit | 4d698310ff830462b7d5fad7d449bedc45aa50cb (patch) | |
tree | 7fedc6ed7bf3df4647abce09b87382451f4c40ba /mobile-widgets/qmlmapwidgethelper.cpp | |
parent | 5e57e428748d8c9876dc607ba32bafafb33e797d (diff) | |
download | subsurface-4d698310ff830462b7d5fad7d449bedc45aa50cb.tar.gz |
mapwidgethelper: add methods for editing MapLocations
updateCurrentDiveSiteCoordinates() should be called from
QML when a marker changed it's location. it emits the coordinatesChanged()
signal, which should be tracked in the MapWidget class. The MapWidget
class should emit the same signal to the MainWindow (Marble does that).
editMode is now a boolean property, which should put the QML map into
editing mode.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'mobile-widgets/qmlmapwidgethelper.cpp')
-rw-r--r-- | mobile-widgets/qmlmapwidgethelper.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/mobile-widgets/qmlmapwidgethelper.cpp b/mobile-widgets/qmlmapwidgethelper.cpp index 81c92e708..22e8b28c6 100644 --- a/mobile-widgets/qmlmapwidgethelper.cpp +++ b/mobile-widgets/qmlmapwidgethelper.cpp @@ -78,7 +78,7 @@ void MapWidgetHelper::selectedLocationChanged(MapLocation *location) int idx;
struct dive *dive;
m_selectedDiveIds.clear();
- QGeoCoordinate locationCoord = qvariant_cast<QGeoCoordinate>(location->getRole(MapLocation::Roles::RoleCoordinate));
+ QGeoCoordinate locationCoord = location->coordinate();
for_each_dive (idx, dive) {
struct dive_site *ds = get_dive_site_for_dive(dive);
if (!dive_site_has_gps_location(ds))
@@ -129,3 +129,33 @@ void MapWidgetHelper::copyToClipboardCoordinates(QGeoCoordinate coord, bool form free((void *)coordinates);
prefs.coordinates_traditional = savep;
}
+
+void MapWidgetHelper::updateCurrentDiveSiteCoordinates(quint32 uuid, QGeoCoordinate coord)
+{
+ MapLocation *loc = m_mapLocationModel->getMapLocationForUuid(uuid);
+ if (loc)
+ loc->setCoordinate(coord);
+ displayed_dive_site.latitude.udeg = llrint(coord.latitude() * 1000000.0);
+ displayed_dive_site.longitude.udeg = llrint(coord.longitude() * 1000000.0);
+ emit coordinatesChanged();
+}
+
+bool MapWidgetHelper::editMode()
+{
+ return m_editMode;
+}
+
+void MapWidgetHelper::setEditMode(bool editMode)
+{
+ m_editMode = editMode;
+ MapLocation *exists = m_mapLocationModel->getMapLocationForUuid(displayed_dive_site.uuid);
+ // if divesite uuid doesn't exist in the model, add a new MapLocation.
+ if (editMode && !exists) {
+ QGeoCoordinate coord(0.0, 0.0);
+ m_mapLocationModel->add(new MapLocation(displayed_dive_site.uuid, coord,
+ QString(displayed_dive_site.name)));
+ QMetaObject::invokeMethod(m_map, "centerOnCoordinate",
+ Q_ARG(QVariant, QVariant::fromValue(coord)));
+ }
+ emit editModeChanged();
+}
|