mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +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;
|
m_mapHelper = nullptr;
|
||||||
setResizeMode(QQuickWidget::SizeRootObjectToView);
|
setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||||
connect(this, &QQuickWidget::statusChanged, this, &MapWidget::doneLoading);
|
connect(this, &QQuickWidget::statusChanged, this, &MapWidget::doneLoading);
|
||||||
connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MapWidget::diveSiteChanged);
|
|
||||||
connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &MapWidget::divesChanged);
|
connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &MapWidget::divesChanged);
|
||||||
setSource(urlMapWidget);
|
setSource(urlMapWidget);
|
||||||
}
|
}
|
||||||
|
@ -91,13 +90,6 @@ void MapWidget::coordinatesChanged(struct dive_site *ds, const location_t &locat
|
||||||
Command::editDiveSiteLocation(ds, location);
|
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)
|
void MapWidget::divesChanged(dive_trip *, const QVector<dive *> &, DiveField field)
|
||||||
{
|
{
|
||||||
if (field == DiveField::DIVESITE)
|
if (field == DiveField::DIVESITE)
|
||||||
|
|
|
@ -31,7 +31,6 @@ public slots:
|
||||||
void selectedDivesChanged(const QList<int> &);
|
void selectedDivesChanged(const QList<int> &);
|
||||||
void coordinatesChanged(struct dive_site *ds, const location_t &);
|
void coordinatesChanged(struct dive_site *ds, const location_t &);
|
||||||
void doneLoading(QQuickWidget::Status status);
|
void doneLoading(QQuickWidget::Status status);
|
||||||
void diveSiteChanged(struct dive_site *ds, int field);
|
|
||||||
void divesChanged(dive_trip *, const QVector<dive *> &, DiveField field);
|
void divesChanged(dive_trip *, const QVector<dive *> &, DiveField field);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "core/divesite.h"
|
#include "core/divesite.h"
|
||||||
#include "core/qthelper.h"
|
#include "core/qthelper.h"
|
||||||
#include "qt-models/maplocationmodel.h"
|
#include "qt-models/maplocationmodel.h"
|
||||||
|
#include "qt-models/divelocationmodel.h"
|
||||||
#ifndef SUBSURFACE_MOBILE
|
#ifndef SUBSURFACE_MOBILE
|
||||||
#include "qt-models/filtermodels.h"
|
#include "qt-models/filtermodels.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,6 +23,7 @@ MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
|
||||||
m_editMode = false;
|
m_editMode = false;
|
||||||
connect(m_mapLocationModel, SIGNAL(selectedLocationChanged(MapLocation *)),
|
connect(m_mapLocationModel, SIGNAL(selectedLocationChanged(MapLocation *)),
|
||||||
this, SLOT(selectedLocationChanged(MapLocation *)));
|
this, SLOT(selectedLocationChanged(MapLocation *)));
|
||||||
|
connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MapWidgetHelper::diveSiteChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
QGeoCoordinate MapWidgetHelper::getCoordinates(struct dive_site *ds)
|
QGeoCoordinate MapWidgetHelper::getCoordinates(struct dive_site *ds)
|
||||||
|
@ -218,15 +220,9 @@ void MapWidgetHelper::updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *
|
||||||
emit coordinatesChanged(ds, location);
|
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)
|
centerOnDiveSite(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)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidgetHelper::exitEditMode()
|
void MapWidgetHelper::exitEditMode()
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#define QMLMAPWIDGETHELPER_H
|
#define QMLMAPWIDGETHELPER_H
|
||||||
|
|
||||||
#include "core/units.h"
|
#include "core/units.h"
|
||||||
|
#include "core/subsurface-qt/DiveListNotifier.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QGeoCoordinate>
|
#include <QGeoCoordinate>
|
||||||
|
|
||||||
|
@ -34,7 +35,6 @@ public:
|
||||||
Q_INVOKABLE void calculateSmallCircleRadius(QGeoCoordinate coord);
|
Q_INVOKABLE void calculateSmallCircleRadius(QGeoCoordinate coord);
|
||||||
Q_INVOKABLE void updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *ds, QGeoCoordinate coord);
|
Q_INVOKABLE void updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *ds, QGeoCoordinate coord);
|
||||||
Q_INVOKABLE void selectVisibleLocations();
|
Q_INVOKABLE void selectVisibleLocations();
|
||||||
void updateDiveSiteCoordinates(struct dive_site *ds, const location_t &);
|
|
||||||
QString pluginObject();
|
QString pluginObject();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -47,6 +47,7 @@ private:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void selectedLocationChanged(MapLocation *);
|
void selectedLocationChanged(MapLocation *);
|
||||||
|
void diveSiteChanged(struct dive_site *ds, int field);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void modelChanged();
|
void modelChanged();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include "maplocationmodel.h"
|
#include "maplocationmodel.h"
|
||||||
|
#include "divelocationmodel.h"
|
||||||
#include "core/divesite.h"
|
#include "core/divesite.h"
|
||||||
#ifndef SUBSURFACE_MOBILE
|
#ifndef SUBSURFACE_MOBILE
|
||||||
#include "qt-models/filtermodels.h"
|
#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::RoleDivesite] = MapLocation::PROPERTY_NAME_DIVESITE;
|
||||||
m_roles[MapLocation::Roles::RoleCoordinate] = MapLocation::PROPERTY_NAME_COORDINATE;
|
m_roles[MapLocation::Roles::RoleCoordinate] = MapLocation::PROPERTY_NAME_COORDINATE;
|
||||||
m_roles[MapLocation::Roles::RoleName] = MapLocation::PROPERTY_NAME_NAME;
|
m_roles[MapLocation::Roles::RoleName] = MapLocation::PROPERTY_NAME_NAME;
|
||||||
|
connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MapLocationModel::diveSiteChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapLocationModel::~MapLocationModel()
|
MapLocationModel::~MapLocationModel()
|
||||||
|
@ -215,18 +217,33 @@ MapLocation *MapLocationModel::getMapLocation(const struct dive_site *ds)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapLocationModel::updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord)
|
void MapLocationModel::diveSiteChanged(struct dive_site *ds, int field)
|
||||||
{
|
{
|
||||||
MapLocation *location;
|
// Find dive site
|
||||||
int row = 0;
|
int row;
|
||||||
foreach(location, m_mapLocations) {
|
for (row = 0; row < m_mapLocations.size(); ++row) {
|
||||||
if (ds == location->divesite()) {
|
if (m_mapLocations[row]->divesite() == ds)
|
||||||
location->setCoordinateNoEmit(coord);
|
break;
|
||||||
emit dataChanged(createIndex(row, 0), createIndex(row, 0));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
row++;
|
|
||||||
}
|
}
|
||||||
// should not happen, as this should be called only when editing an existing marker
|
if (row == m_mapLocations.size())
|
||||||
qWarning() << "MapLocationModel::updateMapLocationCoordinates(): cannot find MapLocation for uuid:" << (ds ? ds->uuid : 0);
|
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
|
#ifndef MAPLOCATIONMODEL_H
|
||||||
#define MAPLOCATIONMODEL_H
|
#define MAPLOCATIONMODEL_H
|
||||||
|
|
||||||
|
#include "core/subsurface-qt/DiveListNotifier.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
@ -64,7 +65,6 @@ public:
|
||||||
void reload(QObject *map);
|
void reload(QObject *map);
|
||||||
MapLocation *getMapLocation(const struct dive_site *ds);
|
MapLocation *getMapLocation(const struct dive_site *ds);
|
||||||
const QVector<dive_site *> &selectedDs() const;
|
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);
|
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
|
// 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.
|
// transformed into a null pointer and warning messages are spewed onto the console.
|
||||||
|
@ -73,6 +73,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void diveSiteChanged(struct dive_site *ds, int field);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<MapLocation *> m_mapLocations;
|
QVector<MapLocation *> m_mapLocations;
|
||||||
QHash<int, QByteArray> m_roles;
|
QHash<int, QByteArray> m_roles;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue