summaryrefslogtreecommitdiffstats
path: root/qt-models/maplocationmodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-26 17:03:54 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-29 00:09:31 +0000
commit724055f0af4fb7cdb9f1570967fe4b34797f3419 (patch)
tree6aab8c34e7d0a6df1d6fe84bc5794e8eb5404b7d /qt-models/maplocationmodel.cpp
parentacd44467c1100a1a774cc644921b1dc33dca1266 (diff)
downloadsubsurface-724055f0af4fb7cdb9f1570967fe4b34797f3419.tar.gz
Dive site: replace dive->dive_site_uuid by dive_site
Replace the UUID reference of struct dive by a pointer to dive_site. This commit is rather large in lines, but nevertheless quite simple since most of the UUID->pointer work was done in previous commits. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/maplocationmodel.cpp')
-rw-r--r--qt-models/maplocationmodel.cpp67
1 files changed, 43 insertions, 24 deletions
diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp
index 45759a57f..ab34a7b16 100644
--- a/qt-models/maplocationmodel.cpp
+++ b/qt-models/maplocationmodel.cpp
@@ -1,26 +1,31 @@
// SPDX-License-Identifier: GPL-2.0
#include <QDebug>
#include "maplocationmodel.h"
+#include "core/divesite.h"
const char *MapLocation::PROPERTY_NAME_COORDINATE = "coordinate";
-const char *MapLocation::PROPERTY_NAME_UUID = "uuid";
+const char *MapLocation::PROPERTY_NAME_DIVESITE = "divesite";
const char *MapLocation::PROPERTY_NAME_NAME = "name";
-MapLocation::MapLocation()
+MapLocation::MapLocation() : m_ds(nullptr)
{
- m_uuid = 0;
}
-MapLocation::MapLocation(quint32 uuid, QGeoCoordinate coord, QString name) :
- m_uuid(uuid), m_coordinate(coord), m_name(name)
+MapLocation::MapLocation(struct dive_site *ds, QGeoCoordinate coord, QString name) :
+ m_ds(ds), m_coordinate(coord), m_name(name)
{
}
QVariant MapLocation::getRole(int role) const
{
switch (role) {
- case Roles::RoleUuid:
- return QVariant::fromValue(m_uuid);
+ case Roles::RoleDivesite:
+ // To pass the dive site as an opaque object to QML, we convert it to uintptr_t.
+ // This type is guaranteed to hold a full pointer, therefore false equivalence
+ // owing to truncation can happen. The more logical type would of course be void *,
+ // but in tests all QVariant<void *> compared equal. It is unclear whether this is
+ // a bug in a certain version of QML or QML is inredibly broken by design.
+ return QVariant::fromValue((uintptr_t)m_ds);
case Roles::RoleCoordinate:
return QVariant::fromValue(m_coordinate);
case Roles::RoleName:
@@ -46,17 +51,23 @@ void MapLocation::setCoordinateNoEmit(QGeoCoordinate coord)
m_coordinate = coord;
}
-quint32 MapLocation::uuid()
+struct dive_site *MapLocation::divesite()
{
- return m_uuid;
+ return m_ds;
}
-MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent)
+QVariant MapLocation::divesiteVariant()
{
- m_roles[MapLocation::Roles::RoleUuid] = MapLocation::PROPERTY_NAME_UUID;
+ // See comment on uintptr_t above
+ return QVariant::fromValue((uintptr_t)m_ds);
+}
+
+MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent),
+ m_selectedDs(nullptr)
+{
+ 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;
- m_selectedUuid = 0;
}
MapLocationModel::~MapLocationModel()
@@ -120,36 +131,44 @@ void MapLocationModel::clear()
endRemoveRows();
}
-void MapLocationModel::setSelectedUuid(QVariant uuid, QVariant fromClick)
+void MapLocationModel::setSelected(struct dive_site *ds, bool fromClick)
+{
+ m_selectedDs = ds;
+ emit selectedDsChanged();
+ if (fromClick)
+ emit selectedLocationChanged(getMapLocation(m_selectedDs));
+}
+
+void MapLocationModel::setSelected(QVariant divesite, QVariant fromClick)
{
- m_selectedUuid = qvariant_cast<quint32>(uuid);
+ // See comment on uintptr_t above
+ struct dive_site *ds = (struct dive_site *)qvariant_cast<uintptr_t>(divesite);
const bool fromClickBool = qvariant_cast<bool>(fromClick);
- emit selectedUuidChanged();
- if (fromClickBool)
- emit selectedLocationChanged(getMapLocationForUuid(m_selectedUuid));
+ setSelected(ds, fromClickBool);
}
-quint32 MapLocationModel::selectedUuid()
+QVariant MapLocationModel::selectedDs()
{
- return m_selectedUuid;
+ // See comment on uintptr_t above
+ return QVariant::fromValue((uintptr_t)m_selectedDs);
}
-MapLocation *MapLocationModel::getMapLocationForUuid(quint32 uuid)
+MapLocation *MapLocationModel::getMapLocation(const struct dive_site *ds)
{
MapLocation *location;
foreach(location, m_mapLocations) {
- if (uuid == location->uuid())
+ if (ds == location->divesite())
return location;
}
return NULL;
}
-void MapLocationModel::updateMapLocationCoordinates(quint32 uuid, QGeoCoordinate coord)
+void MapLocationModel::updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord)
{
MapLocation *location;
int row = 0;
foreach(location, m_mapLocations) {
- if (uuid == location->uuid()) {
+ if (ds == location->divesite()) {
location->setCoordinateNoEmit(coord);
emit dataChanged(createIndex(0, row), createIndex(0, row));
return;
@@ -157,5 +176,5 @@ void MapLocationModel::updateMapLocationCoordinates(quint32 uuid, QGeoCoordinate
row++;
}
// should not happen, as this should be called only when editing an existing marker
- qWarning() << "MapLocationModel::updateMapLocationCoordinates(): cannot find MapLocation for uuid:" << uuid;
+ qWarning() << "MapLocationModel::updateMapLocationCoordinates(): cannot find MapLocation for uuid:" << (ds ? ds->uuid : 0);
}