Marble

GeoDataBuilding.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2017 Mohammed Nafees <nafees.technocool@gmail.com>
4//
5
6#include "GeoDataBuilding.h"
7#include "GeoDataBuilding_p.h"
8#include "GeoDataTypes.h"
9
10namespace Marble {
11
12GeoDataBuilding::GeoDataBuilding()
13 : GeoDataGeometry(new GeoDataBuildingPrivate),
14 d(new GeoDataBuildingPrivate)
15{
16}
17
18GeoDataBuilding::GeoDataBuilding(const GeoDataGeometry &other)
19 : GeoDataGeometry(other),
20 d(new GeoDataBuildingPrivate)
21{
22}
23
24GeoDataBuilding::GeoDataBuilding(const GeoDataBuilding &other)
25 : GeoDataGeometry(other),
26 d(new GeoDataBuildingPrivate(*other.d))
27{
28}
29
30GeoDataBuilding::~GeoDataBuilding()
31{
32 delete d;
33}
34
35GeoDataBuilding& GeoDataBuilding::operator=(const GeoDataBuilding& other)
36{
37 GeoDataGeometry::operator=(other);
38 *d = *other.d;
39 return *this;
40}
41
42const char *GeoDataBuilding::nodeType() const
43{
44 return GeoDataTypes::GeoDataBuildingType;
45}
46
47EnumGeometryId GeoDataBuilding::geometryId() const
48{
49 return GeoDataBuildingId;
50}
51
52GeoDataGeometry *GeoDataBuilding::copy() const
53{
54 return new GeoDataBuilding(*this);
55}
56
57double GeoDataBuilding::height() const
58{
59 return d->m_height;
60}
61
62void GeoDataBuilding::setHeight(double height)
63{
64 d->m_height = height;
65}
66
67int GeoDataBuilding::minLevel() const
68{
69 return d->m_minLevel;
70}
71
72void GeoDataBuilding::setMinLevel(int minLevel)
73{
74 d->m_minLevel = minLevel;
75}
76
77int GeoDataBuilding::maxLevel() const
78{
79 return d->m_maxLevel;
80}
81
82void GeoDataBuilding::setMaxLevel(int maxLevel)
83{
84 d->m_maxLevel = maxLevel;
85}
86
87QVector<int> GeoDataBuilding::nonExistentLevels() const
88{
89 return d->m_nonExistentLevels;
90}
91
92void GeoDataBuilding::setNonExistentLevels(const QVector<int> &nonExistentLevels)
93{
94 d->m_nonExistentLevels = nonExistentLevels;
95}
96
97GeoDataMultiGeometry* GeoDataBuilding::multiGeometry() const
98{
99 return &d->m_multiGeometry;
100}
101
102const GeoDataLatLonAltBox &GeoDataBuilding::latLonAltBox() const
103{
104 // @TODO: This is temporary, for only when we have just one child
105 Q_ASSERT(d->m_multiGeometry.size() == 1);
106 return static_cast<const GeoDataMultiGeometry>(d->m_multiGeometry).at(0).latLonAltBox();
107}
108
109QString GeoDataBuilding::name() const
110{
111 return d->m_name;
112}
113
114void GeoDataBuilding::setName(const QString& name)
115{
116 d->m_name = name;
117}
118
119QVector<GeoDataBuilding::NamedEntry> GeoDataBuilding::entries() const
120{
121 return d->m_entries;
122}
123
124void GeoDataBuilding::setEntries(const QVector<GeoDataBuilding::NamedEntry> &entries)
125{
126 d->m_entries = entries;
127}
128
129double GeoDataBuilding::parseBuildingHeight(const QString& buildingHeight)
130{
131 double height = 8.0;
132
133 // check first for unitless value
134 bool converted;
135 double extractedHeight = buildingHeight.toDouble(&converted);
136 if (converted) {
137 return extractedHeight;
138 }
139
140 if (buildingHeight.endsWith(QChar('m')) ||
141 buildingHeight.endsWith(QLatin1String("meter")) ||
142 buildingHeight.endsWith(QLatin1String("meters")) ||
143 buildingHeight.endsWith(QLatin1String("metre")) ||
144 buildingHeight.endsWith(QLatin1String("metres"))) {
145 QString const heightValue = QString(buildingHeight).remove(QStringLiteral("meters"))
146 .remove(QStringLiteral("meter")).remove(QStringLiteral("metres"))
147 .remove(QStringLiteral("metre")).remove(QChar('m')).trimmed();
148 bool extracted;
149 double extractedHeight = heightValue.toDouble(&extracted);
150 if (extracted) {
151 height = extractedHeight;
152 }
153 } else { // feet and inches
154 double extractedHeight = 0.0; // in inches, converted to meters in the end
155 if (buildingHeight.contains(QChar('\''))) {
156 double heightInches = 0.0;
157 QStringList const feetInches = buildingHeight.split(QChar('\''));
158 bool okFeet;
159 double feet = feetInches[0].trimmed().toDouble(&okFeet);
160 if (okFeet) {
161 heightInches = feet * FT2IN;
162 }
163 if (!feetInches[1].isEmpty()) { // has inches as unit as well
164 bool okInches;
165 double inches = QString(feetInches[1]).remove(QChar('\"')).trimmed().toDouble(&okInches);
166 if (okInches) {
167 heightInches += inches;
168 }
169 }
170 extractedHeight = heightInches;
171 } else if (buildingHeight.endsWith(QLatin1String("feet"))) {
172 bool ok;
173 double feet = QString(buildingHeight).remove(QStringLiteral("feet")).trimmed().toDouble(&ok);
174 if (ok) {
175 extractedHeight = feet * FT2IN;
176 }
177 }
178 if (extractedHeight > 0.0) {
179 height = extractedHeight * IN2M; // convert inches to meters
180 }
181 }
182
183 return height;
184}
185
186}
Contains important information about a building and its floors (levels)
A class that defines a 3D bounding box for geographic data.
A class that can contain other GeoDataGeometry objects.
Binds a QML item to a specific geodetic location in screen coordinates.
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
double toDouble(bool *ok) const const
QString trimmed() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.