QVector<GeoDataPlacemark*> GosmoreRunnerPrivate::parseGosmoreInstructions( const QByteArray &content ) { // Determine gosmore version QStringList lines = QString::fromUtf8(content).split(QLatin1Char('\r')); if ( lines.size() > 2 ) { const QStringList fields = lines.at(lines.size()-2).split(QLatin1Char(',')); m_parser.setFieldIndex( WaypointParser::RoadName, fields.size()-1 ); if ( fields.size() < 5 || fields.size() > 6 ) { // Can happen when gosmore changes the output format, returns garbage // or the last street name contains a comma. We may still parse it correctly, just try. mDebug() << "Unexpected number of fields. This gosmore version may be unsupported."; } } QVector<GeoDataPlacemark*> result; QTextStream stream( content ); stream.setCodec("UTF8"); stream.setAutoDetectUnicode( true ); RoutingInstructions directions = InstructionTransformation::process( m_parser.parse( stream ) ); for( int i=0; i<directions.size(); ++i ) { GeoDataPlacemark* placemark = new GeoDataPlacemark( directions[i].instructionText() ); GeoDataExtendedData extendedData; GeoDataData turnType; turnType.setName(QStringLiteral("turnType")); turnType.setValue( qVariantFromValue<int>( int( directions[i].turnType() ) ) ); extendedData.addValue( turnType ); GeoDataData roadName; roadName.setName(QStringLiteral("roadName")); roadName.setValue( directions[i].roadName() ); extendedData.addValue( roadName ); placemark->setExtendedData( extendedData ); Q_ASSERT( !directions[i].points().isEmpty() ); GeoDataLineString* geometry = new GeoDataLineString; QVector<RoutingWaypoint> items = directions[i].points(); for (int j=0; j<items.size(); ++j ) { RoutingPoint point = items[j].point(); GeoDataCoordinates coordinates( point.lon(), point.lat(), 0.0, GeoDataCoordinates::Degree ); geometry->append( coordinates ); } placemark->setGeometry( geometry ); result.push_back( placemark ); } return result; }
int MonavRunnerPrivate::retrieveRoute( const Marble::RouteRequest* route, QVector< Marble::GeoDataPlacemark* >* instructions, Marble::GeoDataLineString* geometry ) const { RoutingResult reply; if ( retrieveData( route, &reply ) ) { /** @todo: make use of reply.seconds, the estimated travel time */ for ( int i = 0; i < reply.pathNodes.size(); ++i ) { qreal lon = reply.pathNodes[i].longitude; qreal lat = reply.pathNodes[i].latitude; GeoDataCoordinates coordinates( lon, lat, 0, GeoDataCoordinates::Degree ); geometry->append( coordinates ); } RoutingWaypoints waypoints; int k = 0; for ( int i = 0; i < reply.pathEdges.size(); ++i ) { QString road = reply.nameStrings[reply.pathEdges[i].name]; QString type = reply.typeStrings[reply.pathEdges[i].type]; RoutingWaypoint::JunctionType junction = RoutingWaypoint::Other; if (type == QLatin1String("roundabout") && reply.pathEdges[i].branchingPossible) { junction = RoutingWaypoint::Roundabout; } for ( unsigned int l = 0; l < reply.pathEdges[i].length; ++k, ++l ) { qreal lon = reply.pathNodes[k].longitude; qreal lat = reply.pathNodes[k].latitude; RoutingPoint point( lon, lat ); bool const last = l == reply.pathEdges[i].length - 1; RoutingWaypoint::JunctionType finalJunction = last ? junction : ( reply.pathEdges[i].branchingPossible ? RoutingWaypoint::Other : RoutingWaypoint::None ); RoutingWaypoint waypoint( point, finalJunction, "", type, -1, road ); waypoints.push_back( waypoint ); } } RoutingInstructions directions = InstructionTransformation::process( waypoints ); for ( int i = 0; i < directions.size(); ++i ) { GeoDataPlacemark* placemark = new GeoDataPlacemark( directions[i].instructionText() ); GeoDataExtendedData extendedData; GeoDataData turnType; turnType.setName(QStringLiteral("turnType")); turnType.setValue( qVariantFromValue<int>( int( directions[i].turnType() ) ) ); extendedData.addValue( turnType ); GeoDataData roadName; roadName.setName(QStringLiteral("roadName")); roadName.setValue( directions[i].roadName() ); extendedData.addValue( roadName ); placemark->setExtendedData( extendedData ); Q_ASSERT( !directions[i].points().isEmpty() ); GeoDataLineString* geometry = new GeoDataLineString; QVector<RoutingWaypoint> items = directions[i].points(); for ( int j = 0; j < items.size(); ++j ) { RoutingPoint point = items[j].point(); GeoDataCoordinates coordinates( point.lon(), point.lat(), 0.0, GeoDataCoordinates::Degree ); geometry->append( coordinates ); } placemark->setGeometry( geometry ); instructions->push_back( placemark ); } int duration = (int) reply.seconds; return duration; } return 0; }