diff options
author | Alex Wilson <alex.wilson@nokia.com> | 2012-02-21 14:04:55 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-21 06:10:34 +0100 |
commit | f4f356df480943a00e08205a8cd389506931a0f7 (patch) | |
tree | 161c47f9b6a2bbf54f18c3f8da89e659952b468c /src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp | |
parent | ae21a43218da958c99fa9f5a13656f479020cf9f (diff) | |
download | qtlocation-f4f356df480943a00e08205a8cd389506931a0f7.tar.gz |
Fix up issues with parsing Route XML in Nokia plugin
This fixes some long-standing issues with route XML parsing in the
Nokia plugin, as well as adding a new autotest to verify that these
and other faults do not develop again in future.
The faulty logic in this case was to attempt to handle the final
maneuver in the route in the same manner as a link-less intermediate
point, which alternately caused the final maneuver to either be
dropped or a subsequent "empty" maneuver to be generated with the
remaining links at the end. The final maneuver is now handled
separately.
Task-number: QTBUG-24341
Task-number: QTBUG-20563
Change-Id: Iefc37c84170d23b4c4a9203f12f33994c7fa4a88
Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp')
-rw-r--r-- | src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp | 59 |
1 files changed, 19 insertions, 40 deletions
diff --git a/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp b/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp index 7d75b75b..ca5967ff 100644 --- a/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp +++ b/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp @@ -212,7 +212,9 @@ bool QGeoRouteXmlParser::postProcessRoute(QGeoRoute *route) int maneuverIndex = 0; for (int i = 0; i < segments.count(); ++i) { - while ((maneuverIndex < maneuvers.size()) && maneuvers.at(maneuverIndex).toId.isEmpty()) { + // In case there is a maneuver in the middle of the list with no + // link ID attached, attach it to the next available segment + while ((maneuverIndex < maneuvers.size() - 1) && maneuvers.at(maneuverIndex).toId.isEmpty()) { QGeoRouteSegment segment; segment.setManeuver(maneuvers.at(maneuverIndex).maneuver); QList<QGeoCoordinate> path; // use instruction position as one point segment path @@ -221,6 +223,7 @@ bool QGeoRouteXmlParser::postProcessRoute(QGeoRoute *route) routeSegments.append(segment); ++maneuverIndex; } + QGeoRouteSegment segment = segments.at(i).segment; if ((maneuverIndex < maneuvers.size()) && segments.at(i).id == maneuvers.at(maneuverIndex).toId) { segment.setManeuver(maneuvers.at(maneuverIndex).maneuver); @@ -229,6 +232,19 @@ bool QGeoRouteXmlParser::postProcessRoute(QGeoRoute *route) routeSegments.append(segment); } + // For the final maneuver in the list, make sure to attach it to the very + // last segment on the path, this is why we don't process the last + // maneuver in the loop above + while (maneuverIndex < maneuvers.size()) { + QGeoRouteSegment segment; + segment.setManeuver(maneuvers.at(maneuverIndex).maneuver); + QList<QGeoCoordinate> path; // use instruction position as one point segment path + path.append(maneuvers.at(maneuverIndex).maneuver.position()); + segment.setPath(path); + + routeSegments.append(segment); + ++maneuverIndex; + } QList<QGeoRouteSegment> compactedRouteSegments; compactedRouteSegments.append(routeSegments.first()); @@ -240,9 +256,9 @@ bool QGeoRouteXmlParser::postProcessRoute(QGeoRoute *route) QGeoRouteSegment lastSegment = compactedRouteSegments.last(); - if (lastSegment.maneuver().isValid()) + if (lastSegment.maneuver().isValid()) { compactedRouteSegments.append(segment); - else { + } else { compactedRouteSegments.removeLast(); lastSegment.setDistance(lastSegment.distance() + segment.distance()); lastSegment.setTravelTime(lastSegment.travelTime() + segment.travelTime()); @@ -254,43 +270,6 @@ bool QGeoRouteXmlParser::postProcessRoute(QGeoRoute *route) } } -// //Add the first instruction as starting point -// if (maneuvers.count() > 0) { -// QGeoRouteSegment segment; -// segment.setManeuver(maneuvers[0].maneuver); -// QList<QGeoCoordinate> path; // use instruction position as one point segment path -// path.append(maneuvers[0].maneuver.position()); -// segment.setPath(path); -// routesegments.append(segment); -// maneuvers.removeAt(0); -// } - -// for (int i = 0; i < segments.count(); ++i) { -// if (segments[i].maneuverId.isEmpty()) { -// routesegments.append(segments[i].segment); -// } else { -// for (int j = 0; j < maneuvers.count(); ++j) { -// if (maneuvers[j].id == segments[i].maneuverId -// && segments[i].segment.maneuver().instructionText().isEmpty()) { -// segments[i].segment.setManeuver(maneuvers[j].maneuver); -// routesegments.append(segments[i].segment); -// maneuvers.removeAt(j); -// break; -// } else { -// //Add orphan instruction into new empty segment -// QGeoRouteSegment segment; -// segment.setManeuver(maneuvers[j].maneuver); -// QList<QGeoCoordinate> path; // use instruction position as one point segment path -// path.append(maneuvers[j].maneuver.position()); -// segment.setPath(path); -// routesegments.append(segment); -// maneuvers.removeAt(j); -// --j; -// } -// } -// } -// } - if (compactedRouteSegments.size() > 0) { route->setFirstRouteSegment(compactedRouteSegments.at(0)); for (int i = 0; i < compactedRouteSegments.size() - 1; ++i) |