map-widget: start dive site editing with coords pre-entered

Once the user starts editing a dive site, make sure to pass
coordinates of either the current map center (if a new MapLocation
is being added) or the coordinates of the existing MapLocation.

The "Dive site management" coordinates text field would receive
these new coordinates after the displayed_dive_site struct
is updated and the coordinatesChanged() signal is emitted.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2017-11-25 23:06:26 +02:00
parent d9cfcae88b
commit b564debe21

View file

@ -238,11 +238,19 @@ 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 = m_map->property("center").value<QGeoCoordinate>();
m_mapLocationModel->add(new MapLocation(displayed_dive_site.uuid, coord,
QString(displayed_dive_site.name)));
if (editMode) {
QGeoCoordinate coord;
// if divesite uuid doesn't exist in the model, add a new MapLocation.
if (!exists) {
coord = m_map->property("center").value<QGeoCoordinate>();
m_mapLocationModel->add(new MapLocation(displayed_dive_site.uuid, coord,
QString(displayed_dive_site.name)));
} else {
coord = exists->coordinate();
}
displayed_dive_site.latitude.udeg = lrint(coord.latitude() * 1000000.0);
displayed_dive_site.longitude.udeg = lrint(coord.longitude() * 1000000.0);
emit coordinatesChanged();
}
emit editModeChanged();
}