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(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(); +} diff --git a/mobile-widgets/qmlmapwidgethelper.h b/mobile-widgets/qmlmapwidgethelper.h index 91e95f4f9..3c6f6a1c8 100644 --- a/mobile-widgets/qmlmapwidgethelper.h +++ b/mobile-widgets/qmlmapwidgethelper.h @@ -14,6 +14,7 @@ class MapWidgetHelper : public QObject { Q_OBJECT Q_PROPERTY(QObject *map MEMBER m_map) Q_PROPERTY(MapLocationModel *model MEMBER m_mapLocationModel NOTIFY modelChanged) + Q_PROPERTY(bool editMode READ editMode WRITE setEditMode NOTIFY editModeChanged) public: explicit MapWidgetHelper(QObject *parent = NULL); @@ -22,19 +23,25 @@ public: void reloadMapLocations(); Q_INVOKABLE void copyToClipboardCoordinates(QGeoCoordinate coord, bool formatTraditional); Q_INVOKABLE void calculateSmallCircleRadius(QGeoCoordinate coord); + Q_INVOKABLE void updateCurrentDiveSiteCoordinates(quint32 uuid, QGeoCoordinate coord); + bool editMode(); + void setEditMode(bool editMode); private: QObject *m_map; MapLocationModel *m_mapLocationModel; qreal m_smallCircleRadius; QList m_selectedDiveIds; + bool m_editMode; private slots: void selectedLocationChanged(MapLocation *); signals: void modelChanged(); + void editModeChanged(); void selectedDivesChanged(QList list); + void coordinatesChanged(); }; extern "C" const char *printGPSCoords(int lat, int lon);