map-widget: allow real-time updates of edited markers

This patch allows updating the location of map markers
while editing a dive site and updating the text in the
LocationInformationWidget in real-time.

Currently it is only possible to see the marker changes by
clicking 'Apply'.

The modification required the following changes:
- add the MapWidget::updateCurrentDiveSiteCoordinatesToMap() slot
and call it each time the GPS text updates
- separate the updateCurrentDiveSiteCoordinates(FromMap/ToMap) logic
by having the FromMap/ToMap suffix to method names
- make MapWidgetHelper::updateCurrentDiveSiteCoordinatesToMap()
call a new MapLocationModel::updateMapLocationCoordinates()
method, which updates selected location coordinates and the model
- add MapLocation::setCoordinateNoEmit() that does not emit
a signal when updating a coordinate

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2017-11-09 18:43:21 +02:00 committed by Dirk Hohndel
parent 89ccdc3178
commit 746874a78e
8 changed files with 45 additions and 3 deletions

View file

@ -52,6 +52,8 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBo
this, &LocationInformationWidget::updateGpsCoordinates);
connect(this, &LocationInformationWidget::endEditDiveSite,
MapWidget::instance(), &MapWidget::repopulateLabels);
connect(this, &LocationInformationWidget::coordinatesChanged,
MapWidget::instance(), &MapWidget::updateCurrentDiveSiteCoordinatesToMap);
}
bool LocationInformationWidget::eventFilter(QObject *, QEvent *ev)

View file

@ -118,6 +118,12 @@ void MapWidget::coordinatesChangedLocal()
emit coordinatesChanged();
}
void MapWidget::updateCurrentDiveSiteCoordinatesToMap()
{
CHECK_IS_READY_RETURN_VOID();
m_mapHelper->updateCurrentDiveSiteCoordinatesToMap();
}
MapWidget::~MapWidget()
{
m_instance = NULL;

View file

@ -35,6 +35,7 @@ public slots:
void selectedDivesChanged(QList<int>);
void coordinatesChangedLocal();
void doneLoading(QQuickWidget::Status status);
void updateCurrentDiveSiteCoordinatesToMap();
private:
void setEditMode(bool editMode);

View file

@ -72,7 +72,7 @@ Item {
onDoubleClicked: map.doubleClickHandler(mapItem.coordinate)
onReleased: {
if (mapHelper.editMode && mapHelper.model.selectedUuid === model.uuid) {
mapHelper.updateCurrentDiveSiteCoordinates(mapHelper.model.selectedUuid, mapItem.coordinate)
mapHelper.updateCurrentDiveSiteCoordinatesFromMap(mapHelper.model.selectedUuid, mapItem.coordinate)
}
}
}

View file

@ -210,7 +210,7 @@ void MapWidgetHelper::copyToClipboardCoordinates(QGeoCoordinate coord, bool form
prefs.coordinates_traditional = savep;
}
void MapWidgetHelper::updateCurrentDiveSiteCoordinates(quint32 uuid, QGeoCoordinate coord)
void MapWidgetHelper::updateCurrentDiveSiteCoordinatesFromMap(quint32 uuid, QGeoCoordinate coord)
{
MapLocation *loc = m_mapLocationModel->getMapLocationForUuid(uuid);
if (loc)
@ -220,6 +220,14 @@ void MapWidgetHelper::updateCurrentDiveSiteCoordinates(quint32 uuid, QGeoCoordin
emit coordinatesChanged();
}
void MapWidgetHelper::updateCurrentDiveSiteCoordinatesToMap()
{
const qreal latitude = displayed_dive_site.latitude.udeg * 0.000001;
const qreal longitude = displayed_dive_site.longitude.udeg * 0.000001;
QGeoCoordinate coord(latitude, longitude);
m_mapLocationModel->updateMapLocationCoordinates(displayed_dive_site.uuid, coord);
}
bool MapWidgetHelper::editMode()
{
return m_editMode;

View file

@ -24,8 +24,9 @@ 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);
Q_INVOKABLE void updateCurrentDiveSiteCoordinatesFromMap(quint32 uuid, QGeoCoordinate coord);
Q_INVOKABLE void selectVisibleLocations();
void updateCurrentDiveSiteCoordinatesToMap();
bool editMode();
void setEditMode(bool editMode);
QString pluginObject();

View file

@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
#include <QDebug>
#include "maplocationmodel.h"
const char *MapLocation::PROPERTY_NAME_COORDINATE = "coordinate";
@ -39,6 +40,11 @@ void MapLocation::setCoordinate(QGeoCoordinate coord)
emit coordinateChanged();
}
void MapLocation::setCoordinateNoEmit(QGeoCoordinate coord)
{
m_coordinate = coord;
}
quint32 MapLocation::uuid()
{
return m_uuid;
@ -136,3 +142,19 @@ MapLocation *MapLocationModel::getMapLocationForUuid(quint32 uuid)
}
return NULL;
}
void MapLocationModel::updateMapLocationCoordinates(quint32 uuid, QGeoCoordinate coord)
{
MapLocation *location;
int row = 0;
foreach(location, m_mapLocations) {
if (uuid == location->uuid()) {
location->setCoordinateNoEmit(coord);
emit dataChanged(createIndex(0, row), createIndex(0, row));
return;
}
row++;
}
// should not happen, as this should be called only when editing an existing marker
qWarning() << "MapLocationModel::updateMapLocationCoordinates(): cannot find MapLocation for uuid:" << uuid;
}

View file

@ -27,6 +27,7 @@ public:
QVariant getRole(int role) const;
QGeoCoordinate coordinate();
void setCoordinate(QGeoCoordinate coord);
void setCoordinateNoEmit(QGeoCoordinate coord);
quint32 uuid();
enum Roles {
@ -62,6 +63,7 @@ public:
void addList(QVector<MapLocation *>);
void clear();
MapLocation *getMapLocationForUuid(quint32 uuid);
void updateMapLocationCoordinates(quint32 uuid, QGeoCoordinate coord);
Q_INVOKABLE void setSelectedUuid(QVariant uuid, QVariant fromClick = true);
quint32 selectedUuid();