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 "GeoDataTimeStamp.h"
12#include "GeoDataTrack.h"
13#include "GeoParser.h"
14#include "KmlElementDictionary.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(QLatin1StringView(kmlTag_when)));
25
26 GeoStackItem parentItem = parser.parentElement();
27
28 QString whenString = parser.readElementText().trimmed();
29 GeoDataTimeStamp::TimeResolution resolution = modify(whenString);
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 case 4:
61 whenString += QLatin1StringView("-01-01");
62 return GeoDataTimeStamp::YearResolution;
63 case 7:
64 whenString += QLatin1StringView("-01");
65 return GeoDataTimeStamp::MonthResolution;
66 case 10:
67 return GeoDataTimeStamp::DayResolution;
68 default:
69 return GeoDataTimeStamp::SecondResolution;
70 }
71
72 return GeoDataTimeStamp::SecondResolution;
73}
74
75}
76
77}
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 Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.