Marble

KmlSimpleFieldTagHandler.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Patrick Spendrin <ps_ml@gmx.de>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "KmlSimpleFieldTagHandler.h"
8
9#include "MarbleDebug.h"
10
11#include "KmlElementDictionary.h"
12#include "GeoDataSchema.h"
13
14#include "GeoParser.h"
15
16namespace Marble
17{
18namespace kml
19{
20KML_DEFINE_TAG_HANDLER( SimpleField )
21
22GeoNode* KmlSimpleFieldTagHandler::parse( GeoParser& parser ) const
23{
24 Q_ASSERT(parser.isStartElement() && parser.isValidElement(QLatin1String(kmlTag_SimpleField)));
25
26 GeoStackItem parentItem = parser.parentElement();
27
28 if( parentItem.represents( kmlTag_Schema ) ) {
29 GeoDataSimpleField simpleField;
30 QString name = parser.attribute( "name" ).trimmed();
31 QString type = parser.attribute( "type" ).trimmed();
32 simpleField.setName( name );
33 GeoDataSimpleField::SimpleFieldType fieldType = resolveType( type );
34 simpleField.setType( fieldType );
35 parentItem.nodeAs<GeoDataSchema>()->addSimpleField( simpleField );
36 return &parentItem.nodeAs<GeoDataSchema>()->simpleField( name );
37 }
38
39 return nullptr;
40}
41
42GeoDataSimpleField::SimpleFieldType KmlSimpleFieldTagHandler::resolveType( const QString& type )
43{
44 GeoDataSimpleField::SimpleFieldType fieldType;
45 if (type == QLatin1String("string")) {
46 fieldType = GeoDataSimpleField::String;
47 }
48 else if (type == QLatin1String("int")) {
49 fieldType = GeoDataSimpleField::Int;
50 }
51 else if (type == QLatin1String("unit")) {
52 fieldType = GeoDataSimpleField::UInt;
53 }
54 else if (type == QLatin1String("short")) {
55 fieldType = GeoDataSimpleField::Short;
56 }
57 else if (type == QLatin1String("ushort")) {
58 fieldType = GeoDataSimpleField::UShort;
59 }
60 else if (type == QLatin1String("float")) {
61 fieldType = GeoDataSimpleField::Float;
62 }
63 else if (type == QLatin1String("double")) {
64 fieldType = GeoDataSimpleField::Double;
65 }
66 else {
67 fieldType = GeoDataSimpleField::Bool;
68 }
69 return fieldType;
70}
71
72}
73}
Type type(const QSqlDatabase &db)
QString name(StandardShortcut id)
Binds a QML item to a specific geodetic location in screen coordinates.
QString trimmed() 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.