QStringList QGeoRoutingManagerEngineNokia::calculateRouteRequestString(const QGeoRouteRequest &request) { bool supported = checkEngineSupport(request, request.travelModes()); if (!supported) return QStringList(); QStringList requests; QString baseRequest = QStringLiteral("http://"); baseRequest += m_uriProvider->getCurrentHost(); baseRequest += QStringLiteral("/routing/7.2/calculateroute.xml"); baseRequest += QStringLiteral("?alternatives="); baseRequest += QString::number(request.numberAlternativeRoutes()); if (!m_appId.isEmpty() && !m_token.isEmpty()) { baseRequest += QStringLiteral("&app_id="); baseRequest += m_appId; baseRequest += QStringLiteral("&token="); baseRequest += m_token; } int numWaypoints = request.waypoints().size(); if (numWaypoints < 2) return QStringList(); for (int i = 0;i < numWaypoints;++i) { baseRequest += QStringLiteral("&waypoint"); baseRequest += QString::number(i); baseRequest += QStringLiteral("=geo!"); baseRequest += trimDouble(request.waypoints().at(i).latitude()); baseRequest += ','; baseRequest += trimDouble(request.waypoints().at(i).longitude()); } QGeoRouteRequest::RouteOptimizations optimization = request.routeOptimization(); QStringList types; if (optimization.testFlag(QGeoRouteRequest::ShortestRoute)) types.append("shortest"); if (optimization.testFlag(QGeoRouteRequest::FastestRoute)) types.append("fastest"); foreach (const QString &optimization, types) { QString requestString = baseRequest; requestString += modesRequestString(request, request.travelModes(), optimization); requestString += routeRequestString(request); requests << requestString; }
QString QGeoRoutingManagerEngineNokia::modesRequestString(const QGeoRouteRequest &request, QGeoRouteRequest::TravelModes travelModes) const { QString requestString; QGeoRouteRequest::RouteOptimizations optimization = request.routeOptimization(); QStringList types; if (optimization.testFlag(QGeoRouteRequest::ShortestRoute)) types.append("shortest"); if (optimization.testFlag(QGeoRouteRequest::FastestRoute)) types.append("fastestNow"); if (optimization.testFlag(QGeoRouteRequest::MostEconomicRoute)) types.append("economic"); if (optimization.testFlag(QGeoRouteRequest::MostScenicRoute)) types.append("scenic"); QStringList modes; if (travelModes.testFlag(QGeoRouteRequest::CarTravel)) modes.append("car"); if (travelModes.testFlag(QGeoRouteRequest::PedestrianTravel)) modes.append("pedestrian"); if (travelModes.testFlag(QGeoRouteRequest::PublicTransitTravel)) modes.append("publicTransport"); QStringList featureStrings; QList<QGeoRouteRequest::FeatureType> featureTypes = request.featureTypes(); for (int i = 0; i < featureTypes.size(); ++i) { QGeoRouteRequest::FeatureWeight weight = request.featureWeight(featureTypes.at(i)); if (weight == QGeoRouteRequest::NeutralFeatureWeight) continue; QString weightString = ""; switch (weight) { case QGeoRouteRequest::PreferFeatureWeight: weightString = "1"; break; case QGeoRouteRequest::AvoidFeatureWeight: weightString = "-1"; break; case QGeoRouteRequest::DisallowFeatureWeight: weightString = "-3"; break; } if (weightString.isEmpty()) continue; switch (featureTypes.at(i)) { case QGeoRouteRequest::TollFeature: featureStrings.append("tollroad:" + weightString); break; case QGeoRouteRequest::HighwayFeature: featureStrings.append("motorway:" + weightString); break; case QGeoRouteRequest::FerryFeature: featureStrings.append("boatFerry:" + weightString); featureStrings.append("railFerry:" + weightString); break; case QGeoRouteRequest::TunnelFeature: featureStrings.append("tunnel:" + weightString); break; case QGeoRouteRequest::DirtRoadFeature: featureStrings.append("dirtRoad:" + weightString); break; } } for (int i = 0;i < types.count();++i) { requestString += "&mode" + QString::number(i) + "="; requestString += types[i] + ";" + modes.join(","); if (featureStrings.count()) requestString += ";" + featureStrings.join(","); } return requestString; }
void RoutePresenter::showModes(QTreeWidgetItem* top, const QGeoRouteRequest &request, QGeoRouteRequest::TravelModes travelModes) { QTreeWidgetItem* optimizationItem = new QTreeWidgetItem(top); optimizationItem->setText(0, "optimization"); QGeoRouteRequest::RouteOptimizations optimization = request.routeOptimization(); if (optimization.testFlag(QGeoRouteRequest::ShortestRoute)) { QTreeWidgetItem* shortestRouteItem = new QTreeWidgetItem(optimizationItem); shortestRouteItem->setText(1, "ShortestRoute"); } if (optimization.testFlag(QGeoRouteRequest::FastestRoute)) { QTreeWidgetItem* fastestRouteItem = new QTreeWidgetItem(optimizationItem); fastestRouteItem->setText(1, "FastestRoute"); } if (optimization.testFlag(QGeoRouteRequest::MostEconomicRoute)) { QTreeWidgetItem* economicRouteItem = new QTreeWidgetItem(optimizationItem); economicRouteItem->setText(1, "MostEconomicRoute"); } if (optimization.testFlag(QGeoRouteRequest::MostScenicRoute)) { QTreeWidgetItem* scenicRouteItem = new QTreeWidgetItem(optimizationItem); scenicRouteItem->setText(1, "MostScenicRoute"); } QTreeWidgetItem* travelModeItem = new QTreeWidgetItem(top); travelModeItem->setText(0, "travel mode"); if (travelModes.testFlag(QGeoRouteRequest::CarTravel)) { QTreeWidgetItem* carTravelItem = new QTreeWidgetItem(travelModeItem); carTravelItem->setText(1, "CarTravel"); } if (travelModes.testFlag(QGeoRouteRequest::PedestrianTravel)) { QTreeWidgetItem* pedestrianTravelItem = new QTreeWidgetItem(travelModeItem); pedestrianTravelItem->setText(1, "PedestrianTravel"); } if (travelModes.testFlag(QGeoRouteRequest::PublicTransitTravel)) { QTreeWidgetItem* transitTravelItem = new QTreeWidgetItem(travelModeItem); transitTravelItem->setText(1, "PublicTransitTravel"); } if (travelModes.testFlag(QGeoRouteRequest::BicycleTravel)) { QTreeWidgetItem* bicycleTravelItem = new QTreeWidgetItem(travelModeItem); bicycleTravelItem->setText(1, "BicycleTravel"); } if (travelModes.testFlag(QGeoRouteRequest::TruckTravel)) { QTreeWidgetItem* truckTravelItem = new QTreeWidgetItem(travelModeItem); truckTravelItem->setText(1, "TruckTravel"); } QTreeWidgetItem* featuresItem = new QTreeWidgetItem(top); featuresItem->setText(0, "features"); QList<QGeoRouteRequest::FeatureType> featureTypeList = request.featureTypes(); for (int i = 0; i < featureTypeList.size(); ++i) { QGeoRouteRequest::FeatureWeight weight = request.featureWeight(featureTypeList.at(i)); if (weight == QGeoRouteRequest::NeutralFeatureWeight) continue; QString labelString = ""; switch (weight) { case QGeoRouteRequest::PreferFeatureWeight: labelString = "Prefer"; break; case QGeoRouteRequest::AvoidFeatureWeight: labelString = "Avoid"; break; case QGeoRouteRequest::DisallowFeatureWeight: labelString = "Disallow"; break; } if (labelString.isEmpty()) continue; labelString += " "; switch (featureTypeList.at(i)) { case QGeoRouteRequest::TollFeature: labelString += "tolls"; break; case QGeoRouteRequest::HighwayFeature: labelString += "highways"; break; case QGeoRouteRequest::PublicTransitFeature: labelString += "public transit"; break; case QGeoRouteRequest::FerryFeature: labelString += "ferries"; break; case QGeoRouteRequest::TunnelFeature: labelString += "tunnels"; break; case QGeoRouteRequest::DirtRoadFeature: labelString += "dirt roads"; break; case QGeoRouteRequest::ParksFeature: labelString += "parks"; break; case QGeoRouteRequest::MotorPoolLaneFeature: labelString += "motor pool lanes"; break; default: labelString = ""; break; } if (labelString.isEmpty()) continue; QTreeWidgetItem* item = new QTreeWidgetItem(featuresItem); item->setText(1, labelString); } }