diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-10-28 22:19:17 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-29 00:09:31 +0000 |
commit | a0cc02dfe8a82e12dc1eb902eeb906b2f9edc80b (patch) | |
tree | 1fd5f27b963fb6b691197a40556e57da147c92d2 | |
parent | c980216dc0e15a21b245a902870f9b8c5a18275c (diff) | |
download | subsurface-a0cc02dfe8a82e12dc1eb902eeb906b2f9edc80b.tar.gz |
Dive list: don't pass dive_site via uintptr_t through QML
Now that struct dive_site * is a proper Q_METATYPE it is not
necessary anymore to pass dive-sites as opaque uintptr_t types.
Simply pass a QVariants or directly via dive_site *.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/subsurface-qt/DiveObjectHelper.cpp | 2 | ||||
-rw-r--r-- | qt-models/maplocationmodel.cpp | 21 | ||||
-rw-r--r-- | qt-models/maplocationmodel.h | 3 |
3 files changed, 5 insertions, 21 deletions
diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp index a1233c3ea..78b1c0d3c 100644 --- a/core/subsurface-qt/DiveObjectHelper.cpp +++ b/core/subsurface-qt/DiveObjectHelper.cpp @@ -129,7 +129,7 @@ QString DiveObjectHelper::gps_decimal() const QVariant DiveObjectHelper::dive_site() const { - return QVariant::fromValue((uintptr_t)m_dive->dive_site); + return QVariant::fromValue(m_dive->dive_site); } QString DiveObjectHelper::duration() const diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp index ab34a7b16..960636260 100644 --- a/qt-models/maplocationmodel.cpp +++ b/qt-models/maplocationmodel.cpp @@ -20,12 +20,7 @@ QVariant MapLocation::getRole(int role) const { switch (role) { 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); + return QVariant::fromValue((dive_site *)m_ds); case Roles::RoleCoordinate: return QVariant::fromValue(m_coordinate); case Roles::RoleName: @@ -58,8 +53,7 @@ struct dive_site *MapLocation::divesite() QVariant MapLocation::divesiteVariant() { - // See comment on uintptr_t above - return QVariant::fromValue((uintptr_t)m_ds); + return QVariant::fromValue(m_ds); } MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent), @@ -139,18 +133,9 @@ void MapLocationModel::setSelected(struct dive_site *ds, bool fromClick) emit selectedLocationChanged(getMapLocation(m_selectedDs)); } -void MapLocationModel::setSelected(QVariant divesite, QVariant fromClick) -{ - // 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); - setSelected(ds, fromClickBool); -} - QVariant MapLocationModel::selectedDs() { - // See comment on uintptr_t above - return QVariant::fromValue((uintptr_t)m_selectedDs); + return QVariant::fromValue(m_selectedDs); } MapLocation *MapLocationModel::getMapLocation(const struct dive_site *ds) diff --git a/qt-models/maplocationmodel.h b/qt-models/maplocationmodel.h index 33a22366f..70f247f33 100644 --- a/qt-models/maplocationmodel.h +++ b/qt-models/maplocationmodel.h @@ -65,8 +65,7 @@ public: void clear(); MapLocation *getMapLocation(const struct dive_site *ds); void updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord); - void setSelected(struct dive_site *ds, bool fromClick = true); - Q_INVOKABLE void setSelected(QVariant divesite, QVariant fromClick = true); + Q_INVOKABLE void setSelected(struct dive_site *ds, bool fromClick = true); QVariant selectedDs(); protected: |