Marble

KmlPlaylistTagWriter.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2013 Adrian Draghici <draghici.adrian.b@gmail.com>
4//
5
6#include "KmlPlaylistTagWriter.h"
7
8#include "GeoDataAnimatedUpdate.h"
9#include "GeoDataFlyTo.h"
10#include "GeoDataPlaylist.h"
11#include "GeoDataSoundCue.h"
12#include "GeoDataTypes.h"
13#include "GeoDataWait.h"
14#include "GeoWriter.h"
15#include "KmlElementDictionary.h"
16#include "KmlObjectTagWriter.h"
17
18namespace Marble
19{
20
21static GeoTagWriterRegistrar s_writerPlaylist(GeoTagWriter::QualifiedName(QString::fromLatin1(GeoDataTypes::GeoDataPlaylistType),
22 QString::fromLatin1(kml::kmlTag_nameSpaceOgc22)),
23 new KmlPlaylistTagWriter);
24
25bool KmlPlaylistTagWriter::write(const GeoNode *node, GeoWriter &writer) const
26{
27 const auto playlist = static_cast<const GeoDataPlaylist *>(node);
28
29 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_nameSpaceGx22), QString::fromUtf8(kml::kmlTag_Playlist));
30
31 for (int i = 0; i < playlist->size(); i++) {
32 writeTourPrimitive(playlist->primitive(i), writer);
33 }
34
35 writer.writeEndElement();
36
37 return true;
38}
39
40void KmlPlaylistTagWriter::writeTourPrimitive(const GeoDataTourPrimitive *primitive, GeoWriter &writer)
41{
42 if (const auto tourControl = geodata_cast<GeoDataTourControl>(primitive)) {
43 writeTourControl(*tourControl, writer);
44 } else if (const auto wait = geodata_cast<GeoDataWait>(primitive)) {
45 writeWait(*wait, writer);
46 } else if (const auto flyTo = geodata_cast<GeoDataFlyTo>(primitive)) {
47 writeElement(flyTo, writer);
48 } else if (const auto soundCue = geodata_cast<GeoDataSoundCue>(primitive)) {
49 writeSoundCue(*soundCue, writer);
50 } else if (const auto animatedUpdate = geodata_cast<GeoDataAnimatedUpdate>(primitive)) {
51 writeElement(animatedUpdate, writer);
52 }
53}
54
55void KmlPlaylistTagWriter::writeTourControl(const GeoDataTourControl &tourControl, GeoWriter &writer)
56{
57 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_nameSpaceGx22), QString::fromUtf8(kml::kmlTag_TourControl));
58 KmlObjectTagWriter::writeIdentifiers(writer, &tourControl);
59
60 writer.writeElement(QString::fromLatin1(kml::kmlTag_nameSpaceGx22), QString::fromLatin1(kml::kmlTag_playMode), playModeToString(tourControl.playMode()));
61
62 writer.writeEndElement();
63}
64
65void KmlPlaylistTagWriter::writeWait(const GeoDataWait &wait, GeoWriter &writer)
66{
67 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_nameSpaceGx22), QString::fromUtf8(kml::kmlTag_Wait));
68 KmlObjectTagWriter::writeIdentifiers(writer, &wait);
69
70 writer.writeElement(QString::fromLatin1(kml::kmlTag_nameSpaceGx22), QString::fromLatin1(kml::kmlTag_duration), QString::number(wait.duration()));
71
72 writer.writeEndElement();
73}
74
75void KmlPlaylistTagWriter::writeSoundCue(const GeoDataSoundCue &cue, GeoWriter &writer)
76{
77 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_nameSpaceGx22), QString::fromUtf8(kml::kmlTag_SoundCue));
78 KmlObjectTagWriter::writeIdentifiers(writer, &cue);
79
80 writer.writeElement(QString::fromLatin1(kml::kmlTag_href), cue.href());
81 writer.writeElement(QString::fromLatin1(kml::kmlTag_nameSpaceGx22), QString::fromLatin1(kml::kmlTag_delayedStart), QString::number(cue.delayedStart()));
82
83 writer.writeEndElement();
84}
85
86QString KmlPlaylistTagWriter::playModeToString(GeoDataTourControl::PlayMode playMode)
87{
88 switch (playMode) {
89 case GeoDataTourControl::Play:
90 return QStringLiteral("play");
91 case GeoDataTourControl::Pause:
92 return QStringLiteral("pause");
93 default:
94 return {};
95 }
96}
97
98}
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.
T * geodata_cast(GeoDataObject *node)
Returns the given node cast to type T if the node was instantiated as type T; otherwise returns 0.
QString fromLatin1(QByteArrayView str)
QString fromUtf8(QByteArrayView str)
QString number(double n, char format, int precision)
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.