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{
12
13GeoDataBuilding::GeoDataBuilding()
14 : GeoDataGeometry(new GeoDataBuildingPrivate)
15 , d(new GeoDataBuildingPrivate)
16{
17}
18
19GeoDataBuilding::GeoDataBuilding(const GeoDataGeometry &other)
20 : GeoDataGeometry(other)
21 , d(new GeoDataBuildingPrivate)
22{
23}
24
25GeoDataBuilding::GeoDataBuilding(const GeoDataBuilding &other)
26 : GeoDataGeometry(other)
27 , d(new GeoDataBuildingPrivate(*other.d))
28{
29}
30
31GeoDataBuilding::~GeoDataBuilding()
32{
33 delete d;
34}
35
36GeoDataBuilding &GeoDataBuilding::operator=(const GeoDataBuilding &other)
37{
38 GeoDataGeometry::operator=(other);
39 *d = *other.d;
40 return *this;
41}
42
43const char *GeoDataBuilding::nodeType() const
44{
45 return GeoDataTypes::GeoDataBuildingType;
46}
47
48EnumGeometryId GeoDataBuilding::geometryId() const
49{
50 return GeoDataBuildingId;
51}
52
53GeoDataGeometry *GeoDataBuilding::copy() const
54{
55 return new GeoDataBuilding(*this);
56}
57
58double GeoDataBuilding::height() const
59{
60 return d->m_height;
61}
62
63void GeoDataBuilding::setHeight(double height)
64{
65 d->m_height = height;
66}
67
68int GeoDataBuilding::minLevel() const
69{
70 return d->m_minLevel;
71}
72
73void GeoDataBuilding::setMinLevel(int minLevel)
74{
75 d->m_minLevel = minLevel;
76}
77
78int GeoDataBuilding::maxLevel() const
79{
80 return d->m_maxLevel;
81}
82
83void GeoDataBuilding::setMaxLevel(int maxLevel)
84{
85 d->m_maxLevel = maxLevel;
86}
87
88QList<int> GeoDataBuilding::nonExistentLevels() const
89{
90 return d->m_nonExistentLevels;
91}
92
93void GeoDataBuilding::setNonExistentLevels(const QList<int> &nonExistentLevels)
94{
95 d->m_nonExistentLevels = nonExistentLevels;
96}
97
98GeoDataMultiGeometry *GeoDataBuilding::multiGeometry() const
99{
100 return &d->m_multiGeometry;
101}
102
103const GeoDataLatLonAltBox &GeoDataBuilding::latLonAltBox() const
104{
105 // @TODO: This is temporary, for only when we have just one child
106 Q_ASSERT(d->m_multiGeometry.size() == 1);
107 return static_cast<const GeoDataMultiGeometry>(d->m_multiGeometry).at(0).latLonAltBox();
108}
109
110QString GeoDataBuilding::name() const
111{
112 return d->m_name;
113}
114
115void GeoDataBuilding::setName(const QString &name)
116{
117 d->m_name = name;
118}
119
120QList<GeoDataBuilding::NamedEntry> GeoDataBuilding::entries() const
121{
122 return d->m_entries;
123}
124
125void GeoDataBuilding::setEntries(const QList<GeoDataBuilding::NamedEntry> &entries)
126{
127 d->m_entries = entries;
128}
129
130double GeoDataBuilding::parseBuildingHeight(const QString &buildingHeight)
131{
132 double height = 8.0;
133
134 // check first for unitless value
135 bool converted;
136 double extractedHeight = buildingHeight.toDouble(&converted);
137 if (converted) {
138 return extractedHeight;
139 }
140
141 if (buildingHeight.endsWith(QLatin1Char('m')) || buildingHeight.endsWith(QLatin1StringView("meter")) || buildingHeight.endsWith(QLatin1StringView("meters"))
142 || buildingHeight.endsWith(QLatin1StringView("metre")) || buildingHeight.endsWith(QLatin1StringView("metres"))) {
143 QString const heightValue = QString(buildingHeight)
144 .remove(QStringLiteral("meters"))
145 .remove(QStringLiteral("meter"))
146 .remove(QStringLiteral("metres"))
147 .remove(QStringLiteral("metre"))
148 .remove(QLatin1Char('m'))
149 .trimmed();
150 bool extracted;
151 double extractedHeight = heightValue.toDouble(&extracted);
152 if (extracted) {
153 height = extractedHeight;
154 }
155 } else { // feet and inches
156 double extractedHeight = 0.0; // in inches, converted to meters in the end
157 if (buildingHeight.contains(QLatin1Char('\''))) {
158 double heightInches = 0.0;
159 QStringList const feetInches = buildingHeight.split(QLatin1Char('\''));
160 bool okFeet;
161 double feet = feetInches[0].trimmed().toDouble(&okFeet);
162 if (okFeet) {
163 heightInches = feet * FT2IN;
164 }
165 if (!feetInches[1].isEmpty()) { // has inches as unit as well
166 bool okInches;
167 double inches = QString(feetInches[1]).remove(QLatin1Char('\"')).trimmed().toDouble(&okInches);
168 if (okInches) {
169 heightInches += inches;
170 }
171 }
172 extractedHeight = heightInches;
173 } else if (buildingHeight.endsWith(QLatin1StringView("feet"))) {
174 bool ok;
175 double feet = QString(buildingHeight).remove(QStringLiteral("feet")).trimmed().toDouble(&ok);
176 if (ok) {
177 extractedHeight = feet * FT2IN;
178 }
179 }
180 if (extractedHeight > 0.0) {
181 height = extractedHeight * IN2M; // convert inches to meters
182 }
183 }
184
185 return height;
186}
187
188}
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 Nov 29 2024 11:55:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.