RoutingWaypoints WaypointParser::parse( QTextStream &stream ) const { RoutingWaypoints result; QString input = stream.readAll(); QStringList lines = input.split( m_lineSeparator ); foreach( const QString &line, lines ) { if ( !line.trimmed().isEmpty() && !line.trimmed().startsWith('#') && !line.startsWith( "Content-Type: text/plain") ) { QStringList entries = line.split( m_fieldSeparator ); if ( entries.size() >= 1 + m_fieldIndices[RoadName] ) { qreal lon = readField<qreal>( Longitude, entries ); qreal lat = readField<qreal>( Latitude, entries ); RoutingPoint point( lon, lat ); QString junctionTypeRaw = readField<QString>( JunctionType, entries, QString() ); RoutingWaypoint::JunctionType junctionType = RoutingWaypoint::Other; if ( m_junctionTypeMapping.contains( junctionTypeRaw ) ) { junctionType = m_junctionTypeMapping[junctionTypeRaw]; } QString roadType = readField<QString>( RoadType, entries, QString() ); int secondsRemaining = readField<int>( TotalSecondsRemaining, entries, -1 ); QString roadName = readField<QString>( RoadName, entries, QString() ); // Road names may contain the field separator for (int i = 2 + m_fieldIndices[RoadName]; i<entries.size(); ++i) { roadName += m_fieldSeparator + entries.at(i); } RoutingWaypoint item( point, junctionType, junctionTypeRaw, roadType, secondsRemaining, roadName ); result.push_back( item ); } else { qDebug() << "Cannot parse " << line << "(detected " << entries.size() << " fields)"; } } } 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; }