Marble

GeoDataMultiGeometry.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2008 Patrick Spendrin <ps_ml@gmx.de>
4//
5
6
7#include "GeoDataMultiGeometry.h"
8#include "GeoDataMultiGeometry_p.h"
9
10#include "GeoDataLineString.h"
11#include "GeoDataLinearRing.h"
12#include "GeoDataPoint.h"
13#include "GeoDataPolygon.h"
14#include "GeoDataTypes.h"
15
16#include "MarbleDebug.h"
17
18#include <QDataStream>
19
20
21namespace Marble
22{
23
24GeoDataMultiGeometry::GeoDataMultiGeometry()
25 : GeoDataGeometry( new GeoDataMultiGeometryPrivate )
26{
27}
28
29GeoDataMultiGeometry::GeoDataMultiGeometry( const GeoDataGeometry& other )
30 : GeoDataGeometry( other )
31{
32}
33
34GeoDataMultiGeometry::~GeoDataMultiGeometry()
35{
36}
37
38const char *GeoDataMultiGeometry::nodeType() const
39{
40 return GeoDataTypes::GeoDataMultiGeometryType;
41}
42
43EnumGeometryId GeoDataMultiGeometry::geometryId() const
44{
45 return GeoDataMultiGeometryId;
46}
47
48GeoDataGeometry *GeoDataMultiGeometry::copy() const
49{
50 return new GeoDataMultiGeometry(*this);
51}
52
53bool GeoDataMultiGeometry::operator==(const GeoDataMultiGeometry &other) const
54{
55 Q_D(const GeoDataMultiGeometry);
56 const GeoDataMultiGeometryPrivate *const other_d = other.d_func();
57 QVector<GeoDataGeometry*>::const_iterator thisBegin = d->m_vector.constBegin();
58 QVector<GeoDataGeometry*>::const_iterator thisEnd = d->m_vector.constEnd();
59 QVector<GeoDataGeometry*>::const_iterator otherBegin = other_d->m_vector.constBegin();
60 QVector<GeoDataGeometry*>::const_iterator otherEnd = other_d->m_vector.constEnd();
61
62 for (; thisBegin != thisEnd && otherBegin != otherEnd; ++thisBegin, ++otherBegin) {
63 if (**thisBegin != **otherBegin) {
64 return false;
65 }
66 }
67
68 return true;
69}
70
71const GeoDataLatLonAltBox& GeoDataMultiGeometry::latLonAltBox() const
72{
73 Q_D(const GeoDataMultiGeometry);
74
75 QVector<GeoDataGeometry*>::const_iterator it = d->m_vector.constBegin();
76 QVector<GeoDataGeometry*>::const_iterator end = d->m_vector.constEnd();
77
78 d->m_latLonAltBox.clear();
79 for (; it != end; ++it) {
80 if ( !(*it)->latLonAltBox().isEmpty() ) {
81 if ( d->m_latLonAltBox.isEmpty() ) {
82 d->m_latLonAltBox = (*it)->latLonAltBox();
83 }
84 else {
85 d->m_latLonAltBox |= (*it)->latLonAltBox();
86 }
87 }
88 }
89 return d->m_latLonAltBox;
90}
91
92int GeoDataMultiGeometry::size() const
93{
94 Q_D(const GeoDataMultiGeometry);
95 return d->m_vector.size();
96}
97
98QVector<GeoDataGeometry *> GeoDataMultiGeometry::vector()
99{
100 Q_D(const GeoDataMultiGeometry);
101
102 return d->m_vector;
103}
104
105GeoDataGeometry& GeoDataMultiGeometry::at( int pos )
106{
107 mDebug() << "detaching!";
108 detach();
109
110 Q_D(GeoDataMultiGeometry);
111 return *(d->m_vector[pos]);
112}
113
114const GeoDataGeometry& GeoDataMultiGeometry::at( int pos ) const
115{
116 Q_D(const GeoDataMultiGeometry);
117 return *(d->m_vector.at(pos));
118}
119
120GeoDataGeometry& GeoDataMultiGeometry::operator[]( int pos )
121{
122 detach();
123
124 Q_D(GeoDataMultiGeometry);
125 return *(d->m_vector[pos]);
126}
127
128const GeoDataGeometry& GeoDataMultiGeometry::operator[]( int pos ) const
129{
130 Q_D(const GeoDataMultiGeometry);
131 return *(d->m_vector[pos]);
132}
133
134GeoDataGeometry& GeoDataMultiGeometry::last()
135{
136 detach();
137
138 Q_D(GeoDataMultiGeometry);
139 return *(d->m_vector.last());
140}
141
142GeoDataGeometry& GeoDataMultiGeometry::first()
143{
144 detach();
145
146 Q_D(GeoDataMultiGeometry);
147 return *(d->m_vector.first());
148}
149
150const GeoDataGeometry& GeoDataMultiGeometry::last() const
151{
152 Q_D(const GeoDataMultiGeometry);
153 return *(d->m_vector.last());
154}
155
156const GeoDataGeometry& GeoDataMultiGeometry::first() const
157{
158 Q_D(const GeoDataMultiGeometry);
159 return *(d->m_vector.first());
160}
161
162QVector<GeoDataGeometry*>::Iterator GeoDataMultiGeometry::begin()
163{
164 detach();
165
166 Q_D(GeoDataMultiGeometry);
167 return d->m_vector.begin();
168}
169
170QVector<GeoDataGeometry*>::Iterator GeoDataMultiGeometry::end()
171{
172 detach();
173
174 Q_D(GeoDataMultiGeometry);
175 return d->m_vector.end();
176}
177
178QVector<GeoDataGeometry*>::ConstIterator GeoDataMultiGeometry::constBegin() const
179{
180 Q_D(const GeoDataMultiGeometry);
181 return d->m_vector.constBegin();
182}
183
184QVector<GeoDataGeometry*>::ConstIterator GeoDataMultiGeometry::constEnd() const
185{
186 Q_D(const GeoDataMultiGeometry);
187 return d->m_vector.constEnd();
188}
189
190/**
191 * @brief returns the requested child item
192 */
193GeoDataGeometry* GeoDataMultiGeometry::child( int i )
194{
195 detach();
196
198 return d->m_vector.at(i);
199}
200
201const GeoDataGeometry* GeoDataMultiGeometry::child( int i ) const
202{
204 return d->m_vector.at(i);
205}
206
207/**
208 * @brief returns the position of an item in the list
209 */
210int GeoDataMultiGeometry::childPosition( const GeoDataGeometry *object ) const
211{
213 for (int i = 0; i < d->m_vector.size(); ++i) {
214 if (d->m_vector.at(i) == object) {
215 return i;
216 }
217 }
218 return -1;
219}
220
221/**
222* @brief add an element
223*/
224void GeoDataMultiGeometry::append( GeoDataGeometry *other )
225{
226 detach();
227
229 other->setParent( this );
230 d->m_vector.append(other);
231}
232
233
234GeoDataMultiGeometry& GeoDataMultiGeometry::operator << ( const GeoDataGeometry& value )
235{
236 detach();
237
239 GeoDataGeometry *g = value.copy();
240 g->setParent( this );
241 d->m_vector.append(g);
242 return *this;
243}
244
245void GeoDataMultiGeometry::clear()
246{
247 detach();
248
249 Q_D(GeoDataMultiGeometry);
250 qDeleteAll(d->m_vector);
251 d->m_vector.clear();
252}
253
254void GeoDataMultiGeometry::pack( QDataStream& stream ) const
255{
256 Q_D(const GeoDataMultiGeometry);
257
258 GeoDataGeometry::pack( stream );
259
260 stream << d->m_vector.size();
261
263 = d->m_vector.constBegin();
264 iterator != d->m_vector.constEnd();
265 ++iterator ) {
266 const GeoDataGeometry *geometry = *iterator;
267 stream << geometry->geometryId();
268 geometry->pack( stream );
269 }
270}
271
272void GeoDataMultiGeometry::unpack( QDataStream& stream )
273{
274 detach();
275
276 Q_D(GeoDataMultiGeometry);
277 GeoDataGeometry::unpack( stream );
278
279 int size = 0;
280
281 stream >> size;
282
283 for( int i = 0; i < size; i++ ) {
284 int geometryId;
285 stream >> geometryId;
286 switch( geometryId ) {
287 case InvalidGeometryId:
288 break;
289 case GeoDataPointId:
290 {
291 GeoDataPoint *point = new GeoDataPoint;
292 point->unpack( stream );
293 d->m_vector.append(point);
294 }
295 break;
296 case GeoDataLineStringId:
297 {
298 GeoDataLineString *lineString = new GeoDataLineString;
299 lineString->unpack( stream );
300 d->m_vector.append(lineString);
301 }
302 break;
303 case GeoDataLinearRingId:
304 {
305 GeoDataLinearRing *linearRing = new GeoDataLinearRing;
306 linearRing->unpack( stream );
307 d->m_vector.append(linearRing);
308 }
309 break;
310 case GeoDataPolygonId:
311 {
312 GeoDataPolygon *polygon = new GeoDataPolygon;
313 polygon->unpack( stream );
314 d->m_vector.append(polygon);
315 }
316 break;
317 case GeoDataMultiGeometryId:
318 {
319 GeoDataMultiGeometry *multiGeometry = new GeoDataMultiGeometry;
320 multiGeometry->unpack( stream );
321 d->m_vector.append(multiGeometry);
322 }
323 break;
324 case GeoDataModelId:
325 break;
326 default: break;
327 };
328 }
329}
330
331}
A base class for all geodata features.
A class that can contain other GeoDataGeometry objects.
void setParent(GeoDataObject *parent)
Sets the parent of the object.
const QList< QKeySequence > & end()
Binds a QML item to a specific geodetic location in screen coordinates.
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.