• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • geodata
  • data
GeoDataContainer.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2007 Murad Tagirov <tmurad@gmail.com>
9 // Copyright 2009 Patrick Spendrin <ps_ml@gmx.de>
10 //
11 
12 
13 // Own
14 #include "GeoDataContainer.h"
15 #include "GeoDataContainer_p.h"
16 
17 // Qt
18 #include <QImage>
19 
20 // Marble
21 #include "MarbleDebug.h"
22 #include "GeoDataFeature.h"
23 #include "GeoDataFolder.h"
24 #include "GeoDataPlacemark.h"
25 #include "GeoDataDocument.h"
26 #include "GeoDataNetworkLinkControl.h"
27 #include "GeoDataNetworkLink.h"
28 #include "GeoDataGroundOverlay.h"
29 #include "GeoDataPhotoOverlay.h"
30 #include "GeoDataScreenOverlay.h"
31 #include "GeoDataTour.h"
32 
33 
34 namespace Marble
35 {
36 
37 GeoDataContainer::GeoDataContainer()
38  : GeoDataFeature( new GeoDataContainerPrivate )
39 {
40 }
41 
42 GeoDataContainer::GeoDataContainer( GeoDataContainerPrivate *priv )
43  : GeoDataFeature( priv )
44 {
45 }
46 
47 GeoDataContainer::GeoDataContainer( const GeoDataContainer& other )
48  : GeoDataFeature( other )
49 {
50 }
51 
52 GeoDataContainer::~GeoDataContainer()
53 {
54 }
55 
56 GeoDataContainerPrivate* GeoDataContainer::p()
57 {
58  return static_cast<GeoDataContainerPrivate*>(d);
59 }
60 
61 const GeoDataContainerPrivate* GeoDataContainer::p() const
62 {
63  return static_cast<GeoDataContainerPrivate*>(d);
64 }
65 
66 bool GeoDataContainer::equals( const GeoDataContainer &other ) const
67 {
68  if ( !GeoDataFeature::equals(other) ) {
69  return false;
70  }
71 
72  QVector<GeoDataFeature*>::const_iterator thisBegin = p()->m_vector.constBegin();
73  QVector<GeoDataFeature*>::const_iterator thisEnd = p()->m_vector.constEnd();
74  QVector<GeoDataFeature*>::const_iterator otherBegin = other.p()->m_vector.constBegin();
75  QVector<GeoDataFeature*>::const_iterator otherEnd = other.p()->m_vector.constEnd();
76 
77  for (; thisBegin != thisEnd && otherBegin != otherEnd; ++thisBegin, ++otherBegin) {
78  if ( (*thisBegin)->nodeType() != (*otherBegin)->nodeType() ) {
79  return false;
80  }
81 
82  if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
83  GeoDataDocument *thisDoc = static_cast<GeoDataDocument*>( *thisBegin );
84  GeoDataDocument *otherDoc = static_cast<GeoDataDocument*>( *otherBegin );
85  Q_ASSERT( thisDoc && otherDoc );
86 
87  if ( *thisDoc != *otherDoc ) {
88  return false;
89  }
90  } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataFolderType ) {
91  GeoDataFolder *thisFolder = static_cast<GeoDataFolder*>( *thisBegin );
92  GeoDataFolder *otherFolder = static_cast<GeoDataFolder*>( *otherBegin );
93  Q_ASSERT( thisFolder && otherFolder );
94 
95  if ( *thisFolder != *otherFolder ) {
96  return false;
97  }
98  } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataNetworkLinkControlType ) {
99  GeoDataNetworkLinkControl *thisNLC = static_cast<GeoDataNetworkLinkControl*>( *thisBegin );
100  GeoDataNetworkLinkControl *otherNLC = static_cast<GeoDataNetworkLinkControl*>( *otherBegin );
101  Q_ASSERT( thisNLC && otherNLC );
102 
103  if ( *thisNLC != *otherNLC ) {
104  return false;
105  }
106  } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataNetworkLinkType ) {
107  GeoDataNetworkLink *thisNetLink = static_cast<GeoDataNetworkLink*>( *thisBegin );
108  GeoDataNetworkLink *otherNetLink = static_cast<GeoDataNetworkLink*>( *otherBegin );
109  Q_ASSERT( thisNetLink && otherNetLink );
110 
111  if ( *thisNetLink != *otherNetLink ) {
112  return false;
113  }
114  } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataGroundOverlayType ) {
115  GeoDataGroundOverlay *thisGO = static_cast<GeoDataGroundOverlay*>( *thisBegin );
116  GeoDataGroundOverlay *otherGO = static_cast<GeoDataGroundOverlay*>( *otherBegin );
117  Q_ASSERT( thisGO && otherGO );
118 
119  if ( *thisGO != *otherGO ) {
120  return false;
121  }
122  } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataPhotoOverlayType ) {
123  GeoDataPhotoOverlay *thisPO = static_cast<GeoDataPhotoOverlay*>( *thisBegin );
124  GeoDataPhotoOverlay *otherPO = static_cast<GeoDataPhotoOverlay*>( *otherBegin );
125  Q_ASSERT( thisPO && otherPO );
126 
127  if ( *thisPO != *otherPO ) {
128  return false;
129  }
130  } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataScreenOverlayType ) {
131  GeoDataScreenOverlay *thisSO = static_cast<GeoDataScreenOverlay*>( *thisBegin );
132  GeoDataScreenOverlay *otherSO = static_cast<GeoDataScreenOverlay*>( *otherBegin );
133  Q_ASSERT( thisSO && otherSO );
134 
135  if ( *thisSO != *otherSO ) {
136  return false;
137  }
138  } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataTourType ) {
139  GeoDataTour *thisTour = static_cast<GeoDataTour*>( *thisBegin );
140  GeoDataTour *otherTour = static_cast<GeoDataTour*>( *otherBegin );
141  Q_ASSERT( thisTour && otherTour );
142 
143  if ( *thisTour != *otherTour ) {
144  return false;
145  }
146  } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
147  GeoDataPlacemark *thisPM = static_cast<GeoDataPlacemark*>( *thisBegin );
148  GeoDataPlacemark *otherPM = static_cast<GeoDataPlacemark*>( *otherBegin );
149  Q_ASSERT( thisPM && otherPM );
150 
151  if ( *thisPM != *otherPM ) {
152  return false;
153  }
154  }
155  }
156 
157  return thisBegin == thisEnd && otherBegin == otherEnd;
158 }
159 
160 GeoDataLatLonAltBox GeoDataContainer::latLonAltBox() const
161 {
162  GeoDataLatLonAltBox result;
163 
164  QVector<GeoDataFeature*>::const_iterator it = p()->m_vector.constBegin();
165  QVector<GeoDataFeature*>::const_iterator end = p()->m_vector.constEnd();
166  for (; it != end; ++it) {
167 
168  // Get all the placemarks from GeoDataContainer
169  if ( (*it)->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
170  GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>(*it);
171 
172  // Only use visible placemarks for extracting their latLonAltBox and
173  // making an union with the global latLonAltBox Marble will fit its
174  // zoom to
175  if (placemark->isVisible())
176  {
177  if (result.isEmpty()) {
178  result = placemark->geometry()->latLonAltBox();
179  } else {
180  result |= placemark->geometry()->latLonAltBox();
181  }
182  }
183  }
184  else if ( (*it)->nodeType() == GeoDataTypes::GeoDataFolderType
185  || (*it)->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
186  GeoDataContainer *container = static_cast<GeoDataContainer*>(*it);
187  if (result.isEmpty()) {
188  result = container->latLonAltBox();
189  } else {
190  result |= container->latLonAltBox();
191  }
192  }
193  }
194  return result;
195 }
196 
197 QVector<GeoDataFolder*> GeoDataContainer::folderList() const
198 {
199  QVector<GeoDataFolder*> results;
200 
201  QVector<GeoDataFeature*>::const_iterator it = p()->m_vector.constBegin();
202  QVector<GeoDataFeature*>::const_iterator end = p()->m_vector.constEnd();
203 
204  for (; it != end; ++it) {
205  GeoDataFolder *folder = dynamic_cast<GeoDataFolder*>(*it);
206  if ( folder ) {
207  results.append( folder );
208  }
209  }
210 
211  return results;
212 }
213 
214 QVector<GeoDataPlacemark*> GeoDataContainer::placemarkList() const
215 {
216  QVector<GeoDataPlacemark*> results;
217 
218  QVector<GeoDataFeature*>::const_iterator it = p()->m_vector.constBegin();
219  QVector<GeoDataFeature*>::const_iterator end = p()->m_vector.constEnd();
220 
221  for (; it != end; ++it) {
222  GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( *it );
223  if ( placemark ) {
224  results.append( placemark );
225  }
226  }
227 
228  return results;
229 }
230 
231 QVector<GeoDataFeature*> GeoDataContainer::featureList() const
232 {
233  return p()->m_vector;
234 }
235 
239 GeoDataFeature* GeoDataContainer::child( int i )
240 {
241  return p()->m_vector.at(i);
242 }
243 
244 const GeoDataFeature* GeoDataContainer::child( int i ) const
245 {
246  return p()->m_vector.at(i);
247 }
248 
252 int GeoDataContainer::childPosition( const GeoDataFeature* object ) const
253 {
254  for ( int i=0; i< p()->m_vector.size(); i++ )
255  {
256  if ( p()->m_vector.at( i ) == object )
257  {
258  return i;
259  }
260  }
261  return -1;
262 }
263 
264 
265 void GeoDataContainer::insert( GeoDataFeature *other, int index )
266 {
267  detach();
268  other->setParent(this);
269  p()->m_vector.insert( index, other );
270 }
271 
272 void GeoDataContainer::append( GeoDataFeature *other )
273 {
274  detach();
275  other->setParent(this);
276  p()->m_vector.append( other );
277 }
278 
279 
280 void GeoDataContainer::remove( int index )
281 {
282  detach();
283  p()->m_vector.remove( index );
284 }
285 
286 int GeoDataContainer::size() const
287 {
288  return p()->m_vector.size();
289 }
290 
291 GeoDataFeature& GeoDataContainer::at( int pos )
292 {
293  detach();
294  return *(p()->m_vector[ pos ]);
295 }
296 
297 const GeoDataFeature& GeoDataContainer::at( int pos ) const
298 {
299  return *(p()->m_vector.at( pos ));
300 }
301 
302 GeoDataFeature& GeoDataContainer::last()
303 {
304  detach();
305  return *(p()->m_vector.last());
306 }
307 
308 const GeoDataFeature& GeoDataContainer::last() const
309 {
310  return *(p()->m_vector.last());
311 }
312 
313 GeoDataFeature& GeoDataContainer::first()
314 {
315  detach();
316  return *(p()->m_vector.first());
317 }
318 
319 const GeoDataFeature& GeoDataContainer::first() const
320 {
321  return *(p()->m_vector.first());
322 }
323 
324 void GeoDataContainer::clear()
325 {
326  GeoDataContainer::detach();
327  qDeleteAll(p()->m_vector);
328  p()->m_vector.clear();
329 }
330 
331 QVector<GeoDataFeature*>::Iterator GeoDataContainer::begin()
332 {
333  return p()->m_vector.begin();
334 }
335 
336 QVector<GeoDataFeature*>::Iterator GeoDataContainer::end()
337 {
338  return p()->m_vector.end();
339 }
340 
341 QVector<GeoDataFeature*>::ConstIterator GeoDataContainer::constBegin() const
342 {
343  return p()->m_vector.constBegin();
344 }
345 
346 QVector<GeoDataFeature*>::ConstIterator GeoDataContainer::constEnd() const
347 {
348  return p()->m_vector.constEnd();
349 }
350 
351 void GeoDataContainer::pack( QDataStream& stream ) const
352 {
353  GeoDataFeature::pack( stream );
354 
355  stream << p()->m_vector.count();
356 
357  for ( QVector <GeoDataFeature*>::const_iterator iterator = p()->m_vector.constBegin();
358  iterator != p()->m_vector.constEnd();
359  ++iterator )
360  {
361  const GeoDataFeature *feature = *iterator;
362  stream << feature->featureId();
363  feature->pack( stream );
364  }
365 }
366 
367 void GeoDataContainer::unpack( QDataStream& stream )
368 {
369  detach();
370  GeoDataFeature::unpack( stream );
371 
372  int count;
373  stream >> count;
374 
375  for ( int i = 0; i < count; ++i ) {
376  int featureId;
377  stream >> featureId;
378  switch( featureId ) {
379  case GeoDataDocumentId:
380  /* not usable!!!! */ break;
381  case GeoDataFolderId:
382  {
383  GeoDataFolder *folder = new GeoDataFolder;
384  folder->unpack( stream );
385  p()->m_vector.append( folder );
386  }
387  break;
388  case GeoDataPlacemarkId:
389  {
390  GeoDataPlacemark *placemark = new GeoDataPlacemark;
391  placemark->unpack( stream );
392  p()->m_vector.append( placemark );
393  }
394  break;
395  case GeoDataNetworkLinkId:
396  break;
397  case GeoDataScreenOverlayId:
398  break;
399  case GeoDataGroundOverlayId:
400  break;
401  default: break;
402  };
403  }
404 }
405 
406 }
GeoDataDocument.h
Marble::GeoDataContainer::~GeoDataContainer
virtual ~GeoDataContainer()
Destruct the GeoDataContainer.
Definition: GeoDataContainer.cpp:52
Marble::GeoDataLatLonBox::isEmpty
virtual bool isEmpty() const
Indicates whether the bounding box is not initialised (and contains nothing).
Definition: GeoDataLatLonBox.cpp:768
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:65
Marble::GeoDataContainer::child
GeoDataFeature * child(int)
returns the requested child item
Definition: GeoDataContainer.cpp:239
GeoDataGroundOverlay.h
QVector::append
void append(const T &value)
Marble::GeoDataContainer::unpack
virtual void unpack(QDataStream &stream)
Unserialize the container from a stream.
Definition: GeoDataContainer.cpp:367
GeoDataContainer.h
Marble::GeoDataContainer::constBegin
QVector< GeoDataFeature * >::ConstIterator constBegin() const
Definition: GeoDataContainer.cpp:341
Marble::GeoDataFeature::featureId
EnumFeatureId featureId() const
Definition: GeoDataFeature.cpp:163
QDataStream
Marble::GeoDataContainer::begin
QVector< GeoDataFeature * >::Iterator begin()
Definition: GeoDataContainer.cpp:331
Marble::GeoDataTypes::GeoDataPlacemarkType
const char * GeoDataPlacemarkType
Definition: GeoDataTypes.cpp:66
Marble::GeoDataTypes::GeoDataDocumentType
const char * GeoDataDocumentType
Definition: GeoDataTypes.cpp:38
Marble::GeoDataFeature::equals
bool equals(const GeoDataFeature &other) const
Definition: GeoDataFeature.cpp:94
Marble::GeoDataFeature::isVisible
bool isVisible() const
Return whether this feature is visible or not.
Definition: GeoDataFeature.cpp:656
Marble::GeoDataContainer
A base class that can hold GeoDataFeatures.
Definition: GeoDataContainer.h:47
Marble::GeoDataContainerPrivate::m_vector
QVector< GeoDataFeature * > m_vector
Definition: GeoDataContainer_p.h:61
Marble::GeoDataTypes::GeoDataGroundOverlayType
const char * GeoDataGroundOverlayType
Definition: GeoDataTypes.cpp:44
Marble::GeoDataTour
Definition: GeoDataTour.h:25
Marble::GeoDataFeature::pack
virtual void pack(QDataStream &stream) const
Serialize the contents of the feature to stream.
Definition: GeoDataFeature.cpp:844
Marble::GeoDataContainer::last
GeoDataFeature & last()
return the reference of the last element for convenience
Definition: GeoDataContainer.cpp:302
MarbleDebug.h
Marble::GeoDataContainer::first
GeoDataFeature & first()
return the reference of the last element for convenience
Definition: GeoDataContainer.cpp:313
Marble::GeoDataPlacemark::geometry
GeoDataGeometry * geometry()
The geometry of the GeoDataPlacemark is to be rendered to the marble map along with the icon at the c...
Definition: GeoDataPlacemark.cpp:152
Marble::GeoDataObject::setParent
virtual void setParent(GeoDataObject *parent)
Sets the parent of the object.
Definition: GeoDataObject.cpp:70
Marble::GeoDataTypes::GeoDataScreenOverlayType
const char * GeoDataScreenOverlayType
Definition: GeoDataTypes.cpp:88
Marble::GeoDataFolderId
Definition: Serializable.h:33
GeoDataFeature.h
Marble::GeoDataScreenOverlay
Definition: GeoDataScreenOverlay.h:22
Marble::GeoDataDocumentId
Definition: Serializable.h:32
Marble::GeoDataContainer::constEnd
QVector< GeoDataFeature * >::ConstIterator constEnd() const
Definition: GeoDataContainer.cpp:346
Marble::GeoDataContainer::folderList
QVector< GeoDataFolder * > folderList() const
A convenience function that returns all folders in this container.
Definition: GeoDataContainer.cpp:197
Marble::GeoDataFeature::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataFeature.cpp:859
Marble::GeoDataTypes::GeoDataFolderType
const char * GeoDataFolderType
Definition: GeoDataTypes.cpp:42
Marble::GeoDataNetworkLinkId
Definition: Serializable.h:35
Marble::GeoDataScreenOverlayId
Definition: Serializable.h:36
Marble::GeoDataPhotoOverlay
Definition: GeoDataPhotoOverlay.h:27
Marble::GeoDataFeature::d
GeoDataFeaturePrivate * d
Definition: GeoDataFeature.h:506
Marble::GeoDataContainer::size
int size() const
size of the container
Definition: GeoDataContainer.cpp:286
Marble::GeoDataContainer::insert
void insert(GeoDataFeature *other, int index)
Definition: GeoDataContainer.cpp:265
Marble::GeoDataTypes::GeoDataTourType
const char * GeoDataTourType
Definition: GeoDataTypes.cpp:83
Marble::GeoDataContainer::latLonAltBox
GeoDataLatLonAltBox latLonAltBox() const
A convenience function that returns the LatLonAltBox of all placemarks in this container.
Definition: GeoDataContainer.cpp:160
Marble::GeoDataFolder
Definition: GeoDataFolder.h:50
GeoDataPlacemark.h
Marble::GeoDataContainer::pack
virtual void pack(QDataStream &stream) const
Serialize the container to a stream.
Definition: GeoDataContainer.cpp:351
GeoDataScreenOverlay.h
GeoDataNetworkLink.h
Marble::GeoDataContainer::childPosition
int childPosition(const GeoDataFeature *child) const
returns the position of an item in the list
Definition: GeoDataContainer.cpp:252
Marble::GeoDataContainer::append
void append(GeoDataFeature *other)
add an element
Definition: GeoDataContainer.cpp:272
Marble::GeoDataNetworkLink
Definition: GeoDataNetworkLink.h:23
Marble::GeoDataContainerPrivate
Definition: GeoDataContainer_p.h:21
GeoDataFolder.h
Marble::GeoDataContainer::end
QVector< GeoDataFeature * >::Iterator end()
Definition: GeoDataContainer.cpp:336
Marble::GeoDataContainer::at
GeoDataFeature & at(int pos)
return the reference of the element at a specific position
Definition: GeoDataContainer.cpp:291
Marble::GeoDataPlacemarkId
Definition: Serializable.h:34
QVector
Marble::GeoDataPlacemark::unpack
virtual void unpack(QDataStream &stream)
Deserialize the Placemark from a data stream.
Definition: GeoDataPlacemark.cpp:325
Marble::GeoDataFeature
A base class for all geodata features.
Definition: GeoDataFeature.h:57
Marble::GeoDataContainer::featureList
QVector< GeoDataFeature * > featureList() const
A convenience function that returns all features in this container.
Definition: GeoDataContainer.cpp:231
Marble::GeoDataContainer::remove
void remove(int index)
Definition: GeoDataContainer.cpp:280
Marble::GeoDataTypes::GeoDataNetworkLinkControlType
const char * GeoDataNetworkLinkControlType
Definition: GeoDataTypes.cpp:94
Marble::GeoDataTypes::GeoDataNetworkLinkType
const char * GeoDataNetworkLinkType
Definition: GeoDataTypes.cpp:62
Marble::GeoDataGroundOverlay
Definition: GeoDataGroundOverlay.h:24
Marble::GeoDataContainer::GeoDataContainer
GeoDataContainer()
Default constructor.
Definition: GeoDataContainer.cpp:37
Marble::GeoDataGroundOverlayId
Definition: Serializable.h:37
GeoDataNetworkLinkControl.h
Marble::GeoDataGeometry::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Definition: GeoDataGeometry.cpp:122
Marble::GeoDataNetworkLinkControl
Definition: GeoDataNetworkLinkControl.h:27
GeoDataContainer_p.h
Marble::GeoDataContainer::equals
bool equals(const GeoDataContainer &other) const
Definition: GeoDataContainer.cpp:66
GeoDataPhotoOverlay.h
Marble::GeoDataPlacemark
a class representing a point of interest on the map
Definition: GeoDataPlacemark.h:54
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
GeoDataTour.h
Marble::GeoDataFeature::detach
virtual void detach()
Definition: GeoDataFeature.cpp:824
Marble::GeoDataContainer::clear
void clear()
Definition: GeoDataContainer.cpp:324
Marble::GeoDataTypes::GeoDataPhotoOverlayType
const char * GeoDataPhotoOverlayType
Definition: GeoDataTypes.cpp:65
Marble::GeoDataContainer::placemarkList
QVector< GeoDataPlacemark * > placemarkList() const
A convenience function that returns all placemarks in this container.
Definition: GeoDataContainer.cpp:214
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal