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 <QRegularExpression>
10
11#include "GeoDataBalloonStyle.h"
12#include "GeoDataTypes.h"
13#include "GeoWriter.h"
14#include "KmlColorStyleTagWriter.h"
15#include "KmlElementDictionary.h"
16#include "KmlObjectTagWriter.h"
17
18namespace Marble
19{
20
21static GeoTagWriterRegistrar s_writerBallonStyle(GeoTagWriter::QualifiedName(QString::fromLatin1(GeoDataTypes::GeoDataBalloonStyleType),
22 QString::fromLatin1(kml::kmlTag_nameSpaceOgc22)),
23 new KmlBalloonStyleTagWriter());
24
25bool KmlBalloonStyleTagWriter::write(const GeoNode *node, GeoWriter &writer) const
26{
27 const auto balloonStyle = static_cast<const GeoDataBalloonStyle *>(node);
28 bool const isEmpty = balloonStyle->backgroundColor() == QColor(Qt::white) && balloonStyle->textColor() == QColor(Qt::black)
29 && balloonStyle->text().isEmpty() && balloonStyle->displayMode() == GeoDataBalloonStyle::Default;
30 if (isEmpty) {
31 return true;
32 }
33
34 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_BalloonStyle));
35 KmlObjectTagWriter::writeIdentifiers(writer, balloonStyle);
36
37 QString const backgroundColor = KmlColorStyleTagWriter::formatColor(balloonStyle->backgroundColor());
38 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_bgColor), backgroundColor, QStringLiteral("ffffffff"));
39 QString const textColor = KmlColorStyleTagWriter::formatColor(balloonStyle->textColor());
40 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_textColor), textColor, QStringLiteral("ff000000"));
41
42 QString const textString = balloonStyle->text();
43 if (textString.contains(QRegularExpression(QStringLiteral("[<>&]")))) {
44 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_text));
45 writer.writeCDATA(textString);
46 writer.writeEndElement();
47 } else {
48 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_text), textString);
49 }
50
51 if (balloonStyle->displayMode() == GeoDataBalloonStyle::Hide) {
52 writer.writeElement(QString::fromLatin1(kml::kmlTag_displayMode), QStringLiteral("hide"));
53 }
54
55 writer.writeEndElement();
56 return true;
57}
58
59}
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
QString fromLatin1(QByteArrayView str)
QString fromUtf8(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.