• 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
  • lib
  • marble
  • geodata
  • handlers
  • kml
KmlWhenTagHandler.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 2010 Harshit Jain <hjain.itbhu@gmail.com>
9 //
10 
11 #include "KmlWhenTagHandler.h"
12 
13 #include "MarbleDebug.h"
14 #include <QDateTime>
15 
16 #include "KmlElementDictionary.h"
17 #include "GeoDataTimeStamp.h"
18 #include "GeoDataTrack.h"
19 #include "GeoParser.h"
20 
21 namespace Marble
22 {
23 namespace kml
24 {
25 KML_DEFINE_TAG_HANDLER( when )
26 
27 GeoNode* KmlwhenTagHandler::parse( GeoParser& parser ) const
28 {
29  Q_ASSERT( parser.isStartElement() && parser.isValidElement( kmlTag_when ) );
30 
31  GeoStackItem parentItem = parser.parentElement();
32 
33  QString whenString = parser.readElementText().trimmed();
34  GeoDataTimeStamp::TimeResolution resolution = modify( whenString );
35  QDateTime when = QDateTime::fromString( whenString, Qt::ISODate );
36  if( parentItem.represents( kmlTag_TimeStamp ) ) {
37  parentItem.nodeAs<GeoDataTimeStamp>()->setWhen( when );
38  parentItem.nodeAs<GeoDataTimeStamp>()->setResolution( resolution );
39  } else if ( parentItem.represents( kmlTag_Track ) ) {
40  parentItem.nodeAs<GeoDataTrack>()->appendWhen( when );
41  }
42 
43  return 0;
44 }
45 
46 QDateTime KmlwhenTagHandler::parse( const QString &dateTime )
47 {
48  QString iso = dateTime;
49  modify( iso );
50  return QDateTime::fromString( iso, Qt::ISODate );
51 }
52 
53 GeoDataTimeStamp KmlwhenTagHandler::parseTimestamp( const QString &dateTime )
54 {
55  GeoDataTimeStamp result;
56  QString input = dateTime;
57  result.setResolution( modify( input ) );
58  result.setWhen( parse( input) );
59  return result;
60 }
61 
62 GeoDataTimeStamp::TimeResolution KmlwhenTagHandler::modify( QString& whenString )
63 {
64  switch( whenString.length() )
65  {
66  case 4:
67  whenString.append( "-01-01" );
68  return GeoDataTimeStamp::YearResolution;
69  case 7:
70  whenString.append( "-01" );
71  return GeoDataTimeStamp::MonthResolution;
72  case 10:
73  return GeoDataTimeStamp::DayResolution;
74  default:
75  return GeoDataTimeStamp::SecondResolution;
76  }
77 
78  return GeoDataTimeStamp::SecondResolution;
79 }
80 
81 }
82 
83 }
QString::append
QString & append(QChar ch)
Marble::GeoDataTrack
A geometry for tracking objects made of (time, coordinates) pairs.
Definition: GeoDataTrack.h:54
Marble::GeoDataTimeStamp
Definition: GeoDataTimeStamp.h:27
Marble::GeoDataTimeStamp::MonthResolution
Definition: GeoDataTimeStamp.h:33
Marble::GeoDataTimeStamp::setWhen
void setWhen(const QDateTime &when)
Set the when time of timestamp.
Definition: GeoDataTimeStamp.cpp:71
Marble::GeoNode
A shared base class for all classes that are mapped to a specific tag (ie.
Definition: GeoDocument.h:60
GeoParser.h
GeoDataTimeStamp.h
Marble::kml::kmlTag_TimeStamp
const char * kmlTag_TimeStamp
Definition: KmlElementDictionary.cpp:187
Marble::kml::KmlwhenTagHandler
Definition: KmlWhenTagHandler.h:23
MarbleDebug.h
GeoDataTrack.h
Marble::GeoParser
Definition: GeoParser.h:40
Marble::kml::kmlTag_when
const char * kmlTag_when
Definition: KmlElementDictionary.cpp:200
Marble::GeoDataTimeStamp::setResolution
void setResolution(TimeResolution resolution)
Definition: GeoDataTimeStamp.cpp:76
KmlElementDictionary.h
Marble::GeoDataTimeStamp::DayResolution
Definition: GeoDataTimeStamp.h:32
QString::trimmed
QString trimmed() const
Marble::GeoDataTimeStamp::YearResolution
Definition: GeoDataTimeStamp.h:34
Marble::GeoStackItem
Definition: GeoParser.h:97
KML_DEFINE_TAG_HANDLER
#define KML_DEFINE_TAG_HANDLER(Name)
Definition: KmlElementDictionary.h:242
QString
QDateTime::fromString
QDateTime fromString(const QString &string, Qt::DateFormat format)
Marble::kml::KmlwhenTagHandler::parseTimestamp
static GeoDataTimeStamp parseTimestamp(const QString &dateTime)
Definition: KmlWhenTagHandler.cpp:53
Marble::GeoDataTimeStamp::SecondResolution
Definition: GeoDataTimeStamp.h:31
KmlWhenTagHandler.h
QString::length
int length() const
Marble::GeoDataTimeStamp::TimeResolution
TimeResolution
Definition: GeoDataTimeStamp.h:30
Marble::kml::KmlwhenTagHandler::parse
virtual GeoNode * parse(GeoParser &) const
Definition: KmlWhenTagHandler.cpp:27
Marble::kml::kmlTag_Track
const char * kmlTag_Track
Definition: KmlElementDictionary.cpp:209
QDateTime
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