Ejemplo n.º 1
0
void MapBox::addFakeRoute(const QList<QGeoCoordinate> &waypoints, int segments)
{
    QGeoRoute route;

    int index = 0;
    QGeoRouteSegment lastSegment;
    for (int i = 0; i < segments; ++i) {
        QGeoRouteSegment segment;

        QList<QGeoCoordinate> path;

        int limit = (waypoints.size() * (i + 1)) / segments;
        for (; index < limit; ++index)
            path.append(waypoints.at(index));

        segment.setPath(path);

        if (i == 0)
            route.setFirstRouteSegment(segment);
        else
            lastSegment.setNextRouteSegment(segment);
        lastSegment = segment;
    }

    QPen pen(QColor(0, 0, 255, 127)); // blue, semi-transparent
    pen.setWidth(7);
    //pen.setCosmetic(true);
    pen.setCapStyle(Qt::RoundCap);

    QGeoMapRouteObject * routeObject = new QGeoMapRouteObject(route);

    routeObject->setPen(pen);

    m_mapWidget->addMapObject(routeObject);
}
Ejemplo n.º 2
0
bool QGeoRouteXmlParser::parseRootElement()
{
    if (!m_reader->readNextStartElement()) {
        m_reader->raiseError("Expected a root element named \"CalculateRoute\" (no root element found).");
        return false;
    }

    bool updateroute = false;
    if (m_reader->name() != "CalculateRoute" && m_reader->name() != "GetRoute")  {
        m_reader->raiseError(QString("The root element is expected to have the name \"CalculateRoute\" or \"GetRoute\" (root element was named \"%1\").").arg(m_reader->name().toString()));
        return false;
    } else if (m_reader->name() == "GetRoute") {
        updateroute = true;
    }

    if (m_reader->readNextStartElement()) {
        if (m_reader->name() != "Response") {
            m_reader->raiseError(QString("Expected a element named \"Response\" (element was named \"%1\").").arg(m_reader->name().toString()));
            return false;
        }
    }

    while (m_reader->readNextStartElement()) {
        if (m_reader->name() == "MetaInfo") {
            m_reader->skipCurrentElement();
        } else if (m_reader->name() == "Route") {
            QGeoRoute route;
            route.setRequest(m_request);
            if (updateroute)
                route.setTravelMode(QGeoRouteRequest::TravelMode(int(m_request.travelModes())));
            if (!parseRoute(&route))
                continue; //route parsing failed move on to the next
            m_results.append(route);
        } else if (m_reader->name() == "Progress") {
            //TODO: updated route progress
            m_reader->skipCurrentElement();
        } else {
            m_reader->raiseError(QString("Did not expect a child element named \"%1\".").arg(
                                     m_reader->name().toString()));
            return false;
        }
    }

    return true;
}
Ejemplo n.º 3
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]);
    }
}
Ejemplo n.º 4
0
QDeclarativeGeoRoute::QDeclarativeGeoRoute(const QGeoRoute &route, QObject *parent)
    : QObject(parent),
      route_(route)
{
    bounds_ = new QDeclarativeGeoBoundingBox(route.bounds(), this);

    for (int i = 0; i < route_.path().size(); ++i)
        path_.append(new QDeclarativeCoordinate(route_.path().at(i), this));

    QGeoRouteSegment segment = route_.firstRouteSegment();
    while (segment.isValid()) {
        segments_.append(new QDeclarativeGeoRouteSegment(segment, this));
        segment = segment.nextRouteSegment();
    }
}
QString QGeoRoutingManagerEngineNokia::updateRouteRequestString(const QGeoRoute &route, const QGeoCoordinate &position)
{
    if (!checkEngineSupport(route.request(), route.travelMode()))
        return "";

    QString requestString = "http://";
    requestString += m_host;
    requestString += "/routing/6.2/getroute.xml";

    requestString += "?routeid=";
    requestString += route.routeId();

    requestString += "&pos=";
    requestString += QString::number(position.latitude());
    requestString += ",";
    requestString += QString::number(position.longitude());

    requestString += modesRequestString(route.request(), route.travelMode());

    requestString += routeRequestString(route.request());

    return requestString;
}
Ejemplo n.º 6
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());

    }
}