Marble

KmlColorStyleTagWriter.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2011 Dennis Nienhüser <[email protected]>
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 
14 namespace Marble
15 {
16 
17 KmlColorStyleTagWriter::KmlColorStyleTagWriter(const QString &elementName)
18  : m_elementName( elementName )
19 {
20  // nothing to do
21 }
22 
23 bool 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 
47 QString 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 
57 QColor KmlColorStyleTagWriter::defaultColor() const
58 {
59  return QColor( Qt::white );
60 }
61 
62 }
int red() const const
A shared base class for all classes that are mapped to a specific tag (ie.
Definition: GeoDocument.h:34
int alpha() const const
int green() const const
Binds a QML item to a specific geodetic location in screen coordinates.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
int blue() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:27 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.