• 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
  • runner
  • log
LogRunner.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 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
9 
10 #include "LogRunner.h"
11 
12 #include "GeoDataDocument.h"
13 #include "GeoDataLineString.h"
14 #include "GeoDataPlacemark.h"
15 #include "MarbleDebug.h"
16 
17 #include <QFile>
18 #include <QFileInfo>
19 
20 namespace Marble
21 {
22 
23 LogRunner::LogRunner( QObject *parent ) :
24  ParsingRunner( parent )
25 {
26 }
27 
28 LogRunner::~LogRunner()
29 {
30 }
31 
32 void LogRunner::parseFile( const QString &fileName, DocumentRole role = UnknownDocument )
33 {
34  QFile file( fileName );
35  if ( !file.exists() ) {
36  qWarning( "File does not exist!" );
37  emit parsingFinished( 0 );
38  return;
39  }
40 
41  file.open( QIODevice::ReadOnly );
42  QTextStream stream( &file );
43 
44  GeoDataLineString *const track = new GeoDataLineString;
45 
46  GeoDataPlacemark *const placemark = new GeoDataPlacemark;
47  placemark->setGeometry( track );
48 
49  GeoDataDocument *document = new GeoDataDocument();
50  document->setDocumentRole( role );
51  document->append( placemark );
52 
53  int count = 0;
54  bool error = false;
55  while( !stream.atEnd() || error ){
56  const QString line = stream.readLine();
57  const QStringList list = line.split( ',' );
58 
59  if ( list.size() != 7 ) {
60  mDebug() << Q_FUNC_INFO << "Aborting due to error in line" << count << ". Line was:" << line;
61  error = true;
62  break;
63  }
64 
65  const QString strLat = list[0];
66  const QString strLon = list[1];
67  const QString strElevation = list[2];
68  const QString strSpeed = list[3];
69  const QString strCourse = list[4];
70  const QString strHdop = list[5];
71  const QString strTime = list[6];
72 
73  if ( strLat.isEmpty() || strLon.isEmpty() || strElevation.isEmpty() ) {
74  continue;
75  }
76 
77  bool okLat, okLon, okAlt = false;
78  const qreal lat = strLat.toDouble( &okLat );
79  const qreal lon = strLon.toDouble( &okLon );
80  const qreal alt = strElevation.toDouble( &okAlt );
81 
82  if ( !okLat || !okLon || !okAlt ) {
83  continue;
84  }
85 
86  GeoDataCoordinates coord( lon, lat, alt, GeoDataCoordinates::Degree );
87  track->append( coord );
88  }
89 
90  file.close();
91  if ( track->size() == 0 || error ) {
92  delete document;
93  document = 0;
94  emit parsingFinished( 0 );
95  return;
96  }
97 
98  document->setFileName( fileName );
99  emit parsingFinished( document );
100 }
101 
102 }
103 
104 #include "LogRunner.moc"
GeoDataDocument.h
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:65
Marble::GeoDataDocument::setDocumentRole
void setDocumentRole(DocumentRole role)
Definition: GeoDataDocument.cpp:86
QTextStream::readLine
QString readLine(qint64 maxlen)
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
Marble::GeoDataLineString::size
int size() const
Returns the number of nodes in a LineString.
Definition: GeoDataLineString.cpp:138
QFile::exists
bool exists() const
QString::toDouble
double toDouble(bool *ok) const
MarbleDebug.h
QFile
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
QTextStream
Marble::UnknownDocument
Definition: GeoDataDocument.h:40
QList::size
int size() const
Marble::ParsingRunner::parsingFinished
void parsingFinished(GeoDataDocument *document, const QString &error=QString())
File parsing is finished, result in the given document object.
LogRunner.h
QTextStream::atEnd
bool atEnd() const
QObject
QString::isEmpty
bool isEmpty() const
GeoDataLineString.h
QString
Marble::LogRunner::LogRunner
LogRunner(QObject *parent=0)
Definition: LogRunner.cpp:23
GeoDataPlacemark.h
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
Marble::GeoDataLineString::append
void append(const GeoDataCoordinates &position)
Appends a given geodesic position as a new node to the LineString.
Definition: GeoDataLineString.cpp:225
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
Marble::ParsingRunner
Definition: ParsingRunner.h:23
QStringList
Marble::GeoDataContainer::append
void append(GeoDataFeature *other)
add an element
Definition: GeoDataContainer.cpp:272
QFile::close
virtual void close()
Marble::GeoDataDocument::setFileName
void setFileName(const QString &value)
Set a new file name for this document.
Definition: GeoDataDocument.cpp:106
Marble::LogRunner::~LogRunner
~LogRunner()
Definition: LogRunner.cpp:28
Marble::LogRunner::parseFile
virtual void parseFile(const QString &fileName, DocumentRole role)
Start a file parsing.
Definition: LogRunner.cpp:32
Marble::GeoDataPlacemark
a class representing a point of interest on the map
Definition: GeoDataPlacemark.h:54
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
Marble::DocumentRole
DocumentRole
Definition: GeoDataDocument.h:39
Marble::GeoDataPlacemark::setGeometry
void setGeometry(GeoDataGeometry *entry)
Sets the current Geometry of this Placemark.
Definition: GeoDataPlacemark.cpp:230
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:40 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