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

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • plugins
  • runner
  • cache
CacheRunner.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 2011 Thibaut Gridel <tgridel@free.fr>
9 
10 #include "CacheRunner.h"
11 
12 #include "GeoDataDocument.h"
13 #include "GeoDataExtendedData.h"
14 #include "GeoDataPlacemark.h"
15 
16 #include <QFile>
17 
18 namespace Marble
19 {
20 
21 const quint32 MarbleMagicNumber = 0x31415926;
22 
23 CacheRunner::CacheRunner(QObject *parent) :
24  ParsingRunner(parent)
25 {
26 }
27 
28 CacheRunner::~CacheRunner()
29 {
30 }
31 
32 void CacheRunner::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  QDataStream in( &file );
43 
44  // Read and check the header
45  quint32 magic;
46  in >> magic;
47  if ( magic != MarbleMagicNumber ) {
48  emit parsingFinished( 0 );
49  return;
50  }
51 
52  // Read the version
53  qint32 version;
54  in >> version;
55  if ( version < 015 ) {
56  qDebug( "Bad Cache file - too old!" );
57  emit parsingFinished( 0 );
58  return;
59  }
60  /*
61  if (version > 002) {
62  qDebug( "Bad file - too new!" );
63  return;
64  }
65  */
66  GeoDataDocument *document = new GeoDataDocument();
67  document->setDocumentRole( role );
68 
69  in.setVersion( QDataStream::Qt_4_2 );
70 
71  // Read the data itself
72  // Use double to provide a single cache file format across architectures
73  double lon;
74  double lat;
75  double alt;
76  double area;
77 
78  QString tmpstr;
79  qint64 tmpint64;
80  qint8 tmpint8;
81  qint16 tmpint16;
82 
83  while ( !in.atEnd() ) {
84  GeoDataPlacemark *mark = new GeoDataPlacemark;
85  in >> tmpstr;
86  mark->setName( tmpstr );
87  in >> lon >> lat >> alt;
88  mark->setCoordinate( (qreal)(lon), (qreal)(lat), (qreal)(alt) );
89  in >> tmpstr;
90  mark->setRole( tmpstr );
91  in >> tmpstr;
92  mark->setDescription( tmpstr );
93  in >> tmpstr;
94  mark->setCountryCode( tmpstr );
95  in >> tmpstr;
96  mark->setState( tmpstr );
97  in >> area;
98  mark->setArea( (qreal)(area) );
99  in >> tmpint64;
100  mark->setPopulation( tmpint64 );
101  in >> tmpint16;
102  mark->extendedData().addValue( GeoDataData( "gmt", int( tmpint16 ) ) );
103  in >> tmpint8;
104  mark->extendedData().addValue( GeoDataData( "dst", int( tmpint8 ) ) );
105 
106  document->append( mark );
107  }
108  document->setFileName( fileName );
109 
110  file.close();
111  emit parsingFinished( document );
112 }
113 
114 }
115 
116 #include "CacheRunner.moc"
GeoDataDocument.h
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:64
Marble::GeoDataDocument::setDocumentRole
void setDocumentRole(DocumentRole role)
Definition: GeoDataDocument.cpp:62
Marble::CacheRunner::~CacheRunner
~CacheRunner()
Definition: CacheRunner.cpp:28
Marble::GeoDataFeature::setDescription
void setDescription(const QString &value)
Set the description of this feature to value.
Definition: GeoDataFeature.cpp:518
GeoDataExtendedData.h
Marble::CacheRunner::CacheRunner
CacheRunner(QObject *parent=0)
Definition: CacheRunner.cpp:23
Marble::GeoDataPlacemark::setCoordinate
void setCoordinate(qreal longitude, qreal latitude, qreal altitude=0, GeoDataCoordinates::Unit _unit=GeoDataCoordinates::Radian)
Set the coordinate of the placemark in longitude and latitude.
Definition: GeoDataPlacemark.cpp:121
Marble::GeoDataPlacemark::setState
void setState(const QString &state)
Set the state state of the placemark.
Definition: GeoDataPlacemark.cpp:171
QObject
Marble::UnknownDocument
Definition: GeoDataDocument.h:40
Marble::ParsingRunner::parsingFinished
void parsingFinished(GeoDataDocument *document, const QString &error=QString())
File parsing is finished, result in the given document object.
Marble::MarbleMagicNumber
const quint32 MarbleMagicNumber
Definition: FileLoader.cpp:241
Marble::GeoDataFeature::setName
void setName(const QString &value)
Set a new name for this feature.
Definition: GeoDataFeature.cpp:485
GeoDataPlacemark.h
Marble::ParsingRunner
Definition: ParsingRunner.h:23
Marble::GeoDataContainer::append
void append(GeoDataFeature *other)
add an element
Definition: GeoDataContainer.cpp:165
Marble::GeoDataPlacemark::setPopulation
void setPopulation(qint64 population)
Sets the population of the placemark.
Definition: GeoDataPlacemark.cpp:160
Marble::CacheRunner::parseFile
virtual void parseFile(const QString &fileName, DocumentRole role)
Start a file parsing.
Definition: CacheRunner.cpp:32
Marble::GeoDataData
Definition: GeoDataData.h:26
Marble::GeoDataExtendedData::addValue
void addValue(const GeoDataData &data)
add a data object to the GeoDataExtendedData with the key
Definition: GeoDataExtendedData.cpp:59
Marble::GeoDataDocument::setFileName
void setFileName(const QString &value)
Set a new file name for this document.
Definition: GeoDataDocument.cpp:82
Marble::GeoDataPlacemark::setArea
void setArea(qreal area)
Set the area size of the feature in square km.
Definition: GeoDataPlacemark.cpp:149
Marble::GeoDataFeature::setRole
void setRole(const QString &role)
Sets the role of the placemark.
Definition: GeoDataFeature.cpp:691
CacheRunner.h
Marble::GeoDataFeature::extendedData
GeoDataExtendedData & extendedData() const
Return the ExtendedData assigned to the feature.
Definition: GeoDataFeature.cpp:653
Marble::GeoDataPlacemark::setCountryCode
void setCountryCode(const QString &code)
Set the country code of the placemark.
Definition: GeoDataPlacemark.cpp:182
Marble::GeoDataPlacemark
a class representing a point of interest on the map
Definition: GeoDataPlacemark.h:54
Marble::DocumentRole
DocumentRole
Definition: GeoDataDocument.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:49 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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