Marble

KmlBalloonStyleTagWriter.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2012 Mayank Madan <maddiemadan@gmail.com>
4// SPDX-FileCopyrightText: 2013 Dennis Nienhüser <nienhueser@kde.org>
5//
6
7#include "KmlBalloonStyleTagWriter.h"
8
9#include "GeoDataBalloonStyle.h"
10#include "GeoDataTypes.h"
11#include "GeoWriter.h"
12#include "KmlElementDictionary.h"
13#include "KmlColorStyleTagWriter.h"
14#include "KmlObjectTagWriter.h"
15
16namespace Marble
17{
18
19static GeoTagWriterRegistrar s_writerBallonStyle( GeoTagWriter::QualifiedName(GeoDataTypes::GeoDataBalloonStyleType,
20 kml::kmlTag_nameSpaceOgc22),
21 new KmlBalloonStyleTagWriter() );
22
23bool KmlBalloonStyleTagWriter::write( const GeoNode *node,
24 GeoWriter& writer ) const
25{
26 const GeoDataBalloonStyle *balloonStyle = static_cast<const GeoDataBalloonStyle*>( node );
27 bool const isEmpty = balloonStyle->backgroundColor() == QColor( Qt::white ) &&
28 balloonStyle->textColor() == QColor( Qt::black ) &&
29 balloonStyle->text().isEmpty() &&
30 balloonStyle->displayMode() == GeoDataBalloonStyle::Default;
31 if ( isEmpty ) {
32 return true;
33 }
34
35 writer.writeStartElement( kml::kmlTag_BalloonStyle );
36 KmlObjectTagWriter::writeIdentifiers( writer, balloonStyle );
37
38 QString const backgroundColor = KmlColorStyleTagWriter::formatColor( balloonStyle->backgroundColor() );
39 writer.writeOptionalElement( kml::kmlTag_bgColor, backgroundColor, "ffffffff" );
40 QString const textColor = KmlColorStyleTagWriter::formatColor( balloonStyle->textColor() );
41 writer.writeOptionalElement( kml::kmlTag_textColor, textColor, "ff000000" );
42
43 QString const textString = balloonStyle->text();
44 if ( textString.contains( QRegExp( "[<>&]" ) ) ) {
45 writer.writeStartElement( kml::kmlTag_text );
46 writer.writeCDATA( textString );
47 writer.writeEndElement();
48 } else {
49 writer.writeOptionalElement( kml::kmlTag_text, textString );
50 }
51
52 if ( balloonStyle->displayMode() == GeoDataBalloonStyle::Hide ) {
53 writer.writeElement( kml::kmlTag_displayMode, "hide" );
54 }
55
56 writer.writeEndElement();
57 return true;
58}
59
60}
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.
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.