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(
17 GeoTagWriter::QualifiedName( GeoDataTypes::GeoDataIconStyleType,
18 kml::kmlTag_nameSpaceOgc22 ),
19 new KmlIconStyleTagWriter );
20
21KmlIconStyleTagWriter::KmlIconStyleTagWriter() : KmlColorStyleTagWriter( kml::kmlTag_IconStyle )
22{
23 // nothing to do
24}
25
26bool KmlIconStyleTagWriter::writeMid( const GeoNode *node, GeoWriter& writer ) const
27{
28 const GeoDataIconStyle *style = static_cast<const GeoDataIconStyle*>( node );
29
30 if ( style->scale() != 1.0 ) {
31 writer.writeElement( kml::kmlTag_scale, QString::number( style->scale(), 'f' ) );
32 }
33
34 if (!style->size().isEmpty()) {
35 writer.writeNamespace(kml::kmlTag_nameSpaceMx, QStringLiteral("mx"));
36 writer.writeStartElement(kml::kmlTag_nameSpaceMx, kml::kmlTag_size);
37 writer.writeAttribute(kml::kmlTag_width, QString::number(style->size().width()));
38 writer.writeAttribute(kml::kmlTag_height, QString::number(style->size().height()));
39 writer.writeEndElement();
40 }
41
42 if ( !style->iconPath().isEmpty() ) {
43 writer.writeStartElement( kml::kmlTag_Icon );
44 writer.writeStartElement( 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 &&
53 xunits == GeoDataHotSpot::Fraction && yunits == GeoDataHotSpot::Fraction;
54 if ( !emptyHotSpot ) {
55 writer.writeStartElement( kml::kmlTag_hotSpot );
56 if ( hotSpot.x() != 0.5 || xunits != GeoDataHotSpot::Fraction ) {
57 writer.writeAttribute( "x", QString::number( hotSpot.x(), 'f' ) );
58 }
59 if ( hotSpot.y() != 0.5 || yunits != GeoDataHotSpot::Fraction ) {
60 writer.writeAttribute( "y", QString::number( hotSpot.y(), 'f' ) );
61 }
62
63 if ( xunits != GeoDataHotSpot::Fraction ) {
64 writer.writeAttribute( "xunits", unitString( xunits ) );
65 }
66 if ( yunits != GeoDataHotSpot::Fraction ) {
67 writer.writeAttribute( "yunits", unitString( yunits ) );
68 }
69 writer.writeEndElement();
70 }
71
72 return true;
73}
74
75bool KmlIconStyleTagWriter::isEmpty( const GeoNode *node ) const
76{
77 const GeoDataIconStyle *style = static_cast<const GeoDataIconStyle*>( node );
78 GeoDataHotSpot::Units xunits, yunits;
79 QPointF const hotSpot = style->hotSpot( xunits, yunits );
80 return style->iconPath().isEmpty() &&
81 hotSpot.x() == 0.5 &&
82 hotSpot.y() == 0.5 &&
83 xunits == GeoDataHotSpot::Fraction &&
84 yunits == GeoDataHotSpot::Fraction;
85}
86
87QString KmlIconStyleTagWriter::unitString(GeoDataHotSpot::Units unit)
88{
89 switch (unit) {
90 case GeoDataHotSpot::Pixels: return "pixels";
91 case GeoDataHotSpot::InsetPixels: return "insetPixels";
92 case GeoDataHotSpot::Fraction: return "fraction";
93 }
94
95 return "fraction";
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.
qreal x() const const
qreal y() const const
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 Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.