Marble

KmlColorStyleTagWriter.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2011 Dennis Nienhüser <nienhueser@kde.org>
4//
5
6#include "KmlColorStyleTagWriter.h"
7
8#include "GeoDataColorStyle.h"
9#include "GeoDataTypes.h"
10#include "GeoWriter.h"
11#include "KmlElementDictionary.h"
12#include "KmlObjectTagWriter.h"
13
14namespace Marble
15{
16
17KmlColorStyleTagWriter::KmlColorStyleTagWriter(const QString &elementName)
18 : m_elementName(elementName)
19{
20 // nothing to do
21}
22
23bool KmlColorStyleTagWriter::write(const Marble::GeoNode *node, GeoWriter &writer) const
24{
25 auto const *colorStyle = static_cast<const GeoDataColorStyle *>(node);
26
27 if (colorStyle->id().isEmpty() && colorStyle->targetId().isEmpty() && colorStyle->color() == defaultColor()
28 && colorStyle->colorMode() == GeoDataColorStyle::Normal && isEmpty(node)) {
29 return true;
30 }
31
32 writer.writeStartElement(m_elementName);
33
34 KmlObjectTagWriter::writeIdentifiers(writer, colorStyle);
35 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_color), formatColor(colorStyle->color()), formatColor(defaultColor()));
36 QString const colorMode = colorStyle->colorMode() == GeoDataColorStyle::Random ? QStringLiteral("random") : QStringLiteral("normal");
37 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_colorMode), colorMode, QStringLiteral("normal"));
38
39 bool const result = writeMid(node, writer);
40 writer.writeEndElement();
41 return result;
42}
43
44QString KmlColorStyleTagWriter::formatColor(const QColor &color)
45{
46 QChar const fill = QLatin1Char('0');
47 return QStringLiteral("%1%2%3%4")
48 .arg(color.alpha(), 2, 16, fill)
49 .arg(color.blue(), 2, 16, fill)
50 .arg(color.green(), 2, 16, fill)
51 .arg(color.red(), 2, 16, fill);
52}
53
54QColor KmlColorStyleTagWriter::defaultColor() const
55{
56 return {Qt::white};
57}
58
59}
A shared base class for all classes that are mapped to a specific tag (ie.
Definition GeoDocument.h:35
Binds a QML item to a specific geodetic location in screen coordinates.
int alpha() const const
int blue() const const
int green() const const
int red() const const
QString fromLatin1(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 14 2025 12:00:24 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.