diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-05-09 21:33:01 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-05-11 12:06:19 -0700 |
commit | 44c65fec8855315d322b84b4c4207713b90328d3 (patch) | |
tree | 21ba6e6901fa5e46cebca4e7abadc33292e24d05 | |
parent | 30d96d37043684a4087f09b7171b1873ec140236 (diff) | |
download | subsurface-44c65fec8855315d322b84b4c4207713b90328d3.tar.gz |
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>
-rw-r--r-- | desktop-widgets/mapwidget.cpp | 8 | ||||
-rw-r--r-- | desktop-widgets/mapwidget.h | 1 | ||||
-rw-r--r-- | map-widget/qmlmapwidgethelper.cpp | 12 | ||||
-rw-r--r-- | map-widget/qmlmapwidgethelper.h | 3 | ||||
-rw-r--r-- | qt-models/maplocationmodel.cpp | 39 | ||||
-rw-r--r-- | qt-models/maplocationmodel.h | 5 |
6 files changed, 38 insertions, 30 deletions
diff --git a/desktop-widgets/mapwidget.cpp b/desktop-widgets/mapwidget.cpp index b28dea830..113283fc6 100644 --- a/desktop-widgets/mapwidget.cpp +++ b/desktop-widgets/mapwidget.cpp @@ -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) diff --git a/desktop-widgets/mapwidget.h b/desktop-widgets/mapwidget.h index 430dd1668..67801207a 100644 --- a/desktop-widgets/mapwidget.h +++ b/desktop-widgets/mapwidget.h @@ -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: diff --git a/map-widget/qmlmapwidgethelper.cpp b/map-widget/qmlmapwidgethelper.cpp index ccc5a6e7a..7d752cc63 100644 --- a/map-widget/qmlmapwidgethelper.cpp +++ b/map-widget/qmlmapwidgethelper.cpp @@ -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() diff --git a/map-widget/qmlmapwidgethelper.h b/map-widget/qmlmapwidgethelper.h index d6348c346..86d9a8ff5 100644 --- a/map-widget/qmlmapwidgethelper.h +++ b/map-widget/qmlmapwidgethelper.h @@ -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(); diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp index 295f514eb..b1fe16b60 100644 --- a/qt-models/maplocationmodel.cpp +++ b/qt-models/maplocationmodel.cpp @@ -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; + // Find dive site + int row; + for (row = 0; row < m_mapLocations.size(); ++row) { + if (m_mapLocations[row]->divesite() == ds) + break; + } + 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); } - row++; + break; + case LocationInformationModel::NAME: + m_mapLocations[row]->setProperty("name", ds->name); + break; + default: + 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); + + + emit dataChanged(createIndex(row, 0), createIndex(row, 0)); } diff --git a/qt-models/maplocationmodel.h b/qt-models/maplocationmodel.h index 404c76d4a..b33d2d65d 100644 --- a/qt-models/maplocationmodel.h +++ b/qt-models/maplocationmodel.h @@ -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; |