From f44645b6fe3de4d117fe85d1f2ae7a01ac34b252 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Mon, 17 Jul 2017 22:36:55 +0300 Subject: maplocationmodel: store the coordinate as QGeoCoordinate Instead of maintaining a seperate latitude/longitude values in C++ and passing them to QML separatelly, pass them as a QGeoCoordinate. This reduces the number of model "roles" and also prevents the creations of extra objects in QML (e.g. via QtPositioning.coordinate(..)). Signed-off-by: Lubomir I. Ivanov --- qt-models/maplocationmodel.cpp | 13 +++++-------- qt-models/maplocationmodel.h | 12 +++++------- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'qt-models') diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp index 43f28c981..d08e7020c 100644 --- a/qt-models/maplocationmodel.cpp +++ b/qt-models/maplocationmodel.cpp @@ -5,18 +5,16 @@ MapLocation::MapLocation() { } -MapLocation::MapLocation(qreal latitude, qreal longitude) : - m_latitude(latitude), m_longitude(longitude) +MapLocation::MapLocation(QGeoCoordinate coord) : + m_coordinate(coord) { } QVariant MapLocation::getRole(int role) const { switch (role) { - case Roles::RoleLatitude: - return m_latitude; - case Roles::RoleLongitude: - return m_longitude; + case Roles::RoleCoordinate: + return QVariant::fromValue(m_coordinate); default: return QVariant(); } @@ -24,8 +22,7 @@ QVariant MapLocation::getRole(int role) const MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent) { - m_roles[MapLocation::Roles::RoleLatitude] = "latitude"; - m_roles[MapLocation::Roles::RoleLongitude] = "longitude"; + m_roles[MapLocation::Roles::RoleCoordinate] = "coordinate"; } MapLocationModel::~MapLocationModel() diff --git a/qt-models/maplocationmodel.h b/qt-models/maplocationmodel.h index 8dff65eac..4aeee0364 100644 --- a/qt-models/maplocationmodel.h +++ b/qt-models/maplocationmodel.h @@ -7,27 +7,25 @@ #include #include #include +#include class MapLocation : public QObject { Q_OBJECT - Q_PROPERTY(qreal latitude MEMBER m_latitude) - Q_PROPERTY(qreal longitude MEMBER m_longitude) + Q_PROPERTY(QGeoCoordinate coordinate MEMBER m_coordinate) public: explicit MapLocation(); - explicit MapLocation(qreal lat, qreal lng); + explicit MapLocation(QGeoCoordinate); QVariant getRole(int role) const; enum Roles { - RoleLatitude = Qt::UserRole + 1, - RoleLongitude + RoleCoordinate = Qt::UserRole + 1, }; private: - qreal m_latitude; - qreal m_longitude; + QGeoCoordinate m_coordinate; }; class MapLocationModel : public QAbstractListModel -- cgit v1.2.3-70-g09d2