• 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
  • kml
KmlRunner.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 "KmlRunner.h"
11 
12 #include "GeoDataDocument.h"
13 #include "KmlParser.h"
14 #include "KmlDocument.h"
15 #include "MarbleDebug.h"
16 
17 #ifdef MARBLE_HAVE_QUAZIP
18 #include "KmzHandler.h"
19 #endif
20 
21 #include <QFile>
22 #include <QFileInfo>
23 
24 namespace Marble
25 {
26 
27 KmlRunner::KmlRunner(QObject *parent) :
28  ParsingRunner(parent)
29 {
30 }
31 
32 KmlRunner::~KmlRunner()
33 {
34 }
35 
36 void KmlRunner::parseFile( const QString &fileName, DocumentRole role = UnknownDocument )
37 {
38  QString kmlFileName = fileName;
39  QString kmzPath;
40  QStringList kmzFiles;
41 
42 #ifdef MARBLE_HAVE_QUAZIP
43  QFileInfo const kmzFile( fileName );
44  if ( kmzFile.exists() && kmzFile.suffix().toLower() == "kmz" ) {
45  KmzHandler kmzHandler;
46  if ( kmzHandler.open( fileName ) ) {
47  kmlFileName = kmzHandler.kmlFile();
48  kmzPath = kmzHandler.kmzPath();
49  kmzFiles = kmzHandler.kmzFiles();
50  } else {
51  qWarning() << "File " << fileName << " is not a valid .kmz file";
52  emit parsingFinished( 0 );
53  return;
54  }
55  }
56 #endif
57 
58  QFile file( kmlFileName );
59  if ( !file.exists() ) {
60  qWarning() << "File" << kmlFileName << "does not exist!";
61  emit parsingFinished( 0 );
62  return;
63  }
64 
65  // Open file in right mode
66  file.open( QIODevice::ReadOnly );
67 
68  KmlParser parser;
69 
70  if ( !parser.read( &file ) ) {
71  emit parsingFinished( 0, parser.errorString() );
72  return;
73  }
74  GeoDocument* document = parser.releaseDocument();
75  Q_ASSERT( document );
76  KmlDocument* doc = static_cast<KmlDocument*>( document );
77  doc->setDocumentRole( role );
78  doc->setFileName( fileName );
79  doc->setBaseUri( kmlFileName );
80  doc->setFiles( kmzPath, kmzFiles );
81 
82  file.close();
83  emit parsingFinished( doc );
84 }
85 
86 }
87 
88 #include "KmlRunner.moc"
GeoDataDocument.h
QXmlStreamReader::errorString
QString errorString() const
Marble::KmlDocument::setFiles
void setFiles(const QString &path, const QStringList &files)
Temporary files to delete at destruction.
Definition: KmlDocument.cpp:32
Marble::GeoDataDocument::setDocumentRole
void setDocumentRole(DocumentRole role)
Definition: GeoDataDocument.cpp:86
Marble::KmzHandler::kmlFile
QString kmlFile() const
Definition: KmzHandler.cpp:64
KmzHandler.h
QFile::exists
bool exists() const
Marble::KmlRunner::parseFile
virtual void parseFile(const QString &fileName, DocumentRole role)
Start a file parsing.
Definition: KmlRunner.cpp:36
MarbleDebug.h
QFile
Marble::KmlParser
Definition: KmlParser.h:18
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::KmlRunner::~KmlRunner
~KmlRunner()
Definition: KmlRunner.cpp:32
KmlDocument.h
Marble::GeoParser::read
bool read(QIODevice *)
Main API for reading the XML document.
Definition: GeoParser.cpp:74
QObject
KmlRunner.h
QString
Marble::KmzHandler::open
bool open(const QString &file)
Definition: KmzHandler.cpp:21
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
Marble::ParsingRunner
Definition: ParsingRunner.h:23
QStringList
Marble::KmzHandler::kmzPath
QString kmzPath() const
Definition: KmzHandler.cpp:69
Marble::KmzHandler::kmzFiles
QStringList kmzFiles() const
Definition: KmzHandler.cpp:74
QFileInfo
QString::toLower
QString toLower() const
QFileInfo::exists
bool exists() const
QFile::close
virtual void close()
Marble::GeoDataDocument::setBaseUri
void setBaseUri(const QString &baseUri)
Change the URI for resolving relative paths.
Definition: GeoDataDocument.cpp:117
QFileInfo::suffix
QString suffix() const
Marble::KmlDocument
Definition: KmlDocument.h:19
Marble::GeoDataDocument::setFileName
void setFileName(const QString &value)
Set a new file name for this document.
Definition: GeoDataDocument.cpp:106
Marble::GeoDocument
A shared base class between GeoDataDocument/GeoSourceDocument.
Definition: GeoDocument.h:42
Marble::KmlRunner::KmlRunner
KmlRunner(QObject *parent=0)
Definition: KmlRunner.cpp:27
KmlParser.h
Marble::DocumentRole
DocumentRole
Definition: GeoDataDocument.h:39
Marble::KmzHandler
Definition: KmzHandler.h:18
Marble::GeoParser::releaseDocument
GeoDocument * releaseDocument()
retrieve the parsed document and reset the parser If parsing was successful, retrieve the resulting d...
Definition: GeoParser.cpp:205
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