4 #include <QXmlStreamReader>
8 RoutePrivate::RoutePrivate( QObject *parent ) :
17 RoutePrivate::~RoutePrivate()
21 QList<RouteData> RoutePrivate::parseReply( const QByteArray &reply )
23 qDebug() << "parsing route";
25 QList<RouteData> retVal;
28 QXmlStreamReader xml( reply );
30 bool haveLine = false;
31 bool haveTime = false;
35 while ( !xml.atEnd() ) {
37 if ( xml.isStartElement() && xml.name() == "LINE" ) {
38 QString lineCode( xml.attributes().value("code").toString() );
40 routeData.lineCode = parseJORECode( lineCode );
45 if ( inLine && xml.name() == "STOP" ) {
48 if ( inLine && inStop && xml.name() == "ARRIVAL" ) {
49 QString arrivalTime( xml.attributes().value("time").toString() );
51 routeData.arrivalTime = arrivalTime.rightJustified(4).insert(2,":");
56 if ( xml.isEndElement() && xml.name() == "STOP" ) {
60 if ( xml.isEndElement() && xml.name() == "LINE" ) {
65 if ( haveLine && haveTime ) {
66 retVal.append( routeData );
68 // only want first STOP per LINE
74 if ( xml.hasError() ) {
75 qDebug() << "xml error";
78 if ( retVal.isEmpty() ) {
79 qDebug() << "no routes found";
85 void RoutePrivate::setFromLocation( const Location &location )
87 m_fromLocation = location;
91 const Location &RoutePrivate::fromLocation()
93 return m_fromLocation;
96 void RoutePrivate::setToLocation( const Location &toLocation )
98 m_toLocation = toLocation;
102 QString RoutePrivate::parseJORECode( const QString &joreCode ) const
106 QString areaTransportTypeCode( joreCode.mid(0,1) );
107 QString lineCode( joreCode.mid(1,3) );
108 QString letterVariant( joreCode.mid(4,1) );
109 QString letterNumberVariant( joreCode.mid(5,1) );
110 QString direction( joreCode.mid(6,1) );
112 lineCode.setNum( lineCode.toInt() );
116 if ( letterVariant != " " ) {
117 retVal += letterVariant;
123 const Location &RoutePrivate::toLocation()
128 bool RoutePrivate::fromValid()
133 bool RoutePrivate::toValid()