Marble

KmlListStyleTagWriter.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 "KmlListStyleTagWriter.h"
8
9#include "GeoDataTypes.h"
10#include "GeoWriter.h"
11#include "KmlColorStyleTagWriter.h"
12#include "KmlElementDictionary.h"
13
14namespace Marble
15{
16
17static GeoTagWriterRegistrar s_writerListStyle(GeoTagWriter::QualifiedName(QString::fromLatin1(GeoDataTypes::GeoDataListStyleType),
18 QString::fromLatin1(kml::kmlTag_nameSpaceOgc22)),
19 new KmlListStyleTagWriter());
20
21bool KmlListStyleTagWriter::write(const GeoNode *node, GeoWriter &writer) const
22{
23 const auto listStyle = static_cast<const GeoDataListStyle *>(node);
24 bool const isEmpty =
25 listStyle->listItemType() == GeoDataListStyle::Check && listStyle->backgroundColor() == QColor(Qt::white) && listStyle->itemIconList().isEmpty();
26 if (isEmpty) {
27 return true;
28 }
29 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_ListStyle));
30
31 QString const itemType = itemTypeToString(listStyle->listItemType());
32 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_listItemType), itemType, QStringLiteral("check"));
33 QString const color = KmlColorStyleTagWriter::formatColor(listStyle->backgroundColor());
34 writer.writeOptionalElement(QLatin1String(kml::kmlTag_bgColor), color, QStringLiteral("ffffffff"));
35
36 for (GeoDataItemIcon *icon : listStyle->itemIconList()) {
37 writer.writeStartElement(QString::fromLatin1(kml::kmlTag_ItemIcon));
38 QString const state = iconStateToString(icon->state());
39 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_state), state, QStringLiteral("open"));
40 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_href), icon->iconPath());
41 writer.writeEndElement();
42 }
43
44 writer.writeEndElement();
45 return true;
46}
47
48QString KmlListStyleTagWriter::itemTypeToString(GeoDataListStyle::ListItemType itemType)
49{
50 switch (itemType) {
51 case GeoDataListStyle::CheckOffOnly:
52 return QStringLiteral("checkOffOnly");
53 case GeoDataListStyle::CheckHideChildren:
54 return QStringLiteral("checkHideChildren");
55 case GeoDataListStyle::RadioFolder:
56 return QStringLiteral("radioFolder");
57 default:
58 return QStringLiteral("check");
59 }
60}
61
62QString KmlListStyleTagWriter::iconStateToString(GeoDataItemIcon::ItemIconStates state)
63{
64 QStringList stateList;
65 if (state & GeoDataItemIcon::Open) {
66 stateList << QStringLiteral("open");
67 }
68 if (state & GeoDataItemIcon::Closed) {
69 stateList << QStringLiteral("closed");
70 }
71 if (state & GeoDataItemIcon::Error) {
72 stateList << QStringLiteral("error");
73 }
74 if (state & GeoDataItemIcon::Fetching0) {
75 stateList << QStringLiteral("fetching0");
76 }
77 if (state & GeoDataItemIcon::Fetching1) {
78 stateList << QStringLiteral("fetching1");
79 }
80 if (state & GeoDataItemIcon::Fetching2) {
81 stateList << QStringLiteral("fetching2");
82 }
83
84 return stateList.join(QLatin1Char(' '));
85}
86
87}
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.
QString fromLatin1(QByteArrayView str)
QString fromUtf8(QByteArrayView str)
QString join(QChar separator) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:02:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.