summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-05-09 21:33:01 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-05-11 12:06:19 -0700
commit44c65fec8855315d322b84b4c4207713b90328d3 (patch)
tree21ba6e6901fa5e46cebca4e7abadc33292e24d05 /qt-models
parent30d96d37043684a4087f09b7171b1873ec140236 (diff)
downloadsubsurface-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>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/maplocationmodel.cpp39
-rw-r--r--qt-models/maplocationmodel.h5
2 files changed, 32 insertions, 12 deletions
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;