summaryrefslogtreecommitdiff
path: root/src/location/declarativemaps/qdeclarativegeoroute.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2018-06-28 10:45:16 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2018-08-24 11:54:22 +0000
commit0a6315b7a2a00d56a101c4a2ea165242d356e024 (patch)
treec7b9a313f4e001d243d7b796129894b026a53be2 /src/location/declarativemaps/qdeclarativegeoroute.cpp
parent34ee76720ee09ac692ea149ce44413cb5c0c7b99 (diff)
downloadqtlocation-0a6315b7a2a00d56a101c4a2ea165242d356e024.tar.gz
Add support for route legs
This patch adds support for route legs, that are the portions of a route between one waypoint and the next. QGeoRouteLeg in particular can be seen as an API addition to QGeoRoute in that it uses and exposes additional methods added to QGeoRoutePrivate but not used in QGeoRoute. Currently the request for legs is set to be the same as the request for the entire route. Finding the related bounding waypoints has to be done programmatically using the legIndex property. Change-Id: If462b1dc6348be16dc96b167db5500f079fe0a64 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeoroute.cpp')
-rw-r--r--src/location/declarativemaps/qdeclarativegeoroute.cpp91
1 files changed, 89 insertions, 2 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeoroute.cpp b/src/location/declarativemaps/qdeclarativegeoroute.cpp
index 8eeb549a..09ed46ab 100644
--- a/src/location/declarativemaps/qdeclarativegeoroute.cpp
+++ b/src/location/declarativemaps/qdeclarativegeoroute.cpp
@@ -79,12 +79,12 @@ QT_BEGIN_NAMESPACE
*/
QDeclarativeGeoRoute::QDeclarativeGeoRoute(QObject *parent)
- : QObject(parent), segmentsDirty_(true)
+ : QObject(parent)
{
}
QDeclarativeGeoRoute::QDeclarativeGeoRoute(const QGeoRoute &route, QObject *parent)
- : QObject(parent), route_(route), segmentsDirty_(true)
+ : QObject(parent), route_(route)
{
}
@@ -95,6 +95,7 @@ void QDeclarativeGeoRoute::initSegments(unsigned int lastIndex) // -1 turns it
if (!segmentsDirty_)
return;
+ const bool isLeg = qobject_cast<QDeclarativeGeoRoute *>(parent());
QGeoRouteSegment segment = route_.firstRouteSegment();
unsigned int idx = 0;
unsigned int initialListSize = static_cast<unsigned int>(segments_.size());
@@ -104,6 +105,10 @@ void QDeclarativeGeoRoute::initSegments(unsigned int lastIndex) // -1 turns it
QQmlEngine::setContextForObject(routeSegment, QQmlEngine::contextForObject(this));
segments_.append(routeSegment);
}
+ if (isLeg && segment.isLegLastSegment()) {
+ segmentsDirty_ = false;
+ return;
+ }
++idx;
segment = segment.nextRouteSegment();
if (idx > lastIndex && segment.isValid()) // Do not clean segmentsDirty_ if there are still segments to initialize
@@ -322,6 +327,31 @@ QDeclarativeGeoRouteQuery *QDeclarativeGeoRoute::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<QObject *> QDeclarativeGeoRoute::legs()
+{
+ // route_.routeLegs() is expected not to change.
+ // The following if condition is expected to be run only once.
+ if (route_.routeLegs().size() != legs_.size()) {
+ legs_.clear();
+ QList<QGeoRouteLeg> rlegs = route_.routeLegs();
+ for (const QGeoRouteLeg &r: rlegs) {
+ QDeclarativeGeoRouteLeg *dr = new QDeclarativeGeoRouteLeg(r, this);
+ legs_.append(dr);
+ }
+ }
+ return legs_;
+}
+
+/*!
\qmlmethod bool QtLocation::Route::equals(Route other)
This method performs deep comparison.
@@ -333,4 +363,61 @@ bool QDeclarativeGeoRoute::equals(QDeclarativeGeoRoute *other) const
return route_ == other->route_;
}
+/*!
+ \qmltype RouteLeg
+ \instantiates QDeclarativeGeoRouteLeg
+ \inqmlmodule QtLocation
+ \ingroup qml-QtLocation5-routing
+ \since QtLocation 5.12
+
+ \brief The RouteLeg type represents a leg of a Route, that is the portion
+ of a route between one waypoint and the next.
+
+ \note Since RouteLeg is a subclass of Route, QtLocation::Route::legs will
+ return an empty list if accessed on a route leg.
+*/
+
+/*!
+ \qmlproperty int QtLocation::RouteLeg::legIndex
+
+ Read-only property which holds the index of the leg within the containing Route's list of QtLocation::Route::legs .
+*/
+
+/*!
+ \qmlproperty Route QtLocation::RouteLeg::overallRoute
+
+ Read-only property which holds the Route that contains this leg.
+*/
+
+
+QDeclarativeGeoRouteLeg::QDeclarativeGeoRouteLeg(QObject *parent)
+ : QDeclarativeGeoRoute(parent)
+{
+
+}
+
+QDeclarativeGeoRouteLeg::QDeclarativeGeoRouteLeg(const QGeoRouteLeg &routeLeg, QObject *parent)
+ : QDeclarativeGeoRoute(routeLeg, parent), m_routeLeg(routeLeg)
+{
+
+}
+
+QDeclarativeGeoRouteLeg::~QDeclarativeGeoRouteLeg()
+{
+
+}
+
+int QDeclarativeGeoRouteLeg::legIndex() const
+{
+ return m_routeLeg.legIndex();
+}
+
+QObject *QDeclarativeGeoRouteLeg::overallRoute() const
+{
+ QDeclarativeGeoRoute *containingRoute = qobject_cast<QDeclarativeGeoRoute *>(parent());
+ if (Q_UNLIKELY(!containingRoute))
+ return new QDeclarativeGeoRoute(m_routeLeg.overallRoute(), parent());
+ return containingRoute;
+}
+
QT_END_NAMESPACE