Marble

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

KDE's Doxygen guidelines are available online.