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(GeoDataTypes::GeoDataTimeStampType,
20 kml::kmlTag_nameSpaceOgc22),
21 new KmlTimeStampTagWriter() );
22
23
24bool KmlTimeStampTagWriter::write( const GeoNode *node,
25 GeoWriter& writer ) const
26{
27 const GeoDataTimeStamp *timestamp = static_cast<const GeoDataTimeStamp*>(node);
28
29 if( timestamp->when().isValid() )
30 {
31 writer.writeStartElement( kml::kmlTag_TimeStamp );
32 KmlObjectTagWriter::writeIdentifiers( writer, timestamp );
33
34 writer.writeStartElement( kml::kmlTag_when);
35 writer.writeCharacters( toString( *timestamp ) );
36 writer.writeEndElement();
37
38 writer.writeEndElement();
39 }
40 return true;
41}
42
43QString KmlTimeStampTagWriter::toString( const GeoDataTimeStamp &timestamp )
44{
45 switch ( timestamp.resolution() ) {
46 case GeoDataTimeStamp::SecondResolution: return timestamp.when().toString( Qt::ISODate );
47 case GeoDataTimeStamp::DayResolution: return timestamp.when().toString( "yyyy-MM-dd" );
48 case GeoDataTimeStamp::MonthResolution: return timestamp.when().toString( "yyyy-MM" );
49 case GeoDataTimeStamp::YearResolution: return timestamp.when().toString( "yyyy" );
50 }
51
52 Q_ASSERT( false && "not reachable" );
53 return QString();
54}
55
56}
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.
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.