Marble

KmlScreenOverlayWriter.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2012 Mayank Madan <maddiemadan@gmail.com>
4//
5
6#include "KmlScreenOverlayWriter.h"
7
8#include "GeoDataScreenOverlay.h"
9#include "GeoDataTypes.h"
10#include "GeoTagWriter.h"
11#include "GeoWriter.h"
12#include "KmlElementDictionary.h"
13
14namespace Marble
15{
16static GeoTagWriterRegistrar s_writerLookAt(GeoTagWriter::QualifiedName(QString::fromLatin1(GeoDataTypes::GeoDataScreenOverlayType),
17 QString::fromLatin1(kml::kmlTag_nameSpaceOgc22)),
18 new KmlScreenOverlayWriter);
19
20KmlScreenOverlayWriter::KmlScreenOverlayWriter()
21 : KmlOverlayTagWriter(QString::fromLatin1(kml::kmlTag_ScreenOverlay))
22{
23 // nothing to do
24}
25
26bool KmlScreenOverlayWriter::writeMid(const GeoNode *node, GeoWriter &writer) const
27{
28 KmlOverlayTagWriter::writeMid(node, writer);
29
30 const auto screenOverlay = static_cast<const GeoDataScreenOverlay *>(node);
31 writeVec2(QString::fromLatin1(kml::kmlTag_overlayXY), screenOverlay->overlayXY(), writer);
32 writeVec2(QString::fromLatin1(kml::kmlTag_screenXY), screenOverlay->screenXY(), writer);
33 writeVec2(QString::fromLatin1(kml::kmlTag_rotationXY), screenOverlay->rotationXY(), writer);
34 writeVec2(QString::fromLatin1(kml::kmlTag_size), screenOverlay->size(), writer);
35 QString const rotation = QString::number(screenOverlay->rotation());
36 writer.writeOptionalElement(QLatin1String(kml::kmlTag_rotation), rotation, QStringLiteral("0"));
37 return true;
38}
39
40void KmlScreenOverlayWriter::writeVec2(const QString &element, const GeoDataVec2 &vec2, GeoWriter &writer)
41{
42 writer.writeStartElement(element);
43 writer.writeAttribute("x", QString::number(vec2.x()));
44 writer.writeAttribute("xunits", unitToString(vec2.xunit()));
45 writer.writeAttribute("y", QString::number(vec2.y()));
46 writer.writeAttribute("yunits", unitToString(vec2.yunit()));
47 writer.writeEndElement();
48}
49
50QString KmlScreenOverlayWriter::unitToString(GeoDataVec2::Unit unit)
51{
52 switch (unit) {
53 case GeoDataVec2::Fraction:
54 return QStringLiteral("fraction");
55 case GeoDataVec2::Pixels:
56 return QStringLiteral("pixels");
57 case GeoDataVec2::InsetPixels:
58 return QStringLiteral("insetPixels");
59 }
60
61 Q_ASSERT(false);
62 return QStringLiteral("fraction");
63}
64
65}
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 number(double n, char format, int precision)
qsizetype size() const const
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.