Marble

KmlTimeStampTagWriter.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2011 Javier Becerra <javier@auva.es>
4//
5
6#include "KmlTimeStampTagWriter.h"
7
8#include "GeoDataTimeStamp.h"
9#include "GeoDataTypes.h"
10#include "GeoWriter.h"
11#include "KmlElementDictionary.h"
12#include "KmlObjectTagWriter.h"
13
14#include <QDateTime>
15
16namespace Marble
17{
18
19static GeoTagWriterRegistrar s_writerTimeStamp(GeoTagWriter::QualifiedName(QString::fromLatin1(GeoDataTypes::GeoDataTimeStampType),
20 QString::fromLatin1(kml::kmlTag_nameSpaceOgc22)),
21 new KmlTimeStampTagWriter());
22
23bool KmlTimeStampTagWriter::write(const GeoNode *node, GeoWriter &writer) const
24{
25 const auto timestamp = static_cast<const GeoDataTimeStamp *>(node);
26
27 if (timestamp->when().isValid()) {
28 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_TimeStamp));
29 KmlObjectTagWriter::writeIdentifiers(writer, timestamp);
30
31 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_when));
32 writer.writeCharacters(toString(*timestamp));
33 writer.writeEndElement();
34
35 writer.writeEndElement();
36 }
37 return true;
38}
39
40QString KmlTimeStampTagWriter::toString(const GeoDataTimeStamp &timestamp)
41{
42 switch (timestamp.resolution()) {
43 case GeoDataTimeStamp::SecondResolution:
44 return timestamp.when().toString(Qt::ISODate);
45 case GeoDataTimeStamp::DayResolution:
46 return timestamp.when().toString(QStringLiteral("yyyy-MM-dd"));
47 case GeoDataTimeStamp::MonthResolution:
48 return timestamp.when().toString(QStringLiteral("yyyy-MM"));
49 case GeoDataTimeStamp::YearResolution:
50 return timestamp.when().toString(QStringLiteral("yyyy"));
51 }
52
53 Q_ASSERT(false && "not reachable");
54 return {};
55}
56
57}
QPair< QString, QString > QualifiedName
Object Name and Namespace Pair This type is intended to be used in a similar way to.
Binds a QML item to a specific geodetic location in screen coordinates.
QString fromLatin1(QByteArrayView str)
QString fromUtf8(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.