Marble

KmlSimpleFieldTagHandler.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Patrick Spendrin <[email protected]>
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 
16 namespace Marble
17 {
18 namespace kml
19 {
20 KML_DEFINE_TAG_HANDLER( SimpleField )
21 
22 GeoNode* 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 
42 GeoDataSimpleField::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 trimmed() const const
Binds a QML item to a specific geodetic location in screen coordinates.
QString name(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Oct 2 2023 03:52:09 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.