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 "GeoDataSchema.h"
12#include "KmlElementDictionary.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(QLatin1StringView(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 == QLatin1StringView("string")) {
46 fieldType = GeoDataSimpleField::String;
47 } else if (type == QLatin1StringView("int")) {
48 fieldType = GeoDataSimpleField::Int;
49 } else if (type == QLatin1StringView("unit")) {
50 fieldType = GeoDataSimpleField::UInt;
51 } else if (type == QLatin1StringView("short")) {
52 fieldType = GeoDataSimpleField::Short;
53 } else if (type == QLatin1StringView("ushort")) {
54 fieldType = GeoDataSimpleField::UShort;
55 } else if (type == QLatin1StringView("float")) {
56 fieldType = GeoDataSimpleField::Float;
57 } else if (type == QLatin1StringView("double")) {
58 fieldType = GeoDataSimpleField::Double;
59 } else {
60 fieldType = GeoDataSimpleField::Bool;
61 }
62 return fieldType;
63}
64
65}
66}
Type type(const QSqlDatabase &db)
QString name(StandardAction 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 Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.