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

rocs/RocsCore

  • sources
  • kde-4.12
  • kdeedu
  • rocs
  • RocsCore
  • LoadSave
  • Plugins
  • kmlFileFormat
KmlHandler.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2010 Tomaz Canabrava <tomaz.canabrava@gmail.com>
4  Copyright 2010 Wagner Reck <wagner.reck@gmail.com>
5  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "KmlHandler.h"
22 #include "DataStructure.h"
23 #include "Data.h"
24 #include <KDebug>
25 
26 
27 KmlHandler::KmlHandler(DataStructurePtr doc): QXmlDefaultHandler(), m_graph(doc)
28 {
29 
30 }
31 
32 
33 KmlHandler::~KmlHandler()
34 {
35 
36 }
37 
38 
39 bool KmlHandler::characters(const QString& str)
40 {
41  currentText += str;
42  return true;
43 }
44 
45 
46 bool KmlHandler::endElement(const QString& /*namespaceURI*/, const QString& /*localName*/, const QString& qName)
47 {
48  DataPtr n;
49  if (qName == "coordinates") {
50  m_coordinates = currentText;
51  } else if (qName == "name") {
52  m_name = currentText;
53  } else if (qName == "description") {
54  m_description = currentText;
55  } else if (qName == "Placemark" && !m_coordinates.isEmpty()) {
56  if (m_name.isEmpty()) {
57  m_name = QString::number(qrand());
58  }
59  n = m_graph->createData(m_name, 0);
60  QStringList values = m_coordinates.split(',');
61  if (values.count() >= 2) {
62 
63  n->setX(values.at(0).toDouble());
64  n->addDynamicProperty("Longitude", values.at(0).toDouble());
65  n->setY(values.at(1).toDouble());
66  n->addDynamicProperty("Latitude", values.at(1).toDouble());
67  if (values.count() > 2) {
68  n->addDynamicProperty("Elevation", values.at(2).toDouble());
69  }
70  }
71  if (!m_description.isEmpty()) {
72  n->addDynamicProperty("Description", m_description);
73  }
74  m_coordinates.clear();
75  m_description.clear();
76  m_name.clear();
77  }
78  if (qName == "LineString" && !m_coordinates.isEmpty()) {
79  QStringList points = m_coordinates.split('\n');
80  int count = 0;
81  DataPtr n_old;
82  foreach(const QString& point, points) {
83  count++;
84 
85  QStringList values = point.split(',');
86  if (values.count() >= 2) {
87  n = m_graph->createData(m_name + '_' + QString::number(count + 1), 0);
88 
89  n->setX(values.at(0).toDouble());
90  n->addDynamicProperty("Longitude", values.at(0).toDouble());
91  n->setY(values.at(1).toDouble());
92  n->addDynamicProperty("Latitude", values.at(1).toDouble());
93  if (values.count() > 2) {
94  n->addDynamicProperty("Elevation", values.at(2).toDouble());
95  }
96  }
97  if (!m_description.isEmpty()) {
98  n->addDynamicProperty("Description", m_description);
99  }
100  if (n_old) {
101  m_graph->createPointer(n_old, n, 0);
102  }
103  n_old = n;
104  }
105  m_coordinates.clear();
106  m_description.clear();
107  m_name.clear();
108  }
109  kDebug() << qName;
110  return true;
111 }
112 
113 
114 QString KmlHandler::errorString() const
115 {
116  return QXmlDefaultHandler::errorString();
117 }
118 
119 
120 bool KmlHandler::fatalError(const QXmlParseException& exception)
121 {
122  return QXmlDefaultHandler::fatalError(exception);
123 }
124 
125 
126 bool KmlHandler::startElement(const QString& /*namespaceURI*/, const QString& /*localName*/, const QString& /*qName*/, const QXmlAttributes& /*attributes*/)
127 {
128  currentText.clear();
129  return true;
130 }
KmlHandler.h
DataStructurePtr
boost::shared_ptr< DataStructure > DataStructurePtr
Definition: CoreTypes.h:38
Data.h
KmlHandler::errorString
QString errorString() const
Definition: KmlHandler.cpp:114
DataStructure.h
KmlHandler::KmlHandler
KmlHandler(DataStructurePtr doc)
Definition: KmlHandler.cpp:27
QXmlDefaultHandler
KmlHandler::startElement
bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &attributes)
Definition: KmlHandler.cpp:126
KmlHandler::endElement
bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
Definition: KmlHandler.cpp:46
KmlHandler::characters
bool characters(const QString &str)
Definition: KmlHandler.cpp:39
DataPtr
boost::shared_ptr< Data > DataPtr
Definition: CoreTypes.h:34
KmlHandler::~KmlHandler
~KmlHandler()
Definition: KmlHandler.cpp:33
KmlHandler::fatalError
bool fatalError(const QXmlParseException &exception)
Definition: KmlHandler.cpp:120
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:26 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/RocsCore

Skip menu "rocs/RocsCore"
  • 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