diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-11 10:42:38 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-22 14:56:44 +0200 |
commit | 634d9772e52e24ad3709da1b5161c421c1a7370e (patch) | |
tree | 0ca1a58b44a78912ecbbe1848ab8df79eb15959f /src/location/declarativemaps/qdeclarativegeoroute.cpp | |
parent | d8f03e5e71de3d951f86f0b0413fd75d554b2039 (diff) | |
download | qtlocation-634d9772e52e24ad3709da1b5161c421c1a7370e.tar.gz |
Simplify declarative wrapper of QGeoRoute
Move the logic of counting, and assembling a list of segments into the
QGeoRoute implementation, using a generic function that iterates the
linked list of segments and calls a functor. Remove the (premature -
how many legs are there - 5?) optimization of caching the list of legs
and segments.
For extended attributes, return the QVariantMap from QGeoRoute rather
than building a declarative map (that is then supposed to be CONSTANT).
Make the getters const.
The only thing stopping QGeoRoute to be directly exposed to QML and the
declarative wrapper to be removed is now the access to the routeQuery
object.
Change-Id: Ie9b86c3b235a75f3bbea086697a6eda02b060264
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeoroute.cpp')
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeoroute.cpp | 59 |
1 files changed, 15 insertions, 44 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeoroute.cpp b/src/location/declarativemaps/qdeclarativegeoroute.cpp index 5f1afe8d..5ef76f78 100644 --- a/src/location/declarativemaps/qdeclarativegeoroute.cpp +++ b/src/location/declarativemaps/qdeclarativegeoroute.cpp @@ -175,23 +175,7 @@ void QDeclarativeGeoRoute::setPath(const QList<QGeoCoordinate> &value) QList<QGeoRouteSegment> QDeclarativeGeoRoute::segments() { - return segments_; -} - -/*! - \internal -*/ -void QDeclarativeGeoRoute::appendSegment(const QGeoRouteSegment &segment) -{ - segments_.append(segment); -} - -/*! - \internal -*/ -void QDeclarativeGeoRoute::clearSegments() -{ - segments_.clear(); + return route_.d_ptr->segments(); } /*! @@ -206,7 +190,7 @@ void QDeclarativeGeoRoute::clearSegments() int QDeclarativeGeoRoute::segmentsCount() const { - return qMax(route_.d_ptr->segmentsCount(), segments_.count()); + return route_.d_ptr->segmentsCount(); } const QGeoRoute &QDeclarativeGeoRoute::route() const @@ -221,10 +205,12 @@ const QGeoRoute &QDeclarativeGeoRoute::route() const \since 5.11 */ -QDeclarativeGeoRouteQuery *QDeclarativeGeoRoute::routeQuery() +QDeclarativeGeoRouteQuery *QDeclarativeGeoRoute::routeQuery() const { - if (!routeQuery_) - routeQuery_ = new QDeclarativeGeoRouteQuery(route_.request(), this); + if (!routeQuery_) { + routeQuery_ = new QDeclarativeGeoRouteQuery(route_.request(), + const_cast<QDeclarativeGeoRoute *>(this)); + } return routeQuery_; } @@ -238,19 +224,13 @@ QDeclarativeGeoRouteQuery *QDeclarativeGeoRoute::routeQuery() \since QtLocation 5.12 */ -QList<QDeclarativeGeoRoute *> QDeclarativeGeoRoute::legs() +QList<QDeclarativeGeoRoute *> QDeclarativeGeoRoute::legs() const { - // 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(); - const QList<QGeoRoute> rlegs = route_.routeLegs(); - for (const auto &r: rlegs) { - QDeclarativeGeoRoute *dr = new QDeclarativeGeoRoute(r, this); - legs_.append(dr); - } - } - return legs_; + 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; } /*! @@ -268,18 +248,9 @@ QList<QDeclarativeGeoRoute *> QDeclarativeGeoRoute::legs() \since QtLocation 5.13 */ -QQmlPropertyMap *QDeclarativeGeoRoute::extendedAttributes() const +QVariantMap QDeclarativeGeoRoute::extendedAttributes() const { - if (!m_extendedAttributes) { - QDeclarativeGeoRoute *self = const_cast<QDeclarativeGeoRoute *>(this); - self->m_extendedAttributes = new QQmlPropertyMap(self); - // Fill it - const QVariantMap &xAttrs = route_.extendedAttributes(); - const QStringList &keys = xAttrs.keys(); - for (const QString &key: keys) - self->m_extendedAttributes->insert(key, xAttrs.value(key)); - } - return m_extendedAttributes; + return route_.extendedAttributes(); } /*! |