File indexing completed on 2025-01-05 03:59:14

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Mayank Madan <maddiemadan@gmail.com>
0004 //
0005 
0006 #include "KmlScreenOverlayWriter.h"
0007 
0008 #include "GeoDataScreenOverlay.h"
0009 #include "GeoDataTypes.h"
0010 #include "GeoWriter.h"
0011 #include "GeoTagWriter.h"
0012 #include "KmlElementDictionary.h"
0013 
0014 namespace Marble
0015 {
0016 static GeoTagWriterRegistrar s_writerLookAt(
0017         GeoTagWriter::QualifiedName( QString::fromUtf8(GeoDataTypes::GeoDataScreenOverlayType),
0018                                      QString::fromUtf8(kml::kmlTag_nameSpaceOgc22) ),
0019         new KmlScreenOverlayWriter );
0020 
0021 KmlScreenOverlayWriter::KmlScreenOverlayWriter() : KmlOverlayTagWriter( QString::fromUtf8(kml::kmlTag_ScreenOverlay) )
0022 {
0023     // nothing to do
0024 }
0025 
0026 
0027 bool KmlScreenOverlayWriter::writeMid( const GeoNode *node, GeoWriter& writer ) const
0028 {
0029     KmlOverlayTagWriter::writeMid( node, writer );
0030 
0031     const GeoDataScreenOverlay *screenOverlay = static_cast<const GeoDataScreenOverlay*>( node );
0032     writeVec2( QString::fromUtf8(kml::kmlTag_overlayXY), screenOverlay->overlayXY(), writer );
0033     writeVec2( QString::fromUtf8(kml::kmlTag_screenXY), screenOverlay->screenXY(), writer );
0034     writeVec2( QString::fromUtf8(kml::kmlTag_rotationXY), screenOverlay->rotationXY(), writer );
0035     writeVec2( QString::fromUtf8(kml::kmlTag_size), screenOverlay->size(), writer );
0036     QString const rotation = QString::number(screenOverlay->rotation());
0037     writer.writeOptionalElement( QString::fromUtf8(kml::kmlTag_rotation), rotation, QString::fromUtf8("0") );
0038     return true;
0039 }
0040 
0041 void KmlScreenOverlayWriter::writeVec2( const QString &element, const GeoDataVec2 &vec2, GeoWriter &writer )
0042 {
0043     writer.writeStartElement( element );
0044     writer.writeAttribute( QLatin1String("x"), QString::number( vec2.x() ) );
0045     writer.writeAttribute( QLatin1String("xunits"), unitToString( vec2.xunit() ) );
0046     writer.writeAttribute( QLatin1String("y"), QString::number( vec2.y() ) );
0047     writer.writeAttribute( QLatin1String("yunits"), unitToString( vec2.yunit() ) );
0048     writer.writeEndElement();
0049 }
0050 
0051 QString KmlScreenOverlayWriter::unitToString( GeoDataVec2::Unit unit )
0052 {
0053     switch( unit ) {
0054     case GeoDataVec2::Fraction:    return QString::fromUtf8("fraction");
0055     case GeoDataVec2::Pixels:      return QString::fromUtf8("pixels");
0056     case GeoDataVec2::InsetPixels: return QString::fromUtf8("insetPixels");
0057     }
0058 
0059     Q_ASSERT(false);
0060     return QString::fromUtf8("fraction");
0061 }
0062 
0063 }