mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 18:43:24 +00:00
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>
This commit is contained in:
parent
30d96d3704
commit
44c65fec88
6 changed files with 39 additions and 31 deletions
|
@ -28,7 +28,6 @@ MapWidget::MapWidget(QWidget *parent) : QQuickWidget(parent)
|
|||
m_mapHelper = nullptr;
|
||||
setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
connect(this, &QQuickWidget::statusChanged, this, &MapWidget::doneLoading);
|
||||
connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MapWidget::diveSiteChanged);
|
||||
connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &MapWidget::divesChanged);
|
||||
setSource(urlMapWidget);
|
||||
}
|
||||
|
@ -91,13 +90,6 @@ void MapWidget::coordinatesChanged(struct dive_site *ds, const location_t &locat
|
|||
Command::editDiveSiteLocation(ds, location);
|
||||
}
|
||||
|
||||
void MapWidget::diveSiteChanged(struct dive_site *ds, int field)
|
||||
{
|
||||
CHECK_IS_READY_RETURN_VOID();
|
||||
if (field == LocationInformationModel::LOCATION)
|
||||
m_mapHelper->updateDiveSiteCoordinates(ds, ds->location);
|
||||
}
|
||||
|
||||
void MapWidget::divesChanged(dive_trip *, const QVector<dive *> &, DiveField field)
|
||||
{
|
||||
if (field == DiveField::DIVESITE)
|
||||
|
|
|
@ -31,7 +31,6 @@ public slots:
|
|||
void selectedDivesChanged(const QList<int> &);
|
||||
void coordinatesChanged(struct dive_site *ds, const location_t &);
|
||||
void doneLoading(QQuickWidget::Status status);
|
||||
void diveSiteChanged(struct dive_site *ds, int field);
|
||||
void divesChanged(dive_trip *, const QVector<dive *> &, DiveField field);
|
||||
|
||||
private:
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "core/divesite.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "qt-models/maplocationmodel.h"
|
||||
#include "qt-models/divelocationmodel.h"
|
||||
#ifndef SUBSURFACE_MOBILE
|
||||
#include "qt-models/filtermodels.h"
|
||||
#endif
|
||||
|
@ -22,6 +23,7 @@ MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
|
|||
m_editMode = false;
|
||||
connect(m_mapLocationModel, SIGNAL(selectedLocationChanged(MapLocation *)),
|
||||
this, SLOT(selectedLocationChanged(MapLocation *)));
|
||||
connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MapWidgetHelper::diveSiteChanged);
|
||||
}
|
||||
|
||||
QGeoCoordinate MapWidgetHelper::getCoordinates(struct dive_site *ds)
|
||||
|
@ -218,15 +220,9 @@ void MapWidgetHelper::updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *
|
|||
emit coordinatesChanged(ds, location);
|
||||
}
|
||||
|
||||
void MapWidgetHelper::updateDiveSiteCoordinates(struct dive_site *ds, const location_t &location)
|
||||
void MapWidgetHelper::diveSiteChanged(struct dive_site *ds, int field)
|
||||
{
|
||||
if (!ds)
|
||||
return;
|
||||
const qreal latitude_r = location.lat.udeg * 0.000001;
|
||||
const qreal longitude_r = location.lon.udeg * 0.000001;
|
||||
QGeoCoordinate coord(latitude_r, longitude_r);
|
||||
m_mapLocationModel->updateMapLocationCoordinates(ds, coord);
|
||||
QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(coord)));
|
||||
centerOnDiveSite(ds);
|
||||
}
|
||||
|
||||
void MapWidgetHelper::exitEditMode()
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#define QMLMAPWIDGETHELPER_H
|
||||
|
||||
#include "core/units.h"
|
||||
#include "core/subsurface-qt/DiveListNotifier.h"
|
||||
#include <QObject>
|
||||
#include <QGeoCoordinate>
|
||||
|
||||
|
@ -34,7 +35,6 @@ public:
|
|||
Q_INVOKABLE void calculateSmallCircleRadius(QGeoCoordinate coord);
|
||||
Q_INVOKABLE void updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *ds, QGeoCoordinate coord);
|
||||
Q_INVOKABLE void selectVisibleLocations();
|
||||
void updateDiveSiteCoordinates(struct dive_site *ds, const location_t &);
|
||||
QString pluginObject();
|
||||
|
||||
private:
|
||||
|
@ -47,6 +47,7 @@ private:
|
|||
|
||||
private slots:
|
||||
void selectedLocationChanged(MapLocation *);
|
||||
void diveSiteChanged(struct dive_site *ds, int field);
|
||||
|
||||
signals:
|
||||
void modelChanged();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
row++;
|
||||
// Find dive site
|
||||
int row;
|
||||
for (row = 0; row < m_mapLocations.size(); ++row) {
|
||||
if (m_mapLocations[row]->divesite() == ds)
|
||||
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);
|
||||
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);
|
||||
}
|
||||
break;
|
||||
case LocationInformationModel::NAME:
|
||||
m_mapLocations[row]->setProperty("name", ds->name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
emit dataChanged(createIndex(row, 0), createIndex(row, 0));
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#ifndef MAPLOCATIONMODEL_H
|
||||
#define MAPLOCATIONMODEL_H
|
||||
|
||||
#include "core/subsurface-qt/DiveListNotifier.h"
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QHash>
|
||||
|
@ -64,7 +65,6 @@ public:
|
|||
void reload(QObject *map);
|
||||
MapLocation *getMapLocation(const struct dive_site *ds);
|
||||
const QVector<dive_site *> &selectedDs() const;
|
||||
void updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord);
|
||||
Q_INVOKABLE void setSelected(struct dive_site *ds, bool fromClick = true);
|
||||
// The dive site is passed as a QVariant, because a null-QVariant is not automatically
|
||||
// transformed into a null pointer and warning messages are spewed onto the console.
|
||||
|
@ -73,6 +73,9 @@ public:
|
|||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private slots:
|
||||
void diveSiteChanged(struct dive_site *ds, int field);
|
||||
|
||||
private:
|
||||
QVector<MapLocation *> m_mapLocations;
|
||||
QHash<int, QByteArray> m_roles;
|
||||
|
|
Loading…
Add table
Reference in a new issue