• 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
  • lib
  • marble
GeoUriParser.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 2014 Levente Kurusa <levex@linux.com>
9 //
10 
11 #include <QString>
12 #include <QUrl>
13 #if QT_VERSION >= 0x050000
14 #include <QUrlQuery>
15 #endif
16 
17 #include "Planet.h"
18 #include "GeoUriParser.h"
19 #include "MarbleDebug.h"
20 
21 namespace Marble {
22 
23 GeoUriParser::GeoUriParser( const QString& geoUri )
24  : m_geoUri( geoUri ),
25  m_coordinates(),
26  m_planet( "earth" )
27 {
28 }
29 
30 void GeoUriParser::setGeoUri( const QString &geoUri )
31 {
32  m_geoUri = geoUri;
33  m_coordinates = GeoDataCoordinates();
34  m_planet = Planet( "earth" );
35 }
36 
37 QString GeoUriParser::geoUri() const
38 {
39  return m_geoUri;
40 }
41 
42 GeoDataCoordinates GeoUriParser::coordinates() const
43 {
44  return m_coordinates;
45 }
46 
47 Planet GeoUriParser::planet() const
48 {
49  return m_planet;
50 }
51 
52 QString GeoUriParser::queryValue(const QUrl& url, const QString& one, const QString& two)
53 {
54 #if QT_VERSION < 0x050000
55  QString value = url.queryItemValue( one );
56  if ( value.isEmpty() && !two.isEmpty() ) {
57  value = url.queryItemValue( two );
58  }
59  return value;
60 #else
61  QUrlQuery query( url );
62  if ( query.hasQueryItem( one ) ) {
63  return query.queryItemValue( one );
64  } else if ( query.hasQueryItem( two ) ) {
65  return query.queryItemValue( two );
66  }
67 
68  return QString();
69 #endif
70 }
71 
72 bool GeoUriParser::parse()
73 {
74  if ( m_geoUri.isEmpty() ) {
75  return false;
76  }
77 
78  QString const floatRegexp = "[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?";
79 
80  QRegExp geoUriRegexp( "geo:(" + floatRegexp + "),(" + floatRegexp + "),?(" + floatRegexp + ")?(?:;(crs|u)=([\\w\\d-]+))?(?:;(crs|u)=([\\w\\d-]+))?" , Qt::CaseInsensitive, QRegExp::RegExp2 );
81 
82 
83  if ( geoUriRegexp.indexIn( m_geoUri ) > -1 && geoUriRegexp.captureCount() > 1 ) {
84  double const lat = geoUriRegexp.capturedTexts()[1].toDouble();
85  double const lon = geoUriRegexp.capturedTexts()[2].toDouble();
86  double const alt = geoUriRegexp.captureCount() > 2 ? geoUriRegexp.capturedTexts()[3].toDouble() : 0.0;
87 
88  if ( geoUriRegexp.captureCount() > 3 ) {
89  // this is not a bug! The '<=' was intended, otherwise we would skip that last Cgroups's data!
90  for ( int i = 4; i <= geoUriRegexp.captureCount(); ++i )
91  {
92  if ( geoUriRegexp.capturedTexts()[i] == "crs" ) {
93  foreach ( const QString& str, Planet::planetList()) {
94  if ( geoUriRegexp.captureCount() < i+1 ) {
95  i = geoUriRegexp.captureCount() + 1;
96  break;
97  }
98  if ( geoUriRegexp.capturedTexts()[i+1].contains(str, Qt::CaseInsensitive) ) {
99  m_planet = Planet( str );
100  break;
101  }
102  }
103  ++i;
104  } else if ( geoUriRegexp.capturedTexts()[i] == "u" ) {
105  mDebug() << "Captured uncertainity parameter, but this is not supported by Marble (yet).";
106  ++i;
107  }
108  }
109  }
110  GeoDataCoordinates const coordinates( lon, lat, alt, GeoDataCoordinates::Degree );
111  if ( coordinates.isValid() ) {
112  m_coordinates = coordinates;
113  return true;
114  }
115  }
116  if ( m_geoUri.startsWith("worldwind://goto/") ) {
117  m_geoUri = m_geoUri.replace("goto/", "goto/?");
118  QUrl worldwindUrl( m_geoUri );
119 
120  double lat = queryValue(worldwindUrl, "lat", "latitude").toDouble();
121  double lon = queryValue(worldwindUrl, "lon", "longitude").toDouble();
122  double alt = queryValue(worldwindUrl, "alt", "altitude").toDouble();
123  //double bank = getDoubleFromParameter(worldwindUrl, "bank", "");
124  //double dir = getDoubleFromParameter(worldwindUrl, "dir", "direction");
125  //double tilt = getDoubleFromParameter(worldwindUrl, "tilt", "");
126  //QString layer = worldwindUrl.queryItemValue("layer");
127  QString world = queryValue(worldwindUrl, "world");
128 
129  foreach ( const QString& str, Planet::planetList()) {
130  if ( world.contains(str, Qt::CaseInsensitive) ) {
131  m_planet = Planet( str );
132  break;
133  }
134  }
135 
136  GeoDataCoordinates const coordinates( lon, lat, alt, GeoDataCoordinates::Degree );
137  if ( coordinates.isValid() ) {
138  m_coordinates = coordinates;
139  return true;
140  }
141  }
142 
143  return false;
144 }
145 
146 }
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
Planet.h
QString::toDouble
double toDouble(bool *ok) const
MarbleDebug.h
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::Planet::planetList
static QStringList planetList()
Definition: Planet.cpp:373
QRegExp::indexIn
int indexIn(const QString &str, int offset, CaretMode caretMode) const
QRegExp
QRegExp::captureCount
int captureCount() const
QRegExp::capturedTexts
QStringList capturedTexts() const
QString::isEmpty
bool isEmpty() const
Marble::Planet
Definition: Planet.h:25
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
Marble::GeoUriParser::geoUri
QString geoUri() const
Returns the Geo URI stored in this parser.
Definition: GeoUriParser.cpp:37
QString
Marble::GeoUriParser::parse
bool parse()
Parse the given Geo URI.
Definition: GeoUriParser.cpp:72
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QUrl
QString::replace
QString & replace(int position, int n, QChar after)
Marble::GeoUriParser::coordinates
GeoDataCoordinates coordinates() const
Returns the coordinates parsed.
Definition: GeoUriParser.cpp:42
Marble::GeoUriParser::GeoUriParser
GeoUriParser(const QString &geoUri=QString())
Constructs a new GeoUriParser with the given Geo URI.
Definition: GeoUriParser.cpp:23
Marble::GeoUriParser::planet
Planet planet() const
Returns the Planet on which the coordinates are valid.
Definition: GeoUriParser.cpp:47
Marble::GeoUriParser::setGeoUri
void setGeoUri(const QString &geoUri)
Set the Geo URI to be parsed.
Definition: GeoUriParser.cpp:30
Marble::GeoDataCoordinates::isValid
bool isValid() const
Returns.
Definition: GeoDataCoordinates.cpp:624
GeoUriParser.h
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
QUrl::queryItemValue
QString queryItemValue(const QString &key) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 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