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 "GeoDataTypes.h"
9#include "GeoDataColorStyle.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 GeoDataColorStyle const *colorStyle = static_cast<const GeoDataColorStyle*>(node);
26
27 if ( colorStyle->id().isEmpty() &&
28 colorStyle->targetId().isEmpty() &&
29 colorStyle->color() == defaultColor() &&
30 colorStyle->colorMode() == GeoDataColorStyle::Normal &&
31 isEmpty( node ) ) {
32 return true;
33 }
34
35 writer.writeStartElement( m_elementName );
36
37 KmlObjectTagWriter::writeIdentifiers( writer, colorStyle);
38 writer.writeOptionalElement( kml::kmlTag_color, formatColor( colorStyle->color() ), formatColor( defaultColor() ) );
39 QString const colorMode = colorStyle->colorMode() == GeoDataColorStyle::Random ? "random" : "normal";
40 writer.writeOptionalElement( kml::kmlTag_colorMode, colorMode, "normal" );
41
42 bool const result = writeMid( node, writer );
43 writer.writeEndElement();
44 return result;
45}
46
47QString KmlColorStyleTagWriter::formatColor( const QColor &color )
48{
49 QChar const fill = QLatin1Char('0');
50 return QString( "%1%2%3%4" )
51 .arg( color.alpha(), 2, 16, fill )
52 .arg( color.blue(), 2, 16, fill )
53 .arg( color.green(), 2, 16, fill )
54 .arg( color.red(), 2, 16, fill );
55}
56
57QColor KmlColorStyleTagWriter::defaultColor() const
58{
59 return QColor( Qt::white );
60}
61
62}
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 arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 7 2024 12:03:13 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.