summaryrefslogtreecommitdiff
path: root/src/location/maps/qgeoroute_p.h
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-11 10:42:38 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-22 14:56:44 +0200
commit634d9772e52e24ad3709da1b5161c421c1a7370e (patch)
tree0ca1a58b44a78912ecbbe1848ab8df79eb15959f /src/location/maps/qgeoroute_p.h
parentd8f03e5e71de3d951f86f0b0413fd75d554b2039 (diff)
downloadqtlocation-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/maps/qgeoroute_p.h')
-rw-r--r--src/location/maps/qgeoroute_p.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/location/maps/qgeoroute_p.h b/src/location/maps/qgeoroute_p.h
index e2fa8a77..2eddb103 100644
--- a/src/location/maps/qgeoroute_p.h
+++ b/src/location/maps/qgeoroute_p.h
@@ -109,6 +109,7 @@ public:
virtual QString engineName() const = 0;
virtual int segmentsCount() const = 0;
+ virtual QList<QGeoRouteSegment> segments() const = 0;
// QGeoRouteLeg API
virtual void setLegIndex(int idx);
@@ -156,6 +157,7 @@ public:
QString engineName() const override;
int segmentsCount() const override;
+ QList<QGeoRouteSegment> segments() const override;
void setRouteLegs(const QList<QGeoRoute> &legs) override;
QList<QGeoRoute> routeLegs() const override;
@@ -169,6 +171,18 @@ public:
void setContainingRoute(const QGeoRoute &route) override;
QGeoRoute containingRoute() const override;
+private:
+ template<typename Functor>
+ inline void forEachSegment(Functor &&functor) const {
+ QGeoRouteSegment segment = m_firstSegment;
+ while (segment.isValid()) {
+ functor(segment);
+ // if containing route, this is a leg
+ if (segment.isLegLastSegment() && m_containingRoute)
+ break;
+ segment = segment.nextRouteSegment();
+ }
+ }
QString m_id;
QGeoRouteRequest m_request;