diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-26 12:02:12 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-10-04 12:23:21 +0200 |
commit | 16e6505c953d6d8d8f05f89ae052a9dd6ccf828e (patch) | |
tree | b80c21b524acc8896bcf1081bcc1b1428868ea25 /src/location/declarativemaps/qdeclarativegeoroutemodel.cpp | |
parent | 8b9bd24556214074d0930716e1cfe918471f42b6 (diff) | |
download | qtlocation-16e6505c953d6d8d8f05f89ae052a9dd6ccf828e.tar.gz |
Register QGeoRoute as QML value type, remove QDeclarativeGeoRoute
Adapt model and tests accordingly.
Fixes: QTBUG-106482
Change-Id: Ie5a36e4fef17ae7bc4ecfab9187a325fb025e283
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeoroutemodel.cpp')
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeoroutemodel.cpp | 38 |
1 files changed, 9 insertions, 29 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp b/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp index 99dae3a3..c1ab91ce 100644 --- a/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp +++ b/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp @@ -38,7 +38,6 @@ ****************************************************************************/ #include "qdeclarativegeoroutemodel_p.h" -#include "qdeclarativegeoroute_p.h" #include "error_messages_p.h" #include <QtCore/QCoreApplication> @@ -175,14 +174,6 @@ QDeclarativeGeoRouteModel::QDeclarativeGeoRouteModel(QObject *parent) { } -QDeclarativeGeoRouteModel::~QDeclarativeGeoRouteModel() -{ - if (!routes_.empty()) { - qDeleteAll(routes_); - routes_.clear(); - } -} - /*! \qmlproperty int QtLocation::RouteModel::count @@ -208,7 +199,6 @@ void QDeclarativeGeoRouteModel::reset() { if (!routes_.isEmpty()) { beginResetModel(); - qDeleteAll(routes_); routes_.clear(); emit countChanged(); emit routesChanged(); @@ -234,21 +224,21 @@ void QDeclarativeGeoRouteModel::cancel() } /*! - \qmlmethod Route QtLocation::RouteModel::get(int index) + \qmlmethod route QtLocation::RouteModel::get(int index) - Returns the Route at the specified \a index. Use the \l count + Returns the route at the specified \a index. Use the \l count property to check the amount of routes available. The routes are indexed from zero, so the accessible range is 0...(count - 1). - If you access out of bounds, a zero (null object) is returned and + If you access out of bounds, an empty route is returned and a warning is issued. */ -QDeclarativeGeoRoute *QDeclarativeGeoRouteModel::get(int index) +QGeoRoute QDeclarativeGeoRouteModel::get(int index) { if (index < 0 || index >= routes_.count()) { qmlWarning(this) << QStringLiteral("Index '%1' out of range").arg(index); - return nullptr; + return QGeoRoute(); } return routes_.at(index); } @@ -288,10 +278,8 @@ QVariant QDeclarativeGeoRouteModel::data(const QModelIndex &index, int role) con return QVariant(); } - if (role == RouteRole) { - QObject *route = routes_.at(index.row()); - return QVariant::fromValue(route); - } + if (role == RouteRole) + return QVariant::fromValue(routes_.at(index.row())); return QVariant(); } @@ -663,16 +651,8 @@ void QDeclarativeGeoRouteModel::routingFinished(QGeoRouteReply *reply) return; beginResetModel(); - int oldCount = routes_.count(); - qDeleteAll(routes_); - // Convert routes to declarative - routes_.clear(); - const auto routes = reply->routes(); - for (const auto &route : routes) { - QDeclarativeGeoRoute *declroute = new QDeclarativeGeoRoute(route, this); - QQmlEngine::setContextForObject(declroute, QQmlEngine::contextForObject(this)); - routes_.append(declroute); - } + const int oldCount = routes_.count(); + routes_ = reply->routes(); endResetModel(); setError(NoError, QString()); |