summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-26 12:02:12 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-10-04 12:23:21 +0200
commit16e6505c953d6d8d8f05f89ae052a9dd6ccf828e (patch)
treeb80c21b524acc8896bcf1081bcc1b1428868ea25 /src
parent8b9bd24556214074d0930716e1cfe918471f42b6 (diff)
downloadqtlocation-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')
-rw-r--r--src/location/CMakeLists.txt1
-rw-r--r--src/location/declarativemaps/qdeclarativegeoroute.cpp298
-rw-r--r--src/location/declarativemaps/qdeclarativegeoroute_p.h121
-rw-r--r--src/location/declarativemaps/qdeclarativegeoroutemodel.cpp38
-rw-r--r--src/location/declarativemaps/qdeclarativegeoroutemodel_p.h5
-rw-r--r--src/location/declarativeplaces/qdeclarativesearchmodelbase.cpp20
-rw-r--r--src/location/maps/qgeoroute.cpp239
-rw-r--r--src/location/maps/qgeoroute.h6
-rw-r--r--src/location/quickmapitems/qdeclarativeroutemapitem.cpp13
-rw-r--r--src/location/quickmapitems/qdeclarativeroutemapitem_p.h15
10 files changed, 217 insertions, 539 deletions
diff --git a/src/location/CMakeLists.txt b/src/location/CMakeLists.txt
index eb26b79e..19a029ad 100644
--- a/src/location/CMakeLists.txt
+++ b/src/location/CMakeLists.txt
@@ -124,7 +124,6 @@ qt_internal_add_qml_module(Location
declarativemaps/qdeclarativegeomapparameter.cpp
declarativemaps/error_messages.cpp declarativemaps/error_messages_p.h
declarativemaps/qdeclarativegeocodemodel.cpp declarativemaps/qdeclarativegeocodemodel_p.h
- declarativemaps/qdeclarativegeoroute.cpp declarativemaps/qdeclarativegeoroute_p.h
declarativemaps/qdeclarativegeoroutemodel.cpp declarativemaps/qdeclarativegeoroutemodel_p.h
quickmapitems/qgeomapitemgeometry.cpp quickmapitems/qgeomapitemgeometry_p.h
quickmapitems/qdeclarativegeomap_p.h quickmapitems/qdeclarativegeomap.cpp
diff --git a/src/location/declarativemaps/qdeclarativegeoroute.cpp b/src/location/declarativemaps/qdeclarativegeoroute.cpp
deleted file mode 100644
index 5ef76f78..00000000
--- a/src/location/declarativemaps/qdeclarativegeoroute.cpp
+++ /dev/null
@@ -1,298 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativegeoroute_p.h"
-#include <QtLocation/private/qgeomap_p.h>
-#include <QtLocation/private/qgeoroute_p.h>
-#include <QtLocation/private/qdeclarativegeoroutemodel_p.h>
-
-#include <QtPositioning/QGeoRectangle>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype Route
- \instantiates QDeclarativeGeoRoute
- \inqmlmodule QtLocation
- \ingroup qml-QtLocation5-routing
- \since QtLocation 5.5
-
- \brief The Route type represents one geographical route.
-
- A Route type contains high level information about a route, such
- as the length the route, the estimated travel time for the route,
- and enough information to render a basic image of the route on a map.
-
- The QGeoRoute object also contains a list of \l routeSegment objects which
- describe subsections of the route in greater detail.
-
- The primary means of acquiring Route objects is \l RouteModel.
-
- \section1 Example
-
- This example shows how to display a route's maneuvers in a ListView:
-
- \snippet declarative/routing.qml QtQuick import
- \snippet declarative/maps.qml QtLocation import
- \codeline
- \snippet declarative/routing.qml Route Maneuver List1
- \snippet declarative/routing.qml Route Maneuver List2
- \snippet declarative/routing.qml Route Maneuver List3
-
-*/
-
-QDeclarativeGeoRoute::QDeclarativeGeoRoute(QObject *parent)
- : QObject(parent)
-{
-}
-
-QDeclarativeGeoRoute::QDeclarativeGeoRoute(const QGeoRoute &route, QObject *parent)
- : QObject(parent), route_(route)
-{
-}
-
-QDeclarativeGeoRoute::~QDeclarativeGeoRoute() {}
-
-/*!
- \internal
-*/
-QList<QGeoCoordinate> QDeclarativeGeoRoute::routePath()
-{
- return route_.path();
-}
-
-/*!
- \qmlproperty georectangle QtLocation::Route::bounds
-
- Read-only property which holds a bounding box which encompasses the entire route.
-
-*/
-
-QGeoRectangle QDeclarativeGeoRoute::bounds() const
-{
- return route_.bounds();
-}
-
-/*!
- \qmlproperty int QtLocation::Route::travelTime
-
- Read-only property which holds the estimated amount of time it will take to
- traverse this route, in seconds.
-
-*/
-
-int QDeclarativeGeoRoute::travelTime() const
-{
- return route_.travelTime();
-}
-
-/*!
- \qmlproperty real QtLocation::Route::distance
-
- Read-only property which holds distance covered by this route, in meters.
-*/
-
-qreal QDeclarativeGeoRoute::distance() const
-{
- return route_.distance();
-}
-
-/*!
- \qmlproperty list<coordinate> QtLocation::Route::path
-
- Read-only property which holds the geographical coordinates of this route.
- Coordinates are listed in the order in which they would be traversed by someone
- traveling along this segment of the route.
-
- To access individual segments you can use standard list accessors: 'path.length'
- indicates the number of objects and 'path[index starting from zero]' gives
- the actual object.
-
- \sa QtPositioning::coordinate
-*/
-
-QList<QGeoCoordinate> QDeclarativeGeoRoute::path() const
-{
- return route_.path();
-}
-
-void QDeclarativeGeoRoute::setPath(const QList<QGeoCoordinate> &value)
-{
- if (route_.path() == value)
- return;
-
- route_.setPath(value);
- emit pathChanged();
-}
-
-/*!
- \qmlproperty list<routeSegment> QtLocation::Route::segments
-
- Read-only property which holds the list of \l routeSegment objects of this route.
-
- To access individual segments you can use standard list accessors: 'segments.length'
- indicates the number of objects and 'segments[index starting from zero]' gives
- the actual objects.
-
- \sa routeSegment
-*/
-
-QList<QGeoRouteSegment> QDeclarativeGeoRoute::segments()
-{
- return route_.d_ptr->segments();
-}
-
-/*!
- \qmlmethod int QtLocation::Route::segmentsCount()
-
- Returns the number of segments in the route
-
- \sa routeSegment
-
- \since 5.11
-*/
-
-int QDeclarativeGeoRoute::segmentsCount() const
-{
- return route_.d_ptr->segmentsCount();
-}
-
-const QGeoRoute &QDeclarativeGeoRoute::route() const
-{
- return route_;
-}
-
-/*!
- \qmlproperty RouteQuery QtLocation::Route::routeQuery
-
- Returns the route query associated with this route.
-
- \since 5.11
-*/
-QDeclarativeGeoRouteQuery *QDeclarativeGeoRoute::routeQuery() const
-{
- if (!routeQuery_) {
- routeQuery_ = new QDeclarativeGeoRouteQuery(route_.request(),
- const_cast<QDeclarativeGeoRoute *>(this));
- }
- return routeQuery_;
-}
-
-/*!
- \qmlproperty list<Route> QtLocation::Route::legs
-
- Returns the route legs associated with this route.
- Route legs are the sub-routes between each two adjacent waypoints.
- The result may be empty, if this level of detail is not supported by the
- backend.
-
- \since QtLocation 5.12
-*/
-QList<QDeclarativeGeoRoute *> QDeclarativeGeoRoute::legs() const
-{
- QList<QDeclarativeGeoRoute *> legs;
- const QList<QGeoRoute> rlegs = route_.routeLegs();
- for (const auto &r : rlegs)
- legs.append(new QDeclarativeGeoRoute(r, const_cast<QDeclarativeGeoRoute *>(this)));
- return legs;
-}
-
-/*!
- \qmlproperty Object Route::extendedAttributes
-
- This property holds the extended attributes of the route and is a map.
- These attributes are plugin specific, and can be empty.
-
- Consult the \l {Qt Location#Plugin References and Parameters}{plugin documentation}
- for what attributes are supported and how they should be used.
-
- Note, due to limitations of the QQmlPropertyMap, it is not possible
- to declaratively specify the attributes in QML, assignment of attributes keys
- and values can only be accomplished by JavaScript.
-
- \since QtLocation 5.13
-*/
-QVariantMap QDeclarativeGeoRoute::extendedAttributes() const
-{
- return route_.extendedAttributes();
-}
-
-/*!
- \qmlmethod bool QtLocation::Route::equals(Route other)
-
- This method performs deep comparison if the present route
- is identical to the \a other route.
- Returns \c true if the routes are equal.
-
- \since 5.12
-*/
-bool QDeclarativeGeoRoute::equals(QDeclarativeGeoRoute *other) const
-{
- return route_ == other->route_;
-}
-
-/*!
- \qmlproperty int QtLocation::Route::legIndex
-
- Read-only property which holds the index of the leg within the containing Route's
- list of QtLocation::Route::legs. The index is -1 if this route is not a leg within
- an overall route.
-
- \sa overallRoute
-*/
-int QDeclarativeGeoRoute::legIndex() const
-{
- return route_.legIndex();
-}
-
-/*!
- \qmlproperty Route QtLocation::Route::overallRoute
-
- Read-only property which holds the Route that contains this leg.
-*/
-
-QDeclarativeGeoRoute *QDeclarativeGeoRoute::overallRoute() const
-{
- QDeclarativeGeoRoute *containingRoute = qobject_cast<QDeclarativeGeoRoute *>(parent());
- if (Q_UNLIKELY(!containingRoute))
- return new QDeclarativeGeoRoute(route_.overallRoute(), parent());
- return containingRoute;
-}
-
-QT_END_NAMESPACE
diff --git a/src/location/declarativemaps/qdeclarativegeoroute_p.h b/src/location/declarativemaps/qdeclarativegeoroute_p.h
deleted file mode 100644
index 414d8a03..00000000
--- a/src/location/declarativemaps/qdeclarativegeoroute_p.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEGEOROUTE_H
-#define QDECLARATIVEGEOROUTE_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtLocation/private/qlocationglobal_p.h>
-
-#include <QtCore/QObject>
-#include <QtCore/QList>
-#include <QtQml/QQmlPropertyMap>
-#include <QtLocation/QGeoRoute>
-#include <QtLocation/QGeoRouteSegment>
-
-Q_MOC_INCLUDE(<QtLocation/private/qdeclarativegeoroutemodel_p.h>)
-
-QT_BEGIN_NAMESPACE
-class QDeclarativeGeoRouteQuery;
-
-class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoRoute : public QObject
-{
- Q_OBJECT
- QML_NAMED_ELEMENT(Route)
- Q_PROPERTY(QGeoRectangle bounds READ bounds CONSTANT)
- Q_PROPERTY(int travelTime READ travelTime CONSTANT)
- Q_PROPERTY(qreal distance READ distance CONSTANT)
- Q_PROPERTY(QList<QGeoCoordinate> path READ path WRITE setPath NOTIFY pathChanged)
- Q_PROPERTY(QList<QGeoRouteSegment> segments READ segments CONSTANT)
- Q_PROPERTY(QDeclarativeGeoRouteQuery *routeQuery READ routeQuery REVISION(5, 11))
- Q_PROPERTY(QList<QDeclarativeGeoRoute *> legs READ legs CONSTANT REVISION(5, 12))
- Q_PROPERTY(QVariantMap extendedAttributes READ extendedAttributes CONSTANT REVISION(5, 13))
- Q_PROPERTY(int legIndex READ legIndex CONSTANT)
- Q_PROPERTY(QDeclarativeGeoRoute *overallRoute READ overallRoute CONSTANT)
-
-
-public:
- explicit QDeclarativeGeoRoute(QObject *parent = nullptr);
- QDeclarativeGeoRoute(const QGeoRoute &route, QObject *parent = nullptr);
- ~QDeclarativeGeoRoute();
-
- QGeoRectangle bounds() const;
- int travelTime() const;
- qreal distance() const;
-
- QList<QGeoCoordinate> path() const;
- void setPath(const QList<QGeoCoordinate> &value);
-
- QList<QGeoRouteSegment> segments();
- int legIndex() const;
- QDeclarativeGeoRoute *overallRoute() const;
-
- int segmentsCount() const;
- const QGeoRoute &route() const;
- QDeclarativeGeoRouteQuery *routeQuery() const;
- QList<QDeclarativeGeoRoute *> legs() const;
- QVariantMap extendedAttributes() const;
-
- Q_INVOKABLE bool equals(QDeclarativeGeoRoute *other) const;
-
-Q_SIGNALS:
- void pathChanged();
-
-private:
- QList<QGeoCoordinate> routePath();
-
- QGeoRoute route_;
- mutable QDeclarativeGeoRouteQuery *routeQuery_ = nullptr;
-
- friend class QDeclarativeRouteMapItem;
-};
-
-QT_END_NAMESPACE
-
-#endif
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());
diff --git a/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h b/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h
index 9276ef2a..4183ebc3 100644
--- a/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h
+++ b/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h
@@ -118,7 +118,6 @@ public:
};
explicit QDeclarativeGeoRouteModel(QObject *parent = nullptr);
- ~QDeclarativeGeoRouteModel();
// From QQmlParserStatus
void classBegin() override {}
@@ -146,7 +145,7 @@ public:
RouteError error() const;
int count() const;
- Q_INVOKABLE QDeclarativeGeoRoute *get(int index);
+ Q_INVOKABLE QGeoRoute get(int index);
Q_INVOKABLE void reset();
Q_INVOKABLE void cancel();
@@ -181,7 +180,7 @@ private:
QDeclarativeGeoServiceProvider *plugin_ = nullptr;
QDeclarativeGeoRouteQuery *routeQuery_ = nullptr;
- QList<QDeclarativeGeoRoute *> routes_;
+ QList<QGeoRoute> routes_;
bool autoUpdate_ = false;
Status status_ = QDeclarativeGeoRouteModel::Null;
QString errorString_;
diff --git a/src/location/declarativeplaces/qdeclarativesearchmodelbase.cpp b/src/location/declarativeplaces/qdeclarativesearchmodelbase.cpp
index 2bbe363e..36f5190f 100644
--- a/src/location/declarativeplaces/qdeclarativesearchmodelbase.cpp
+++ b/src/location/declarativeplaces/qdeclarativesearchmodelbase.cpp
@@ -50,7 +50,6 @@
#include <QtLocation/QPlaceSearchReply>
#include <QtPositioning/QGeoCircle>
#include <QtPositioning/QGeoPolygon>
-#include <QtLocation/private/qdeclarativegeoroute_p.h>
#include <QtLocation/private/qplacesearchrequest_p.h>
QT_BEGIN_NAMESPACE
@@ -108,17 +107,17 @@ QVariant QDeclarativeSearchModelBase::searchArea() const
void QDeclarativeSearchModelBase::setSearchArea(const QVariant &searchArea)
{
QGeoShape s;
- QDeclarativeGeoRoute *route = nullptr;
+ QGeoRoute route;
bool routeSearchArea = false;
- if (searchArea.userType() == qMetaTypeId<QGeoRectangle>())
+ if (searchArea.userType() == qMetaTypeId<QGeoRectangle>()) {
s = searchArea.value<QGeoRectangle>();
- else if (searchArea.userType() == qMetaTypeId<QGeoCircle>())
+ } else if (searchArea.userType() == qMetaTypeId<QGeoCircle>()) {
s = searchArea.value<QGeoCircle>();
- else if (searchArea.userType() == qMetaTypeId<QGeoShape>())
+ } else if (searchArea.userType() == qMetaTypeId<QGeoShape>()) {
s = searchArea.value<QGeoShape>();
- else if (searchArea.typeId() == qMetaTypeId<QObject *>()) {
- route = searchArea.value<QDeclarativeGeoRoute *>();
- if (!route)
+ } else if (searchArea.typeId() == qMetaTypeId<QGeoRoute>()) {
+ route = searchArea.value<QGeoRoute>();
+ if (route == QGeoRoute())
return;
routeSearchArea = true;
}
@@ -131,11 +130,12 @@ void QDeclarativeSearchModelBase::setSearchArea(const QVariant &searchArea)
rp->routeSearchArea = QGeoRoute();
if (m_request.searchArea() == s
- && (!route || rp->routeSearchArea == route->route()))
+ && (route == QGeoRoute() || rp->routeSearchArea == route)) {
return;
+ }
if (routeSearchArea)
- rp->routeSearchArea = route->route();
+ rp->routeSearchArea = route;
else
m_request.setSearchArea(s);
emit searchAreaChanged();
diff --git a/src/location/maps/qgeoroute.cpp b/src/location/maps/qgeoroute.cpp
index 1b7b938b..0144edb9 100644
--- a/src/location/maps/qgeoroute.cpp
+++ b/src/location/maps/qgeoroute.cpp
@@ -74,6 +74,37 @@ QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QGeoRoutePrivate)
*/
/*!
+ \qmlvaluetype route
+ \instantiates QDeclarativeGeoRoute
+ \inqmlmodule QtLocation
+ \ingroup qml-QtLocation5-routing
+ \since QtLocation 5.5
+
+ \brief The route type represents one geographical route.
+
+ A route type contains high level information about a route, such
+ as the length the route, the estimated travel time for the route,
+ and enough information to render a basic image of the route on a map.
+
+ The QGeoRoute object also contains a list of \l routeSegment objects which
+ describe subsections of the route in greater detail.
+
+ The primary means of acquiring route objects is \l RouteModel.
+
+ \section1 Example
+
+ This example shows how to display a route's maneuvers in a ListView:
+
+ \snippet declarative/routing.qml QtQuick import
+ \snippet declarative/maps.qml QtLocation import
+ \codeline
+ \snippet declarative/routing.qml Route Maneuver List1
+ \snippet declarative/routing.qml Route Maneuver List2
+ \snippet declarative/routing.qml Route Maneuver List3
+
+*/
+
+/*!
Constructs a route object.
*/
QGeoRoute::QGeoRoute()
@@ -136,58 +167,54 @@ bool QGeoRoute::isEqual(const QGeoRoute &other) const noexcept
/*!
- Sets the identifier of this route to \a id.
+ \property QGeoRoute::routeId
+ \brief the identifier of this route
Service providers which support the updating of routes commonly assign
- identifiers to routes. If this route came from such a service provider changing
- the identifier will probably cause route updates to stop working.
+ identifiers to routes. If this route came from such a service provider,
+ then changing the identifier will probably cause route updates to stop
+ working.
*/
void QGeoRoute::setRouteId(const QString &id)
{
d_ptr->setId(id);
}
-/*!
- Returns the identifier of this route.
-
- Service providers which support the updating of routes commonly assign
- identifiers to routes. If this route did not come from such a service provider
- the function will return an empty string.
-*/
QString QGeoRoute::routeId() const
{
return d_ptr->id();
}
/*!
- Sets the route request which describes the criteria used in the
- calculcation of this route to \a request.
+ \property QGeoRoute::request
+ \brief the route request which describes the criteria used in the
+ calculcation of this route
*/
void QGeoRoute::setRequest(const QGeoRouteRequest &request)
{
d_ptr->setRequest(request);
}
-/*!
- Returns the route request which describes the criteria used in
- the calculation of this route.
-*/
QGeoRouteRequest QGeoRoute::request() const
{
return d_ptr->request();
}
/*!
- Sets the bounding box which encompasses the entire route to \a bounds.
+ \qmlproperty georectangle QtLocation::route::bounds
+
+ Read-only property which holds a bounding box which encompasses the entire route.
+*/
+
+/*!
+ \property QGeoRoute::bounds
+ \brief the bounding box which encompasses the entire route
*/
void QGeoRoute::setBounds(const QGeoRectangle &bounds)
{
d_ptr->setBounds(bounds);
}
-/*!
- Returns a bounding box which encompasses the entire route.
-*/
QGeoRectangle QGeoRoute::bounds() const
{
return d_ptr->bounds();
@@ -216,34 +243,82 @@ QGeoRouteSegment QGeoRoute::firstRouteSegment() const
}
/*!
- Sets the estimated amount of time it will take to traverse this route,
- in seconds, to \a secs.
+ \qmlmethod int QtLocation::route::segmentsCount()
+
+ Returns the number of segments in the route
+
+ \sa routeSegment
+
+ \since 5.11
+*/
+
+/*!
+ \property QGeoRoute::segmentsCount
+ \brief the number of segments in the route
+*/
+qsizetype QGeoRoute::segmentsCount() const
+{
+ return d_ptr->segmentsCount();
+}
+
+/*!
+ \qmlproperty list<routeSegment> QtLocation::Route::segments
+
+ Read-only property which holds the list of \l routeSegment objects of this route.
+
+ To access individual segments you can use standard list accessors: 'segments.length'
+ indicates the number of objects and 'segments[index starting from zero]' gives
+ the actual objects.
+
+ \sa routeSegment
*/
-void QGeoRoute::setTravelTime(int secs)
+
+/*!
+ \property QGeoRoute::segments
+ \brief the list of QGeoRouteSegment objects of this route
+*/
+QList<QGeoRouteSegment> QGeoRoute::segments() const
{
- d_ptr->setTravelTime(secs);
+ return d_ptr->segments();
}
/*!
- Returns the estimated amount of time it will take to traverse this route,
- in seconds.
+ \qmlproperty int QtLocation::route::travelTime
+
+ Read-only property which holds the estimated amount of time it will take to
+ traverse this route, in seconds.
*/
+
+/*!
+ \property QGeoRoute::traveltime
+ \brief the estimated amount of time it will take to traverse this route,
+ in seconds
+*/
+void QGeoRoute::setTravelTime(int secs)
+{
+ d_ptr->setTravelTime(secs);
+}
+
int QGeoRoute::travelTime() const
{
return d_ptr->travelTime();
}
/*!
- Sets the distance covered by this route, in meters, to \a distance.
+ \qmlproperty real QtLocation::route::distance
+
+ Read-only property which holds distance covered by this route, in meters.
+*/
+
+/*!
+ \property QGeoRoute::distance
+ \brief the distance covered by this route, in meters
*/
void QGeoRoute::setDistance(qreal distance)
{
d_ptr->setDistance(distance);
}
-/*!
- Returns the distance covered by this route, in meters.
-*/
qreal QGeoRoute::distance() const
{
return d_ptr->distance();
@@ -270,9 +345,24 @@ QGeoRouteRequest::TravelMode QGeoRoute::travelMode() const
}
/*!
- Sets the geometric shape of the route to \a path.
+ \qmlproperty list<coordinate> QtLocation::route::path
+
+ Read-only property which holds the geographical coordinates of this route.
+ Coordinates are listed in the order in which they would be traversed by someone
+ traveling along this segment of the route.
+
+ To access individual segments you can use standard list accessors: 'path.length'
+ indicates the number of objects and 'path[index starting from zero]' gives
+ the actual object.
+
+ \sa QtPositioning::coordinate
+*/
+
+/*!
+ \property QGeoRoute::path
+ \brief the geometric shape of the route
- The coordinates in \a path should be listed in the order in which they
+ The coordinates should be listed in the order in which they
would be traversed by someone traveling along this segment of the route.
*/
void QGeoRoute::setPath(const QList<QGeoCoordinate> &path)
@@ -280,19 +370,26 @@ void QGeoRoute::setPath(const QList<QGeoCoordinate> &path)
d_ptr->setPath(path);
}
-/*!
- Returns the geometric shape of the route.
- The coordinates should be listed in the order in which they
- would be traversed by someone traveling along this segment of the route.
-*/
QList<QGeoCoordinate> QGeoRoute::path() const
{
return d_ptr->path();
}
/*!
- Sets the route \a legs for a multi-waypoint route.
+ \qmlproperty list<route> QtLocation::route::legs
+
+ Returns the route legs associated with this route.
+ Route legs are the sub-routes between each two adjacent waypoints.
+ The result may be empty, if this level of detail is not supported by the
+ backend.
+
+ \since QtLocation 5.12
+*/
+
+/*!
+ \property QGeoRoute::routeLegs
+ \brief the route \a legs for a multi-waypoint route
\sa QGeoRouteLeg
\since 5.12
@@ -302,19 +399,31 @@ void QGeoRoute::setRouteLegs(const QList<QGeoRoute> &legs)
d_ptr->setRouteLegs(legs);
}
-/*!
- Returns the legs for the route.
-
- \sa QGeoRouteLeg
- \since 5.12
-*/
QList<QGeoRoute> QGeoRoute::routeLegs() const
{
return d_ptr->routeLegs();
}
+
+/*!
+ \qmlproperty Object route::extendedAttributes
+
+ This property holds the extended attributes of the route and is a map.
+ These attributes are plugin specific, and can be empty.
+
+ Consult the \l {Qt Location#Plugin References and Parameters}{plugin documentation}
+ for what attributes are supported and how they should be used.
+
+ Note, due to limitations of the QQmlPropertyMap, it is not possible
+ to declaratively specify the attributes in QML, assignment of attributes keys
+ and values can only be accomplished by JavaScript.
+
+ \since QtLocation 5.13
+*/
+
/*!
- Sets the extended attributes \a extendedAttributes associated with this route.
+ \property QGeoRoute::extendedAttributes
+ \brief the extended attributes associated with this route
\since 5.13
*/
@@ -323,44 +432,56 @@ void QGeoRoute::setExtendedAttributes(const QVariantMap &extendedAttributes)
d_ptr->setExtendedAttributes(extendedAttributes);
}
-/*!
- Returns the extended attributes associated with this route.
-
- \since 5.13
-*/
QVariantMap QGeoRoute::extendedAttributes() const
{
return d_ptr->extendedAttributes();
}
/*!
- Sets the route leg index to \a idx.
+ \qmlproperty int QtLocation::route::legIndex
+
+ Read-only property which holds the index of the leg within the containing route's
+ list of QtLocation::route::legs. The index is -1 if this route is not a leg within
+ an overall route.
+
+ \sa overallRoute
+*/
+
+/*!
+ \property QGeoRoute::legIndex
+ \brief the leg index of this route
+
+ The index of the leg inside the containing QGeoRoute::routeLegs list
+ can be used to find the next legs.
*/
void QGeoRoute::setLegIndex(int idx)
{
d()->setLegIndex(idx);
}
-/*!
- Returns the index of this route leg inside the containing QGeoRoute::routeLegs list.
- Can be used to find the next legs.
-*/
int QGeoRoute::legIndex() const
{
return const_d()->legIndex();
}
/*!
- Sets the \a route that contains this route leg.
+ \qmlproperty Route QtLocation::route::overallRoute
+
+ Read-only property which holds the route that contains this leg.
+*/
+
+/*!
+ \property QGeoRoute::overallRoute
+ \brief the route that contains this route leg
+
+ This this route is not a leg within an overall route, then this property
+ holds an empty route.
*/
void QGeoRoute::setOverallRoute(const QGeoRoute &route)
{
d()->setContainingRoute(route);
}
-/*!
- Returns the route that contains this route leg.
-*/
QGeoRoute QGeoRoute::overallRoute() const
{
return const_d()->containingRoute();
diff --git a/src/location/maps/qgeoroute.h b/src/location/maps/qgeoroute.h
index e9a9041a..269515b1 100644
--- a/src/location/maps/qgeoroute.h
+++ b/src/location/maps/qgeoroute.h
@@ -62,13 +62,17 @@ class Q_LOCATION_EXPORT QGeoRoute
QML_VALUE_TYPE(route)
QML_STRUCTURED_VALUE
+ Q_PROPERTY(QString routeId READ routeId CONSTANT)
Q_PROPERTY(QGeoRectangle bounds READ bounds CONSTANT)
Q_PROPERTY(int travelTime READ travelTime CONSTANT)
Q_PROPERTY(qreal distance READ distance CONSTANT)
+ Q_PROPERTY(QList<QGeoCoordinate> path READ path WRITE setPath)
Q_PROPERTY(QList<QGeoRoute> routeLegs READ routeLegs CONSTANT)
Q_PROPERTY(QVariantMap extendedAttributes READ extendedAttributes CONSTANT)
Q_PROPERTY(int legIndex READ legIndex CONSTANT)
Q_PROPERTY(QGeoRoute overallRoute READ overallRoute CONSTANT)
+ Q_PROPERTY(qsizetype segmentsCount READ segmentsCount CONSTANT)
+ Q_PROPERTY(QList<QGeoRouteSegment> segments READ segments CONSTANT)
public:
QGeoRoute();
@@ -97,6 +101,8 @@ public:
void setFirstRouteSegment(const QGeoRouteSegment &routeSegment);
QGeoRouteSegment firstRouteSegment() const;
+ qsizetype segmentsCount() const;
+ QList<QGeoRouteSegment> segments() const;
void setTravelTime(int secs);
int travelTime() const;
diff --git a/src/location/quickmapitems/qdeclarativeroutemapitem.cpp b/src/location/quickmapitems/qdeclarativeroutemapitem.cpp
index 2d013e1a..b1d788ca 100644
--- a/src/location/quickmapitems/qdeclarativeroutemapitem.cpp
+++ b/src/location/quickmapitems/qdeclarativeroutemapitem.cpp
@@ -40,7 +40,6 @@
#include "qdeclarativeroutemapitem_p.h"
#include "qdeclarativepolylinemapitem_p.h"
-#include "qdeclarativegeoroute_p.h"
#include <QtQml/QQmlInfo>
#include <QtGui/QPainter>
@@ -111,30 +110,26 @@ QDeclarativeRouteMapItem::~QDeclarativeRouteMapItem()
This property holds the route to be drawn which can be used
to represent one geographical route.
*/
-QDeclarativeGeoRoute *QDeclarativeRouteMapItem::route() const
+QGeoRoute QDeclarativeRouteMapItem::route() const
{
return route_;
}
-void QDeclarativeRouteMapItem::setRoute(QDeclarativeGeoRoute *route)
+void QDeclarativeRouteMapItem::setRoute(const QGeoRoute &route)
{
if (route_ == route)
return;
route_ = route;
- connect(route_, &QDeclarativeGeoRoute::pathChanged,
- this, &QDeclarativeRouteMapItem::updateRoutePath);
-
- if (route_)
- setPathFromGeoList(route_->routePath());
+ setPathFromGeoList(route_.path());
emit routeChanged(route_);
}
void QDeclarativeRouteMapItem::updateRoutePath()
{
- setPathFromGeoList(route_->routePath());
+ setPathFromGeoList(route_.path());
}
/*!
diff --git a/src/location/quickmapitems/qdeclarativeroutemapitem_p.h b/src/location/quickmapitems/qdeclarativeroutemapitem_p.h
index df9e982f..61a2aadf 100644
--- a/src/location/quickmapitems/qdeclarativeroutemapitem_p.h
+++ b/src/location/quickmapitems/qdeclarativeroutemapitem_p.h
@@ -55,32 +55,29 @@
#include <QtLocation/private/qdeclarativegeomapitembase_p.h>
#include <QtLocation/private/qdeclarativegeomap_p.h>
#include <QtLocation/private/qdeclarativepolylinemapitem_p.h>
+#include <QtLocation/QGeoRoute>
#include <QPen>
#include <QBrush>
-Q_MOC_INCLUDE(<QtLocation/private/qdeclarativegeoroute_p.h>)
-
QT_BEGIN_NAMESPACE
-class QDeclarativeGeoRoute;
-
class Q_LOCATION_PRIVATE_EXPORT QDeclarativeRouteMapItem : public QDeclarativePolylineMapItem
{
Q_OBJECT
QML_NAMED_ELEMENT(MapRoute)
QML_ADDED_IN_VERSION(5, 0)
- Q_PROPERTY(QDeclarativeGeoRoute *route READ route WRITE setRoute NOTIFY routeChanged)
+ Q_PROPERTY(QGeoRoute route READ route WRITE setRoute NOTIFY routeChanged)
public:
explicit QDeclarativeRouteMapItem(QQuickItem *parent = nullptr);
~QDeclarativeRouteMapItem();
- QDeclarativeGeoRoute *route() const;
- void setRoute(QDeclarativeGeoRoute *route);
+ QGeoRoute route() const;
+ void setRoute(const QGeoRoute &route);
Q_SIGNALS:
- void routeChanged(const QDeclarativeGeoRoute *route);
+ void routeChanged(const QGeoRoute &route);
private slots:
void updateRoutePath();
@@ -89,7 +86,7 @@ protected:
void setPath(const QList<QGeoCoordinate> &value) override;
private:
- QDeclarativeGeoRoute *route_ = nullptr;
+ QGeoRoute route_;
};
QT_END_NAMESPACE