• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • plugins
  • render
  • weather
StationListParser.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2009 Bastian Holst <bastianholst@gmx.de>
9 //
10 
11 // Self
12 #include "StationListParser.h"
13 
14 // Marble
15 #include "MarbleGlobal.h"
16 #include "BBCStation.h"
17 #include "GeoDataCoordinates.h"
18 #include "MarbleDebug.h"
19 
20 // Qt
21 #include <QFile>
22 #include <QString>
23 
24 using namespace Marble;
25 
26 StationListParser::StationListParser( QObject *parent )
27  : QThread( parent ),
28  QXmlStreamReader()
29 {
30 }
31 
32 StationListParser::~StationListParser()
33 {
34  wait( 1000 );
35 }
36 
37 void StationListParser::read()
38 {
39  m_list.clear();
40 
41  while ( !atEnd() ) {
42  readNext();
43 
44  if ( isStartElement() ) {
45  if ( name() == "StationList" )
46  readStationList();
47  else
48  raiseError( QObject::tr("The file is not a valid file.") );
49  }
50  }
51 }
52 
53 QList<BBCStation> StationListParser::stationList() const
54 {
55  return m_list;
56 }
57 
58 void StationListParser::setPath( QString path )
59 {
60  m_path = path;
61 }
62 
63 void StationListParser::run()
64 {
65  QFile file( m_path );
66 
67  if( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
68  return;
69  }
70 
71  setDevice( &file );
72  read();
73 }
74 
75 void StationListParser::readUnknownElement()
76 {
77  Q_ASSERT( isStartElement() );
78 
79  while ( !atEnd() ) {
80  readNext();
81 
82  if ( isEndElement() )
83  break;
84 
85  if ( isStartElement() )
86  readUnknownElement();
87  }
88 }
89 
90 void StationListParser::readStationList()
91 {
92  Q_ASSERT( isStartElement()
93  && name() == "StationList" );
94 
95  while( !atEnd() ) {
96  readNext();
97 
98  if( isEndElement() )
99  break;
100 
101  if( isStartElement() ) {
102  if( name() == "Station" )
103  readStation();
104  else
105  readUnknownElement();
106  }
107  }
108 }
109 
110 void StationListParser::readStation()
111 {
112  Q_ASSERT( isStartElement()
113  && name() == "Station" );
114 
115  BBCStation station;
116 
117  while ( !atEnd() ) {
118  readNext();
119 
120  if( isEndElement() )
121  break;
122 
123  if( isStartElement() ) {
124  if( name() == "name" )
125  station.setName( readCharacters() );
126  else if ( name() == "id" )
127  station.setBbcId( readCharacters().toLong() );
128  else if ( name() == "priority" )
129  station.setPriority( readCharacters().toInt() );
130  else if ( name() == "Point" )
131  readPoint( &station );
132  else
133  readUnknownElement();
134  }
135  }
136 
137  // This find the right position in the sorted to insert the new item
138  QList<BBCStation>::iterator i = qLowerBound( m_list.begin(),
139  m_list.end(),
140  station );
141  // Insert the item on the right position in the list
142  m_list.insert( i, station );
143 }
144 
145 QString StationListParser::readCharacters()
146 {
147  Q_ASSERT( isStartElement() );
148 
149  QString string;
150 
151  while ( !atEnd() ) {
152  readNext();
153 
154  if ( isEndElement() )
155  break;
156 
157  if ( isStartElement() ) {
158  readUnknownElement();
159  }
160 
161  if ( isCharacters() ) {
162  string = text().toString();
163  }
164  }
165 
166  return string;
167 }
168 
169 void StationListParser::readPoint( BBCStation *station )
170 {
171  Q_ASSERT( isStartElement()
172  && name() == "Point" );
173 
174  while ( !atEnd() ) {
175  readNext();
176 
177  if ( isEndElement() )
178  break;
179 
180  if ( isStartElement() ) {
181  if ( name() == "coordinates" ) {
182  QString coorString = readCharacters();
183  QStringList coorList = coorString.split( ',' );
184 
185  if ( coorList.size() >= 2 ) {
186  GeoDataCoordinates coordinates( coorList.at( 0 ).toFloat() * DEG2RAD,
187  coorList.at( 1 ).toFloat() * DEG2RAD );
188  station->setCoordinate( coordinates );
189  }
190  }
191  else
192  readUnknownElement();
193  }
194  }
195 }
196 
197 #include "StationListParser.moc"
QXmlStreamReader::atEnd
bool atEnd() const
GeoDataCoordinates.h
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::BBCStation::setCoordinate
void setCoordinate(const GeoDataCoordinates &coordinate)
Definition: BBCStation.cpp:110
Marble::BBCStation::setName
void setName(const QString &name)
Definition: BBCStation.cpp:99
Marble::StationListParser::read
void read()
Definition: StationListParser.cpp:37
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QStringRef::toString
QString toString() const
QList::at
const T & at(int i) const
Marble::StationListParser::setPath
void setPath(QString path)
Definition: StationListParser.cpp:58
QXmlStreamReader::setDevice
void setDevice(QIODevice *device)
MarbleDebug.h
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
Marble::StationListParser::StationListParser
StationListParser(QObject *parent)
Definition: StationListParser.cpp:26
QFile
QXmlStreamReader::raiseError
void raiseError(const QString &message)
Marble::StationListParser::run
void run()
Definition: StationListParser.cpp:63
QList::size
int size() const
BBCStation.h
StationListParser.h
QObject
Marble::BBCStation::setPriority
void setPriority(quint8 priority)
Definition: BBCStation.cpp:132
QXmlStreamReader::isCharacters
bool isCharacters() const
Marble::BBCStation::setBbcId
void setBbcId(quint32 id)
Definition: BBCStation.cpp:121
QString
QList
MarbleGlobal.h
QXmlStreamReader::readNext
TokenType readNext()
Marble::DEG2RAD
const qreal DEG2RAD
Definition: MarbleGlobal.h:219
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QList::iterator
QStringList
QXmlStreamReader
Marble::BBCStation
Definition: BBCStation.h:24
QXmlStreamReader::isStartElement
bool isStartElement() const
QThread::wait
bool wait(unsigned long time)
QXmlStreamReader::text
QStringRef text() const
Marble::StationListParser::~StationListParser
~StationListParser()
Definition: StationListParser.cpp:32
Marble::StationListParser::stationList
QList< BBCStation > stationList() const
Definition: StationListParser.cpp:53
QThread
QXmlStreamReader::name
QStringRef name() const
QXmlStreamReader::isEndElement
bool isEndElement() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal