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 "GeoWriter.h"
11#include "GeoTagWriter.h"
12#include "KmlElementDictionary.h"
13
14namespace Marble
15{
16static GeoTagWriterRegistrar s_writerLookAt(
17 GeoTagWriter::QualifiedName( GeoDataTypes::GeoDataScreenOverlayType,
18 kml::kmlTag_nameSpaceOgc22 ),
19 new KmlScreenOverlayWriter );
20
21KmlScreenOverlayWriter::KmlScreenOverlayWriter() : KmlOverlayTagWriter( kml::kmlTag_ScreenOverlay )
22{
23 // nothing to do
24}
25
26
27bool KmlScreenOverlayWriter::writeMid( const GeoNode *node, GeoWriter& writer ) const
28{
29 KmlOverlayTagWriter::writeMid( node, writer );
30
31 const GeoDataScreenOverlay *screenOverlay = static_cast<const GeoDataScreenOverlay*>( node );
32 writeVec2( kml::kmlTag_overlayXY, screenOverlay->overlayXY(), writer );
33 writeVec2( kml::kmlTag_screenXY, screenOverlay->screenXY(), writer );
34 writeVec2( kml::kmlTag_rotationXY, screenOverlay->rotationXY(), writer );
35 writeVec2( kml::kmlTag_size, screenOverlay->size(), writer );
36 QString const rotation = QString::number(screenOverlay->rotation());
37 writer.writeOptionalElement( kml::kmlTag_rotation, rotation, "0" );
38 return true;
39}
40
41void KmlScreenOverlayWriter::writeVec2( const QString &element, const GeoDataVec2 &vec2, GeoWriter &writer )
42{
43 writer.writeStartElement( element );
44 writer.writeAttribute( "x", QString::number( vec2.x() ) );
45 writer.writeAttribute( "xunits", unitToString( vec2.xunit() ) );
46 writer.writeAttribute( "y", QString::number( vec2.y() ) );
47 writer.writeAttribute( "yunits", unitToString( vec2.yunit() ) );
48 writer.writeEndElement();
49}
50
51QString KmlScreenOverlayWriter::unitToString( GeoDataVec2::Unit unit )
52{
53 switch( unit ) {
54 case GeoDataVec2::Fraction: return "fraction";
55 case GeoDataVec2::Pixels: return "pixels";
56 case GeoDataVec2::InsetPixels: return "insetPixels";
57 }
58
59 Q_ASSERT(false);
60 return "fraction";
61}
62
63}
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 number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:49:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.