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

marble

  • sources
  • kde-4.12
  • 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 
26 namespace Marble
27 {
28 
29 GeoDataContainer::GeoDataContainer()
30  : GeoDataFeature( new GeoDataContainerPrivate )
31 {
32 }
33 
34 GeoDataContainer::GeoDataContainer( GeoDataContainerPrivate *priv )
35  : GeoDataFeature( priv )
36 {
37 }
38 
39 GeoDataContainer::GeoDataContainer( const GeoDataContainer& other )
40  : GeoDataFeature( other )
41 {
42 }
43 
44 GeoDataContainer::~GeoDataContainer()
45 {
46 }
47 
48 GeoDataContainerPrivate* GeoDataContainer::p() const
49 {
50  return static_cast<GeoDataContainerPrivate*>(d);
51 }
52 
53 GeoDataLatLonAltBox GeoDataContainer::latLonAltBox() const
54 {
55  GeoDataLatLonAltBox result;
56 
57  QVector<GeoDataFeature*>::const_iterator it = p()->m_vector.constBegin();
58  QVector<GeoDataFeature*>::const_iterator end = p()->m_vector.constEnd();
59  for (; it != end; ++it) {
60 
61  // Get all the placemarks from GeoDataContainer
62  if ( (*it)->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
63  GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>(*it);
64 
65  // Only use visible placemarks for extracting their latLonAltBox and
66  // making an union with the global latLonAltBox Marble will fit its
67  // zoom to
68  if (placemark->isVisible())
69  {
70  if (result.isEmpty()) {
71  result = placemark->geometry()->latLonAltBox();
72  } else {
73  result |= placemark->geometry()->latLonAltBox();
74  }
75  }
76  }
77  else if ( (*it)->nodeType() == GeoDataTypes::GeoDataFolderType
78  || (*it)->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
79  GeoDataContainer *container = static_cast<GeoDataContainer*>(*it);
80  if (result.isEmpty()) {
81  result = container->latLonAltBox();
82  } else {
83  result |= container->latLonAltBox();
84  }
85  }
86  }
87  return result;
88 }
89 
90 QVector<GeoDataFolder*> GeoDataContainer::folderList() const
91 {
92  QVector<GeoDataFolder*> results;
93 
94  QVector<GeoDataFeature*>::const_iterator it = p()->m_vector.constBegin();
95  QVector<GeoDataFeature*>::const_iterator end = p()->m_vector.constEnd();
96 
97  for (; it != end; ++it) {
98  GeoDataFolder *folder = dynamic_cast<GeoDataFolder*>(*it);
99  if ( folder ) {
100  results.append( folder );
101  }
102  }
103 
104  return results;
105 }
106 
107 QVector<GeoDataPlacemark*> GeoDataContainer::placemarkList() const
108 {
109  QVector<GeoDataPlacemark*> results;
110 
111  QVector<GeoDataFeature*>::const_iterator it = p()->m_vector.constBegin();
112  QVector<GeoDataFeature*>::const_iterator end = p()->m_vector.constEnd();
113 
114  for (; it != end; ++it) {
115  GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( *it );
116  if ( placemark ) {
117  results.append( placemark );
118  }
119  }
120 
121  return results;
122 }
123 
124 QVector<GeoDataFeature*> GeoDataContainer::featureList() const
125 {
126  return p()->m_vector;
127 }
128 
132 GeoDataFeature* GeoDataContainer::child( int i )
133 {
134  return p()->m_vector.at(i);
135 }
136 
137 const GeoDataFeature* GeoDataContainer::child( int i ) const
138 {
139  return p()->m_vector.at(i);
140 }
141 
145 int GeoDataContainer::childPosition( const GeoDataFeature* object ) const
146 {
147  for ( int i=0; i< p()->m_vector.size(); i++ )
148  {
149  if ( p()->m_vector.at( i ) == object )
150  {
151  return i;
152  }
153  }
154  return -1;
155 }
156 
157 
158 void GeoDataContainer::insert( GeoDataFeature *other, int index )
159 {
160  detach();
161  other->setParent(this);
162  p()->m_vector.insert( index, other );
163 }
164 
165 void GeoDataContainer::append( GeoDataFeature *other )
166 {
167  detach();
168  other->setParent(this);
169  p()->m_vector.append( other );
170 }
171 
172 
173 void GeoDataContainer::remove( int index )
174 {
175  detach();
176  p()->m_vector.remove( index );
177 }
178 
179 int GeoDataContainer::size() const
180 {
181  return p()->m_vector.size();
182 }
183 
184 GeoDataFeature& GeoDataContainer::at( int pos )
185 {
186  detach();
187  return *(p()->m_vector[ pos ]);
188 }
189 
190 const GeoDataFeature& GeoDataContainer::at( int pos ) const
191 {
192  return *(p()->m_vector.at( pos ));
193 }
194 
195 GeoDataFeature& GeoDataContainer::last()
196 {
197  detach();
198  return *(p()->m_vector.last());
199 }
200 
201 const GeoDataFeature& GeoDataContainer::last() const
202 {
203  return *(p()->m_vector.last());
204 }
205 
206 GeoDataFeature& GeoDataContainer::first()
207 {
208  detach();
209  return *(p()->m_vector.first());
210 }
211 
212 const GeoDataFeature& GeoDataContainer::first() const
213 {
214  return *(p()->m_vector.first());
215 }
216 
217 void GeoDataContainer::clear()
218 {
219  GeoDataContainer::detach();
220  qDeleteAll(p()->m_vector);
221  p()->m_vector.clear();
222 }
223 
224 QVector<GeoDataFeature*>::Iterator GeoDataContainer::begin()
225 {
226  return p()->m_vector.begin();
227 }
228 
229 QVector<GeoDataFeature*>::Iterator GeoDataContainer::end()
230 {
231  return p()->m_vector.end();
232 }
233 
234 QVector<GeoDataFeature*>::ConstIterator GeoDataContainer::constBegin() const
235 {
236  return p()->m_vector.constBegin();
237 }
238 
239 QVector<GeoDataFeature*>::ConstIterator GeoDataContainer::constEnd() const
240 {
241  return p()->m_vector.constEnd();
242 }
243 
244 void GeoDataContainer::pack( QDataStream& stream ) const
245 {
246  GeoDataFeature::pack( stream );
247 
248  stream << p()->m_vector.count();
249 
250  for ( QVector <GeoDataFeature*>::const_iterator iterator = p()->m_vector.constBegin();
251  iterator != p()->m_vector.constEnd();
252  ++iterator )
253  {
254  const GeoDataFeature *feature = *iterator;
255  stream << feature->featureId();
256  feature->pack( stream );
257  }
258 }
259 
260 void GeoDataContainer::unpack( QDataStream& stream )
261 {
262  detach();
263  GeoDataFeature::unpack( stream );
264 
265  int count;
266  stream >> count;
267 
268  for ( int i = 0; i < count; ++i ) {
269  int featureId;
270  stream >> featureId;
271  switch( featureId ) {
272  case GeoDataDocumentId:
273  /* not usable!!!! */ break;
274  case GeoDataFolderId:
275  {
276  GeoDataFolder *folder = new GeoDataFolder;
277  folder->unpack( stream );
278  p()->m_vector.append( folder );
279  }
280  break;
281  case GeoDataPlacemarkId:
282  {
283  GeoDataPlacemark *placemark = new GeoDataPlacemark;
284  placemark->unpack( stream );
285  p()->m_vector.append( placemark );
286  }
287  break;
288  case GeoDataNetworkLinkId:
289  break;
290  case GeoDataScreenOverlayId:
291  break;
292  case GeoDataGroundOverlayId:
293  break;
294  default: break;
295  };
296  }
297 }
298 
299 }
Marble::GeoDataContainer::~GeoDataContainer
virtual ~GeoDataContainer()
Destruct the GeoDataContainer.
Definition: GeoDataContainer.cpp:44
Marble::GeoDataLatLonBox::isEmpty
virtual bool isEmpty() const
Indicates whether the bounding box is not initialised (and contains nothing).
Definition: GeoDataLatLonBox.cpp:768
Marble::GeoDataContainer::child
GeoDataFeature * child(int)
returns the requested child item
Definition: GeoDataContainer.cpp:132
Marble::GeoDataContainer::unpack
virtual void unpack(QDataStream &stream)
Unserialize the container from a stream.
Definition: GeoDataContainer.cpp:260
GeoDataContainer.h
Marble::GeoDataContainer::constBegin
QVector< GeoDataFeature * >::ConstIterator constBegin() const
Definition: GeoDataContainer.cpp:234
Marble::GeoDataFeature::featureId
EnumFeatureId featureId() const
Definition: GeoDataFeature.cpp:99
Marble::GeoDataContainer::begin
QVector< GeoDataFeature * >::Iterator begin()
Definition: GeoDataContainer.cpp:224
Marble::GeoDataTypes::GeoDataPlacemarkType
const char * GeoDataPlacemarkType
Definition: GeoDataTypes.cpp:62
Marble::GeoDataTypes::GeoDataDocumentType
const char * GeoDataDocumentType
Definition: GeoDataTypes.cpp:34
Marble::GeoDataFeature::isVisible
bool isVisible() const
Return whether this feature is visible or not.
Definition: GeoDataFeature.cpp:581
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:60
Marble::GeoDataFeature::pack
virtual void pack(QDataStream &stream) const
Serialize the contents of the feature to stream.
Definition: GeoDataFeature.cpp:754
Marble::GeoDataContainer::last
GeoDataFeature & last()
return the reference of the last element for convenience
Definition: GeoDataContainer.cpp:195
Marble::GeoDataPlacemark::geometry
GeoDataGeometry * geometry() const
The geometry of the GeoDataPlacemark is to be rendered to the marble map along with the icon at the c...
Definition: GeoDataPlacemark.cpp:63
MarbleDebug.h
Marble::GeoDataContainer::first
GeoDataFeature & first()
return the reference of the last element for convenience
Definition: GeoDataContainer.cpp:206
Marble::GeoDataObject::setParent
virtual void setParent(GeoDataObject *parent)
Sets the parent of the object.
Definition: GeoDataObject.cpp:70
Marble::GeoDataFolderId
Definition: Serializable.h:33
GeoDataFeature.h
Marble::GeoDataDocumentId
Definition: Serializable.h:32
Marble::GeoDataContainer::constEnd
QVector< GeoDataFeature * >::ConstIterator constEnd() const
Definition: GeoDataContainer.cpp:239
Marble::GeoDataContainer::folderList
QVector< GeoDataFolder * > folderList() const
A convenience function that returns all folders in this container.
Definition: GeoDataContainer.cpp:90
Marble::GeoDataFeature::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataFeature.cpp:769
Marble::GeoDataTypes::GeoDataFolderType
const char * GeoDataFolderType
Definition: GeoDataTypes.cpp:38
Marble::GeoDataNetworkLinkId
Definition: Serializable.h:35
Marble::GeoDataScreenOverlayId
Definition: Serializable.h:36
Marble::GeoDataFeature::d
GeoDataFeaturePrivate * d
Definition: GeoDataFeature.h:484
Marble::GeoDataContainer::size
int size() const
size of the container
Definition: GeoDataContainer.cpp:179
Marble::GeoDataContainer::insert
void insert(GeoDataFeature *other, int index)
Definition: GeoDataContainer.cpp:158
Marble::GeoDataContainer::latLonAltBox
GeoDataLatLonAltBox latLonAltBox() const
A convenience function that returns the LatLonAltBox of all placemarks in this container.
Definition: GeoDataContainer.cpp:53
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:244
Marble::GeoDataContainer::childPosition
int childPosition(const GeoDataFeature *child) const
returns the position of an item in the list
Definition: GeoDataContainer.cpp:145
Marble::GeoDataContainer::append
void append(GeoDataFeature *other)
add an element
Definition: GeoDataContainer.cpp:165
Marble::GeoDataContainerPrivate
Definition: GeoDataContainer_p.h:21
GeoDataFolder.h
Marble::GeoDataContainer::end
QVector< GeoDataFeature * >::Iterator end()
Definition: GeoDataContainer.cpp:229
Marble::GeoDataContainer::at
GeoDataFeature & at(int pos)
return the reference of the element at a specific position
Definition: GeoDataContainer.cpp:184
Marble::GeoDataPlacemarkId
Definition: Serializable.h:34
Marble::GeoDataPlacemark::unpack
virtual void unpack(QDataStream &stream)
Deserialize the Placemark from a data stream.
Definition: GeoDataPlacemark.cpp:220
Marble::GeoDataFeature
A base class for all geodata features.
Definition: GeoDataFeature.h:55
Marble::GeoDataContainer::featureList
QVector< GeoDataFeature * > featureList() const
A convenience function that returns all features in this container.
Definition: GeoDataContainer.cpp:124
Marble::GeoDataContainer::remove
void remove(int index)
Definition: GeoDataContainer.cpp:173
Marble::GeoDataContainer::GeoDataFolder
friend class GeoDataFolder
Definition: GeoDataContainer.h:155
Marble::GeoDataContainer::p
GeoDataContainerPrivate * p() const
Definition: GeoDataContainer.cpp:48
Marble::GeoDataContainer::GeoDataContainer
GeoDataContainer()
Default constructor.
Definition: GeoDataContainer.cpp:29
Marble::GeoDataGroundOverlayId
Definition: Serializable.h:37
Marble::GeoDataGeometry::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Definition: GeoDataGeometry.cpp:122
GeoDataContainer_p.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
Marble::GeoDataFeature::detach
virtual void detach()
Definition: GeoDataFeature.cpp:734
Marble::GeoDataContainer::clear
void clear()
Definition: GeoDataContainer.cpp:217
Marble::GeoDataContainer::placemarkList
QVector< GeoDataPlacemark * > placemarkList() const
A convenience function that returns all placemarks in this container.
Definition: GeoDataContainer.cpp:107
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:49 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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