• 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
  • tools
  • svg2pnt
svg2pnt/svgxmlhandler.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 2006-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 //
11 
12 
13 #include "svgxmlhandler.h"
14 #include <QDebug>
15 
16 SVGXmlHandler::SVGXmlHandler(const QString& targetfile)
17 {
18  m_header = 8000;
19  m_pointnum = 0;
20  m_initialized = false;
21  m_targetfile = targetfile;
22 }
23 
24 bool SVGXmlHandler::startElement(const QString& nspace,
25  const QString& localName,
26  const QString& qName,
27  const QXmlAttributes &atts)
28 {
29  Q_UNUSED(nspace)
30  Q_UNUSED(localName)
31 
32  qDebug();
33  if ( qName == "g" ) {
34  qDebug( "Parsing Data ..." );
35  m_initialized = true;
36  }
37 
38  if ( qName == "path" && m_initialized ) {
39  QString coordinates = atts.value( "d" );
40 
41  QStringList stringlist;
42  coordinates.chop(2);
43  stringlist << coordinates.mid( 1 ).split( 'L' );
44  // The last element is the first element
45  // stringlist.removeLast();
46  bool firstheader = true;
47  QFile file( m_targetfile );
48 
49  // Read the data serialized from the file.
50  file.open( QIODevice::Append );
51  QDataStream stream( &file );
52  stream.setByteOrder( QDataStream::LittleEndian );
53 
54  int count = 0;
55  qDebug() << "Starting to write path" << atts.value( "id" );
56  foreach ( const QString& str, stringlist ) {
57  // qDebug()<<str;
58  float x;
59  float y;
60  x = str.section( ',', 0, 0 ).toFloat();
61  y = str.section( ',', 1, 1 ).toFloat();
62 
63  // qDebug() << "x:" << x << "y:" << y;
64 
65  short header;
66  short lat;
67  short lng;
68 
69  if ( firstheader ) {
70  header = m_header;
71  firstheader = false;
72  }
73  else {
74  if ( stringlist.size() > 14 ) {
75  if ( count % 9 == 0 )
76  header = 5;
77  else if ( count % 5 == 0 )
78  header = 3;
79  else if ( count % 2 == 0 )
80  header = 2;
81  else
82  header = 1;
83  }
84  else if ( stringlist.size() > 6 ) {
85  if ( count % 2 == 0 )
86  header = 3;
87  else
88  header = 1;
89  }
90  else {
91  header = 2;
92  }
93  }
94  if ( count == stringlist.size() - 1 )
95  header = 5;
96 
97  lng = (int)( x * 50 - 10800 );
98  lat = -(int)( y * 50 - 5400 );
99 
100  qDebug() << "lng:" << lng << "lat:" << lat << "header:"
101  << header << "node#:" << m_pointnum;
102 
103  stream << header << lat << lng;
104  m_pointnum++;
105  count++;
106  }
107 
108  m_header++;
109  }
110 
111  return true;
112 }
QDataStream
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QString::chop
void chop(int n)
QFile
QList::size
int size() const
QString
QStringList
SVGXmlHandler::SVGXmlHandler
SVGXmlHandler(QDataStream *out, const QString &path, int header)
Definition: pntreplace/svgxmlhandler.cpp:16
SVGXmlHandler::startElement
virtual bool startElement(const QString &, const QString &, const QString &, const QXmlAttributes &)
Definition: pntreplace/svgxmlhandler.cpp:23
svgxmlhandler.h
QString::mid
QString mid(int position, int n) const
QXmlAttributes
QString::toFloat
float toFloat(bool *ok) const
QString::section
QString section(QChar sep, int start, int end, QFlags< QString::SectionFlag > flags) const
QXmlAttributes::value
QString value(int index) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:42 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