Esempio n. 1
0
void RoutePresenter::showRoute(QTreeWidgetItem* top, const QGeoRoute& route)
{
    QTreeWidgetItem* routeItem = new QTreeWidgetItem(top);
    routeItem->setText(0, "route");

    QTreeWidgetItem* idItem = 0;
    if (!route.routeId().isEmpty()) {
        idItem = new QTreeWidgetItem(routeItem);
        idItem->setText(0, "id");
        idItem->setText(1, route.routeId());
    }

    QTreeWidgetItem* modeItem = new QTreeWidgetItem(routeItem);
    modeItem->setText(0, "mode");
    showModes(modeItem, route.request(), route.travelMode());

    QTreeWidgetItem* distanceItem = new QTreeWidgetItem(routeItem);
    distanceItem->setText(0, "distance");
    distanceItem->setText(1, QString().setNum(route.distance()));

    showBoundingBox(routeItem, route.bounds());

    QTreeWidgetItem* wayPointsItem = new QTreeWidgetItem(routeItem);
    QString overviewLabel = "overview";
    if (route.path().count() > 100)
        overviewLabel += "(100)";
    wayPointsItem->setText(0, overviewLabel);
    showPoints(wayPointsItem, route.path());

    QList<QGeoRouteSegment> segments;
    QGeoRouteSegment segment = route.firstRouteSegment();
    while (segment.isValid()) {
        segments << segment;
        segment = segment.nextRouteSegment();
    }

    QTreeWidgetItem* segmentsItem = new QTreeWidgetItem(routeItem);
    QString segmentsLabel = "segments";
    if (segments.length() > 100)
        segmentsLabel += "(100)";

    segmentsItem->setText(0, segmentsLabel);

    segmentsItem->setText(1, QString().setNum(segments.length()));
    for (int i = 0; i < segments.length() && i < 100; ++i) {
        showRouteSegment(segmentsItem, segments[i]);
    }
}
Esempio n. 2
0
void GeoHelper::routingFinishedSlot(QGeoRouteReply * reply)
{

    if (reply->error() == QGeoRouteReply::NoError)
    {
        QScriptEngine scriptEngine;
        QScriptValue replyObject = scriptEngine.newArray();

        QList<QGeoCoordinate> waypoints = reply->request().waypoints();
        double lat1 = 0;
        double lon1 = 0;
        double lat2 = 0;
        double lon2 = 0;

        if (waypoints.count() > 0)
        {
            /*
            QString msg = QString("lat %1, lon %2 => lat %3, lon %4").
                    arg(waypoints.at(0).latitude()).arg(waypoints.at(0).longitude()).
                    arg(waypoints.at((waypoints.count()-1)).latitude()).arg(waypoints.at((waypoints.count()-1)).longitude());
            emit routingError(msg);
            */
            lat1 = waypoints.at(0).latitude();
            lon1 = waypoints.at(0).longitude();
            lat2 = waypoints.at((waypoints.count()-1)).latitude();
            lon2 = waypoints.at((waypoints.count()-1)).longitude();

        }


        for (int i = 0; i < reply->routes().size(); ++i)
        {
            QScriptValue routeObject = scriptEngine.newObject();
            QGeoRoute route = reply->routes().at(i);

            routeObject.setProperty("distance", QScriptValue(route.distance()));
            routeObject.setProperty("travelTime", QScriptValue(route.travelTime()));
            routeObject.setProperty("lat1", QScriptValue(lat1));
            routeObject.setProperty("lon1", QScriptValue(lon1));
            routeObject.setProperty("lat2", QScriptValue(lat2));
            routeObject.setProperty("lon2", QScriptValue(lon2));


            QScriptValue pathObject = scriptEngine.newArray();
            QList<QGeoCoordinate> path = route.path();
            for (int p = 0; p < path.length(); p++)
            {
                QScriptValue coordinateObject = scriptEngine.newObject();
                coordinateObject.setProperty("latitude", QScriptValue(path[p].latitude()));
                coordinateObject.setProperty("longitude", QScriptValue(path[p].longitude()));
                pathObject.setProperty(p, coordinateObject);

            }

            routeObject.setProperty("path", pathObject);

            replyObject.setProperty(i, routeObject);

        }

        QScriptValue fun = scriptEngine.evaluate("(function(a) { return JSON.stringify(a); })");
        QScriptValueList args;
        args << replyObject;
        QScriptValue result = fun.call(QScriptValue(), args);

        emit routingReply(result.toString());

    }
}