• 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
  • photo
CoordinatesParser.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 "CoordinatesParser.h"
13 
14 // Marble
15 #include "GeoDataCoordinates.h"
16 
17 using namespace Marble;
18 
19 CoordinatesParser::CoordinatesParser( GeoDataCoordinates *coordinates )
20  : m_coordinates( coordinates )
21 {
22 }
23 
24 bool CoordinatesParser::read( QIODevice *device )
25 {
26  setDevice( device );
27 
28  while( !atEnd() ) {
29  readNext();
30 
31  if( isStartElement() ) {
32  if ( name() == "rsp" && attributes().value( "stat" ) == "ok" )
33  readRsp();
34  else if ( name() == "rsp" )
35  raiseError( QObject::tr("Query failed") );
36  else
37  raiseError( QObject::tr("The file is not a valid Flickr answer.") );
38  }
39  }
40 
41  return !error();
42 }
43 
44 
45 void CoordinatesParser::readUnknownElement()
46 {
47  Q_ASSERT( isStartElement() );
48 
49  while ( !atEnd() ) {
50  readNext();
51 
52  if ( isEndElement() )
53  break;
54 
55  if ( isStartElement() )
56  readUnknownElement();
57  }
58 }
59 
60 void CoordinatesParser::readRsp()
61 {
62  Q_ASSERT( isStartElement() );
63 
64  while( !atEnd() ) {
65  readNext();
66 
67  if( isEndElement() )
68  break;
69 
70  if( isStartElement() ) {
71  if( name() == "photo" )
72  readPhoto();
73  else
74  readUnknownElement();
75  }
76  }
77 }
78 
79 void CoordinatesParser::readPhoto()
80 {
81  Q_ASSERT( isStartElement()
82  && name() == "photo" );
83 
84  while( !atEnd() ) {
85  readNext();
86 
87  if( isEndElement() )
88  break;
89 
90  if( isStartElement() ) {
91  if( name() == "location" )
92  readLocation();
93  else
94  readUnknownElement();
95  }
96  }
97 }
98 
99 void CoordinatesParser::readLocation()
100 {
101  Q_ASSERT( isStartElement()
102  && name() == "location" );
103 
104  m_coordinates->setLatitude( attributes().value( "latitude" ).toString().toDouble() * DEG2RAD );
105  m_coordinates->setLongitude( attributes().value( "longitude" ).toString().toDouble() * DEG2RAD );
106 
107  while( !atEnd() ) {
108  readNext();
109 
110  if( isEndElement() )
111  break;
112 
113  if( isStartElement() )
114  break;
115  }
116 }
QIODevice
QXmlStreamReader::atEnd
bool atEnd() const
GeoDataCoordinates.h
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
CoordinatesParser.h
QXmlStreamReader::error
Error error() const
QXmlStreamReader::setDevice
void setDevice(QIODevice *device)
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
QXmlStreamReader::raiseError
void raiseError(const QString &message)
Marble::CoordinatesParser::read
bool read(QIODevice *device)
Definition: CoordinatesParser.cpp:24
QXmlStreamReader::readNext
TokenType readNext()
Marble::DEG2RAD
const qreal DEG2RAD
Definition: MarbleGlobal.h:219
Marble::CoordinatesParser::CoordinatesParser
CoordinatesParser(GeoDataCoordinates *coordinates)
Definition: CoordinatesParser.cpp:19
Marble::GeoDataCoordinates::setLatitude
void setLatitude(qreal lat, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
set the longitude in a GeoDataCoordinates object
Definition: GeoDataCoordinates.cpp:699
Marble::GeoDataCoordinates::setLongitude
void setLongitude(qreal lon, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
set the longitude in a GeoDataCoordinates object
Definition: GeoDataCoordinates.cpp:679
QXmlStreamReader::isStartElement
bool isStartElement() const
QTest::toString
char * toString(const T &value)
QXmlStreamReader::attributes
QXmlStreamAttributes attributes() const
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:38 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