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

KDE's Doxygen guidelines are available online.