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;
}
Exemple #2
0
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);
    }
}