KOSMIndoorMap

osmelement.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "osmelement.h"
8
9#include <QJSValueIterator>
10#include <QLocale>
11
12using namespace KOSMIndoorMap;
13
14OSMElement::OSMElement() = default;
15OSMElement::OSMElement(OSM::Element e)
16 : m_element(e)
17{
18}
19
20OSMElement::~OSMElement() = default;
21
22bool OSMElement::isNull() const
23{
24 return m_element.type() == OSM::Type::Null;
25}
26
27qint64 OSMElement::id() const
28{
29 return m_element.id();
30}
31
32QString OSMElement::name() const
33{
34 return QString::fromUtf8(m_element.tagValue(OSM::Languages::fromQLocale(QLocale()), "name"));
35}
36
37QString OSMElement::url() const
38{
39 return m_element.url();
40}
41
42QPointF OSMElement::center() const
43{
44 const auto c = m_element.center();
45 return {c.lonF(), c.latF() };
46}
47
48QString OSMElement::tagValue(const QJSValue &key) const
49{
50 if (key.isString()) {
51 return QString::fromUtf8(m_element.tagValue(key.toString().toUtf8().constData()));
52 }
53 if (key.isArray()) {
54 for (QJSValueIterator it(key); it.hasNext();) {
55 it.next();
56 auto v = m_element.tagValue(it.value().toString().toUtf8().constData());
57 if (!v.isEmpty()) {
58 return QString::fromUtf8(v);
59 }
60 }
61 }
62
63 return {};
64}
65
66OSM::Element OSMElement::element() const
67{
68 return m_element;
69}
70
71#include "moc_osmelement.cpp"
A reference to any of OSM::Node/OSM::Way/OSM::Relation.
Definition element.h:24
static KOSM_EXPORT Languages fromQLocale(const QLocale &locale)
Convert QLocale::uiLanguages() into an OSM::Languages set.
Definition languages.cpp:40
OSM-based multi-floor indoor maps for buildings.
const char * constData() const const
bool isArray() const const
bool isString() const const
QString toString() const const
bool hasNext() const const
QString fromUtf8(QByteArrayView str)
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:55 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.