Marble

KmlIconStyleTagWriter.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
4//
5
6#include "KmlIconStyleTagWriter.h"
7
8#include "GeoDataIconStyle.h"
9#include "GeoDataTypes.h"
10#include "GeoWriter.h"
11#include "KmlElementDictionary.h"
12
13namespace Marble
14{
15
16static GeoTagWriterRegistrar s_writerIconStyle(GeoTagWriter::QualifiedName(QString::fromLatin1(GeoDataTypes::GeoDataIconStyleType),
17 QString::fromLatin1(kml::kmlTag_nameSpaceOgc22)),
18 new KmlIconStyleTagWriter);
19
20KmlIconStyleTagWriter::KmlIconStyleTagWriter()
21 : KmlColorStyleTagWriter(QString::fromLatin1(kml::kmlTag_IconStyle))
22{
23 // nothing to do
24}
25
26bool KmlIconStyleTagWriter::writeMid(const GeoNode *node, GeoWriter &writer) const
27{
28 const auto style = static_cast<const GeoDataIconStyle *>(node);
29
30 if (style->scale() != 1.0) {
31 writer.writeElement(QString::fromLatin1(kml::kmlTag_scale), QString::number(style->scale(), 'f'));
32 }
33
34 if (!style->size().isEmpty()) {
35 writer.writeNamespace(QString::fromUtf8(kml::kmlTag_nameSpaceMx), QStringLiteral("mx"));
36 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_nameSpaceMx), QString::fromUtf8(kml::kmlTag_size));
37 writer.writeAttribute(QString::fromUtf8(kml::kmlTag_width), QString::number(style->size().width()));
38 writer.writeAttribute(QString::fromUtf8(kml::kmlTag_height), QString::number(style->size().height()));
39 writer.writeEndElement();
40 }
41
42 if (!style->iconPath().isEmpty()) {
43 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_Icon));
44 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_href));
45 writer.writeCharacters(style->iconPath());
46 writer.writeEndElement();
47 writer.writeEndElement();
48 }
49
50 GeoDataHotSpot::Units xunits, yunits;
51 QPointF const hotSpot = style->hotSpot(xunits, yunits);
52 bool const emptyHotSpot = hotSpot.x() == 0.5 && hotSpot.y() == 0.5 && xunits == GeoDataHotSpot::Fraction && yunits == GeoDataHotSpot::Fraction;
53 if (!emptyHotSpot) {
54 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_hotSpot));
55 if (hotSpot.x() != 0.5 || xunits != GeoDataHotSpot::Fraction) {
56 writer.writeAttribute("x", QString::number(hotSpot.x(), 'f'));
57 }
58 if (hotSpot.y() != 0.5 || yunits != GeoDataHotSpot::Fraction) {
59 writer.writeAttribute("y", QString::number(hotSpot.y(), 'f'));
60 }
61
62 if (xunits != GeoDataHotSpot::Fraction) {
63 writer.writeAttribute("xunits", unitString(xunits));
64 }
65 if (yunits != GeoDataHotSpot::Fraction) {
66 writer.writeAttribute("yunits", unitString(yunits));
67 }
68 writer.writeEndElement();
69 }
70
71 return true;
72}
73
74bool KmlIconStyleTagWriter::isEmpty(const GeoNode *node) const
75{
76 const auto style = static_cast<const GeoDataIconStyle *>(node);
77 GeoDataHotSpot::Units xunits, yunits;
78 QPointF const hotSpot = style->hotSpot(xunits, yunits);
79 return style->iconPath().isEmpty() && hotSpot.x() == 0.5 && hotSpot.y() == 0.5 && xunits == GeoDataHotSpot::Fraction && yunits == GeoDataHotSpot::Fraction;
80}
81
82QString KmlIconStyleTagWriter::unitString(GeoDataHotSpot::Units unit)
83{
84 switch (unit) {
85 case GeoDataHotSpot::Pixels:
86 return QStringLiteral("pixels");
87 case GeoDataHotSpot::InsetPixels:
88 return QStringLiteral("insetPixels");
89 case GeoDataHotSpot::Fraction:
90 return QStringLiteral("fraction");
91 }
92
93 return QStringLiteral("fraction");
94}
95
96}
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.
qreal x() const const
qreal y() const const
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 18 2024 12:15:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.