Marble

KmlWhenTagHandler.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2010 Harshit Jain <hjain.itbhu@gmail.com>
4//
5
6#include "KmlWhenTagHandler.h"
7
8#include "MarbleDebug.h"
9#include <QDateTime>
10
11#include "KmlElementDictionary.h"
12#include "GeoDataTimeStamp.h"
13#include "GeoDataTrack.h"
14#include "GeoParser.h"
15
16namespace Marble
17{
18namespace kml
19{
20KML_DEFINE_TAG_HANDLER( when )
21
22GeoNode* KmlwhenTagHandler::parse( GeoParser& parser ) const
23{
24 Q_ASSERT(parser.isStartElement() && parser.isValidElement(QLatin1String(kmlTag_when)));
25
26 GeoStackItem parentItem = parser.parentElement();
27
28 QString whenString = parser.readElementText().trimmed();
29 GeoDataTimeStamp::TimeResolution resolution = modify( whenString );
30 QDateTime when = QDateTime::fromString( whenString, Qt::ISODate );
31 if( parentItem.represents( kmlTag_TimeStamp ) ) {
32 parentItem.nodeAs<GeoDataTimeStamp>()->setWhen( when );
33 parentItem.nodeAs<GeoDataTimeStamp>()->setResolution( resolution );
34 } else if ( parentItem.represents( kmlTag_Track ) ) {
35 parentItem.nodeAs<GeoDataTrack>()->appendWhen( when );
36 }
37
38 return nullptr;
39}
40
41QDateTime KmlwhenTagHandler::parse( const QString &dateTime )
42{
43 QString iso = dateTime;
44 modify( iso );
46}
47
48GeoDataTimeStamp KmlwhenTagHandler::parseTimestamp( const QString &dateTime )
49{
50 GeoDataTimeStamp result;
51 QString input = dateTime;
52 result.setResolution( modify( input ) );
53 result.setWhen( parse( input) );
54 return result;
55}
56
57GeoDataTimeStamp::TimeResolution KmlwhenTagHandler::modify( QString& whenString )
58{
59 switch( whenString.length() )
60 {
61 case 4:
62 whenString += QLatin1String("-01-01");
63 return GeoDataTimeStamp::YearResolution;
64 case 7:
65 whenString += QLatin1String("-01");
66 return GeoDataTimeStamp::MonthResolution;
67 case 10:
68 return GeoDataTimeStamp::DayResolution;
69 default:
70 return GeoDataTimeStamp::SecondResolution;
71 }
72
73 return GeoDataTimeStamp::SecondResolution;
74}
75
76}
77
78}
Binds a QML item to a specific geodetic location in screen coordinates.
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
qsizetype length() const const
QString trimmed() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.