Marble

GeoDataContainer.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2007 Murad Tagirov <tmurad@gmail.com>
4// SPDX-FileCopyrightText: 2009 Patrick Spendrin <ps_ml@gmx.de>
5//
6
7// Own
8#include "GeoDataContainer.h"
9#include "GeoDataContainer_p.h"
10
11// Marble
12#include "GeoDataDocument.h"
13#include "GeoDataFolder.h"
14#include "GeoDataGeometry.h"
15#include "GeoDataGroundOverlay.h"
16#include "GeoDataLatLonAltBox.h"
17#include "GeoDataNetworkLink.h"
18#include "GeoDataNetworkLinkControl.h"
19#include "GeoDataPhotoOverlay.h"
20#include "GeoDataPlacemark.h"
21#include "GeoDataScreenOverlay.h"
22#include "GeoDataTour.h"
23#include "MarbleDebug.h"
24
25#include <QDataStream>
26
27namespace Marble
28{
29
31 : GeoDataFeature(new GeoDataContainerPrivate)
32{
33}
34
35GeoDataContainer::GeoDataContainer(GeoDataContainerPrivate *priv)
36 : GeoDataFeature(priv)
37{
39 d->setParent(this);
40}
41
42GeoDataContainer::GeoDataContainer(const GeoDataContainer &other, GeoDataContainerPrivate *priv)
43 : GeoDataFeature(other, priv)
44{
46 d->setParent(this);
47}
48
49GeoDataContainer::GeoDataContainer(const GeoDataContainer &other)
50 : GeoDataFeature(other, new GeoDataContainerPrivate(*other.d_func()))
51{
53 d->setParent(this);
54}
55
57
58GeoDataContainer &GeoDataContainer::operator=(const GeoDataContainer &other)
59{
60 if (this != &other) {
62 *d = *other.d_func();
63 }
64
65 return *this;
66}
67
68bool GeoDataContainer::equals(const GeoDataContainer &other) const
69{
70 if (!GeoDataFeature::equals(other)) {
71 return false;
72 }
73
74 Q_D(const GeoDataContainer);
75 const GeoDataContainerPrivate *const other_d = other.d_func();
76 QList<GeoDataFeature *>::const_iterator thisBegin = d->m_vector.constBegin();
77 QList<GeoDataFeature *>::const_iterator thisEnd = d->m_vector.constEnd();
78 QList<GeoDataFeature *>::const_iterator otherBegin = other_d->m_vector.constBegin();
79 QList<GeoDataFeature *>::const_iterator otherEnd = other_d->m_vector.constEnd();
80
81 for (; thisBegin != thisEnd && otherBegin != otherEnd; ++thisBegin, ++otherBegin) {
82 if (**thisBegin != **otherBegin) {
83 return false;
84 }
85 }
86
87 return thisBegin == thisEnd && otherBegin == otherEnd;
88}
89
91{
92 Q_D(const GeoDataContainer);
94
95 QList<GeoDataFeature *>::const_iterator it = d->m_vector.constBegin();
96 QList<GeoDataFeature *>::const_iterator end = d->m_vector.constEnd();
97 for (; it != end; ++it) {
98 // Get all the placemarks from GeoDataContainer
99 if (const GeoDataPlacemark *placemark = geodata_cast<GeoDataPlacemark>(*it)) {
100 // Only use visible placemarks for extracting their latLonAltBox and
101 // making an union with the global latLonAltBox Marble will fit its
102 // zoom to
103 if (placemark->isVisible()) {
104 if (result.isEmpty()) {
105 result = placemark->geometry()->latLonAltBox();
106 } else {
107 result |= placemark->geometry()->latLonAltBox();
108 }
109 }
110 } else if (const GeoDataContainer *container = dynamic_cast<GeoDataContainer *>(*it)) {
111 if (result.isEmpty()) {
112 result = container->latLonAltBox();
113 } else {
114 result |= container->latLonAltBox();
115 }
116 }
117 }
118 return result;
119}
120
122{
123 Q_D(const GeoDataContainer);
125
126 QList<GeoDataFeature *>::const_iterator it = d->m_vector.constBegin();
127 QList<GeoDataFeature *>::const_iterator end = d->m_vector.constEnd();
128
129 for (; it != end; ++it) {
130 auto folder = dynamic_cast<GeoDataFolder *>(*it);
131 if (folder) {
132 results.append(folder);
133 }
134 }
135
136 return results;
137}
138
140{
141 Q_D(const GeoDataContainer);
143 for (auto it = d->m_vector.constBegin(), end = d->m_vector.constEnd(); it != end; ++it) {
144 if (auto placemark = geodata_cast<GeoDataPlacemark>(*it)) {
145 results.append(placemark);
146 }
147 }
148 return results;
149}
150
152{
153 Q_D(const GeoDataContainer);
154 return d->m_vector;
155}
156
157/**
158 * @brief returns the requested child item
159 */
161{
163 return d->m_vector.at(i);
164}
165
167{
168 Q_D(const GeoDataContainer);
169 return d->m_vector.at(i);
170}
171
172/**
173 * @brief returns the position of an item in the list
174 */
176{
177 Q_D(const GeoDataContainer);
178 for (int i = 0; i < d->m_vector.size(); ++i) {
179 if (d->m_vector.at(i) == object) {
180 return i;
181 }
182 }
183 return -1;
184}
185
186void GeoDataContainer::insert(GeoDataFeature *other, int index)
187{
188 insert(index, other);
189}
190
192{
194 feature->setParent(this);
195 d->m_vector.insert(index, feature);
196}
197
199{
201 other->setParent(this);
202 d->m_vector.append(other);
203}
204
205void GeoDataContainer::remove(int index)
206{
208 d->m_vector.remove(index);
209}
210
211void GeoDataContainer::remove(int index, int count)
212{
214 d->m_vector.remove(index, count);
215}
216
217int GeoDataContainer::removeAll(GeoDataFeature *feature)
218{
220 return d->m_vector.removeAll(feature);
221}
222
223void GeoDataContainer::removeAt(int index)
224{
226 d->m_vector.removeAt(index);
227}
228
229void GeoDataContainer::removeFirst()
230{
232 d->m_vector.removeFirst();
233}
234
235void GeoDataContainer::removeLast()
236{
238 d->m_vector.removeLast();
239}
240
241bool GeoDataContainer::removeOne(GeoDataFeature *feature)
242{
244 return d->m_vector.removeOne(feature);
245}
246
248{
249 Q_D(const GeoDataContainer);
250 return d->m_vector.size();
251}
252
254{
255 return size() == 0;
256}
257
259{
261 return *(d->m_vector[pos]);
262}
263
264const GeoDataFeature &GeoDataContainer::at(int pos) const
265{
266 Q_D(const GeoDataContainer);
267 return *(d->m_vector.at(pos));
268}
269
271{
273 return *(d->m_vector.last());
274}
275
277{
278 Q_D(const GeoDataContainer);
279 return *(d->m_vector.last());
280}
281
283{
285 return *(d->m_vector.first());
286}
287
289{
290 Q_D(const GeoDataContainer);
291 return *(d->m_vector.first());
292}
293
294void GeoDataContainer::clear()
295{
297 qDeleteAll(d->m_vector);
298 d->m_vector.clear();
299}
300
301QList<GeoDataFeature *>::Iterator GeoDataContainer::begin()
302{
304 return d->m_vector.begin();
305}
306
307QList<GeoDataFeature *>::Iterator GeoDataContainer::end()
308{
310 return d->m_vector.end();
311}
312
313QList<GeoDataFeature *>::ConstIterator GeoDataContainer::constBegin() const
314{
315 Q_D(const GeoDataContainer);
316 return d->m_vector.constBegin();
317}
318
319QList<GeoDataFeature *>::ConstIterator GeoDataContainer::constEnd() const
320{
321 Q_D(const GeoDataContainer);
322 return d->m_vector.constEnd();
323}
324
326{
327 Q_D(const GeoDataContainer);
328 GeoDataFeature::pack(stream);
329
330 stream << d->m_vector.count();
331
332 for (QList<GeoDataFeature *>::const_iterator iterator = d->m_vector.constBegin(); iterator != d->m_vector.constEnd(); ++iterator) {
333 const GeoDataFeature *feature = *iterator;
334 stream << feature->featureId();
335 feature->pack(stream);
336 }
337}
338
340{
343
344 int count;
345 stream >> count;
346
347 for (int i = 0; i < count; ++i) {
348 int featureId;
349 stream >> featureId;
350 switch (featureId) {
351 case GeoDataDocumentId:
352 /* not usable!!!! */ break;
353 case GeoDataFolderId: {
354 auto folder = new GeoDataFolder;
355 folder->unpack(stream);
356 d->m_vector.append(folder);
357 } break;
358 case GeoDataPlacemarkId: {
359 auto placemark = new GeoDataPlacemark;
360 placemark->unpack(stream);
361 d->m_vector.append(placemark);
362 } break;
363 case GeoDataNetworkLinkId:
364 break;
365 case GeoDataScreenOverlayId:
366 break;
367 case GeoDataGroundOverlayId:
368 break;
369 default:
370 break;
371 };
372 }
373}
374
375}
A base class that can hold GeoDataFeatures.
GeoDataFeature & first()
return the reference of the last element for convenience
int childPosition(const GeoDataFeature *child) const
returns the position of an item in the list
GeoDataLatLonAltBox latLonAltBox() const
A convenience function that returns the LatLonAltBox of all placemarks in this container.
int size() const
size of the container
void append(GeoDataFeature *other)
add an element
QList< GeoDataFolder * > folderList() const
A convenience function that returns all folders in this container.
GeoDataFeature * child(int)
returns the requested child item
bool isEmpty() const
Returns true if the container has size 0; otherwise returns false.
void pack(QDataStream &stream) const override
Serialize the container to a stream.
QList< GeoDataFeature * > featureList() const
A convenience function that returns all features in this container.
void unpack(QDataStream &stream) override
Unserialize the container from a stream.
~GeoDataContainer() override
Destruct the GeoDataContainer.
GeoDataFeature & last()
return the reference of the last element for convenience
QList< GeoDataPlacemark * > placemarkList() const
A convenience function that returns all placemarks in this container.
GeoDataFeature & at(int pos)
return the reference of the element at a specific position
void insert(int index, GeoDataFeature *feature)
inserts feature at position index in the container
GeoDataContainer()
Default constructor.
A base class for all geodata features.
void unpack(QDataStream &stream) override
Unserialize the contents of the feature from stream.
void pack(QDataStream &stream) const override
Serialize the contents of the feature to stream.
A container that is used to arrange other GeoDataFeatures.
A class that defines a 3D bounding box for geographic data.
virtual bool isEmpty() const
Indicates whether the bounding box is not initialised (and contains nothing).
void setParent(GeoDataObject *parent)
Sets the parent of the object.
a class representing a point of interest on the map
void unpack(QDataStream &stream) override
Deserialize the Placemark from a data stream.
Binds a QML item to a specific geodetic location in screen coordinates.
T * geodata_cast(GeoDataObject *node)
Returns the given node cast to type T if the node was instantiated as type T; otherwise returns 0.
void append(QList< T > &&value)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.