• 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
GeoDataMultiGeometry.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 2008 Patrick Spendrin <ps_ml@gmx.de>
9 //
10 
11 
12 #include "GeoDataMultiGeometry.h"
13 #include "GeoDataMultiGeometry_p.h"
14 
15 #include "GeoDataLineString.h"
16 #include "GeoDataLinearRing.h"
17 #include "GeoDataPoint.h"
18 #include "GeoDataPolygon.h"
19 
20 #include "MarbleDebug.h"
21 
22 
23 namespace Marble
24 {
25 
26 GeoDataMultiGeometry::GeoDataMultiGeometry()
27  : GeoDataGeometry( new GeoDataMultiGeometryPrivate )
28 {
29 }
30 
31 GeoDataMultiGeometry::GeoDataMultiGeometry( const GeoDataGeometry& other )
32  : GeoDataGeometry( other )
33 {
34 }
35 
36 GeoDataMultiGeometry::~GeoDataMultiGeometry()
37 {
38 }
39 
40 GeoDataMultiGeometryPrivate* GeoDataMultiGeometry::p() const
41 {
42  return static_cast<GeoDataMultiGeometryPrivate*>(d);
43 }
44 
45 const GeoDataLatLonAltBox& GeoDataMultiGeometry::latLonAltBox() const
46 {
47  QVector<GeoDataGeometry*>::const_iterator it = p()->m_vector.constBegin();
48  QVector<GeoDataGeometry*>::const_iterator end = p()->m_vector.constEnd();
49 
50  p()->m_latLonAltBox.clear();
51  for (; it != end; ++it) {
52  if ( !(*it)->latLonAltBox().isEmpty() ) {
53  if ( p()->m_latLonAltBox.isEmpty() ) {
54  p()->m_latLonAltBox = (*it)->latLonAltBox();
55  }
56  else {
57  p()->m_latLonAltBox |= (*it)->latLonAltBox();
58  }
59  }
60  }
61  return p()->m_latLonAltBox;
62 }
63 
64 int GeoDataMultiGeometry::size() const
65 {
66  return p()->m_vector.size();
67 }
68 
69 QVector<GeoDataGeometry> GeoDataMultiGeometry::vector() const
70 {
71  QVector<GeoDataGeometry> results;
72 
73  QVector<GeoDataGeometry*>::const_iterator it = p()->m_vector.constBegin();
74  QVector<GeoDataGeometry*>::const_iterator end = p()->m_vector.constEnd();
75 
76  for (; it != end; ++it) {
77  GeoDataGeometry f = **it;
78  results.append( f );
79  }
80 
81  return results;
82 }
83 
84 GeoDataGeometry& GeoDataMultiGeometry::at( int pos )
85 {
86  mDebug() << "detaching!";
87  detach();
88  return *(p()->m_vector[ pos ]);
89 }
90 
91 const GeoDataGeometry& GeoDataMultiGeometry::at( int pos ) const
92 {
93  return *(p()->m_vector.at( pos ));
94 }
95 
96 GeoDataGeometry& GeoDataMultiGeometry::operator[]( int pos )
97 {
98  detach();
99  return *(p()->m_vector[ pos ]);
100 }
101 
102 const GeoDataGeometry& GeoDataMultiGeometry::operator[]( int pos ) const
103 {
104  return *(p()->m_vector[ pos ]);
105 }
106 
107 GeoDataGeometry& GeoDataMultiGeometry::last()
108 {
109  detach();
110  return *(p()->m_vector.last());
111 }
112 
113 GeoDataGeometry& GeoDataMultiGeometry::first()
114 {
115  detach();
116  return *(p()->m_vector.first());
117 }
118 
119 const GeoDataGeometry& GeoDataMultiGeometry::last() const
120 {
121  return *(p()->m_vector.last());
122 }
123 
124 const GeoDataGeometry& GeoDataMultiGeometry::first() const
125 {
126  return *(p()->m_vector.first());
127 }
128 
129 QVector<GeoDataGeometry*>::Iterator GeoDataMultiGeometry::begin()
130 {
131  detach();
132  return p()->m_vector.begin();
133 }
134 
135 QVector<GeoDataGeometry*>::Iterator GeoDataMultiGeometry::end()
136 {
137  detach();
138  return p()->m_vector.end();
139 }
140 
141 QVector<GeoDataGeometry*>::ConstIterator GeoDataMultiGeometry::constBegin() const
142 {
143  return p()->m_vector.constBegin();
144 }
145 
146 QVector<GeoDataGeometry*>::ConstIterator GeoDataMultiGeometry::constEnd() const
147 {
148  return p()->m_vector.constEnd();
149 }
150 
154 GeoDataGeometry* GeoDataMultiGeometry::child( int i )
155 {
156  return p()->m_vector.at( i );
157 }
158 
159 const GeoDataGeometry* GeoDataMultiGeometry::child( int i ) const
160 {
161  return p()->m_vector.at( i );
162 }
163 
167 int GeoDataMultiGeometry::childPosition( GeoDataGeometry *object)
168 {
169  for ( int i=0; i< p()->m_vector.size(); i++ )
170  {
171  if ( p()->m_vector.at( i ) == object )
172  {
173  return i;
174  }
175  }
176  return -1;
177 }
178 
182 void GeoDataMultiGeometry::append( GeoDataGeometry *other )
183 {
184  detach();
185  other->setParent( this );
186  p()->m_vector.append( other );
187 }
188 
189 
190 GeoDataMultiGeometry& GeoDataMultiGeometry::operator << ( const GeoDataGeometry& value )
191 {
192  detach();
193  GeoDataGeometry *g = new GeoDataGeometry( value );
194  g->setParent( this );
195  p()->m_vector.append( g );
196  return *this;
197 }
198 
199 void GeoDataMultiGeometry::clear()
200 {
201  detach();
202  qDeleteAll(p()->m_vector);
203  p()->m_vector.clear();
204 }
205 
206 void GeoDataMultiGeometry::pack( QDataStream& stream ) const
207 {
208  GeoDataGeometry::pack( stream );
209 
210  stream << p()->m_vector.size();
211 
212  for( QVector<GeoDataGeometry*>::const_iterator iterator
213  = p()->m_vector.constBegin();
214  iterator != p()->m_vector.constEnd();
215  ++iterator ) {
216  const GeoDataGeometry *geometry = *iterator;
217  stream << geometry->geometryId();
218  geometry->pack( stream );
219  }
220 }
221 
222 void GeoDataMultiGeometry::unpack( QDataStream& stream )
223 {
224  detach();
225  GeoDataGeometry::unpack( stream );
226 
227  int size = 0;
228 
229  stream >> size;
230 
231  for( int i = 0; i < size; i++ ) {
232  int geometryId;
233  stream >> geometryId;
234  switch( geometryId ) {
235  case InvalidGeometryId:
236  break;
237  case GeoDataPointId:
238  {
239  GeoDataPoint *point = new GeoDataPoint;
240  point->unpack( stream );
241  p()->m_vector.append( point );
242  }
243  break;
244  case GeoDataLineStringId:
245  {
246  GeoDataLineString *lineString = new GeoDataLineString;
247  lineString->unpack( stream );
248  p()->m_vector.append( lineString );
249  }
250  break;
251  case GeoDataLinearRingId:
252  {
253  GeoDataLinearRing *linearRing = new GeoDataLinearRing;
254  linearRing->unpack( stream );
255  p()->m_vector.append( linearRing );
256  }
257  break;
258  case GeoDataPolygonId:
259  {
260  GeoDataPolygon *polygon = new GeoDataPolygon;
261  polygon->unpack( stream );
262  p()->m_vector.append( polygon );
263  }
264  break;
265  case GeoDataMultiGeometryId:
266  {
267  GeoDataMultiGeometry *multiGeometry = new GeoDataMultiGeometry;
268  multiGeometry->unpack( stream );
269  p()->m_vector.append( multiGeometry );
270  }
271  break;
272  case GeoDataModelId:
273  break;
274  default: break;
275  };
276  }
277 }
278 
279 }
Marble::GeoDataPointId
Definition: Serializable.h:42
Marble::GeoDataPoint
A Geometry object representing a 3d point.
Definition: GeoDataPoint.h:47
Marble::GeoDataGeometry::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataGeometry.cpp:135
Marble::GeoDataLatLonBox::isEmpty
virtual bool isEmpty() const
Indicates whether the bounding box is not initialised (and contains nothing).
Definition: GeoDataLatLonBox.cpp:768
Marble::GeoDataLinearRing
A LinearRing that allows to store a closed, contiguous set of line segments.
Definition: GeoDataLinearRing.h:68
Marble::GeoDataMultiGeometry::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataMultiGeometry.cpp:222
Marble::GeoDataGeometry::GeoDataPoint
friend class GeoDataPoint
Definition: GeoDataGeometry.h:49
Marble::GeoDataGeometry::GeoDataPolygon
friend class GeoDataPolygon
Definition: GeoDataGeometry.h:50
GeoDataPolygon.h
Marble::GeoDataMultiGeometry::end
QVector< GeoDataGeometry * >::Iterator end()
Definition: GeoDataMultiGeometry.cpp:135
Marble::GeoDataMultiGeometry::child
GeoDataGeometry * child(int)
returns the requested child item
Definition: GeoDataMultiGeometry.cpp:154
Marble::GeoDataGeometry
A base class for all geodata features.
Definition: GeoDataGeometry.h:47
Marble::GeoDataGeometry::detach
void detach()
Definition: GeoDataGeometry.cpp:54
Marble::GeoDataMultiGeometry::GeoDataMultiGeometry
GeoDataMultiGeometry()
Definition: GeoDataMultiGeometry.cpp:26
Marble::GeoDataLineString::unpack
virtual void unpack(QDataStream &stream)
Unserialize the LineString from a stream.
Definition: GeoDataLineString.cpp:627
MarbleDebug.h
Marble::GeoDataMultiGeometry::size
int size() const
Definition: GeoDataMultiGeometry.cpp:64
Marble::GeoDataLinearRingId
Definition: Serializable.h:44
Marble::GeoDataGeometry::pack
virtual void pack(QDataStream &stream) const
Serialize the contents of the feature to stream.
Definition: GeoDataGeometry.cpp:127
Marble::GeoDataObject::setParent
virtual void setParent(GeoDataObject *parent)
Sets the parent of the object.
Definition: GeoDataObject.cpp:70
Marble::GeoDataMultiGeometry::operator[]
GeoDataGeometry & operator[](int pos)
Definition: GeoDataMultiGeometry.cpp:96
GeoDataMultiGeometry.h
Marble::GeoDataMultiGeometry::first
GeoDataGeometry & first()
Definition: GeoDataMultiGeometry.cpp:113
Marble::GeoDataMultiGeometryPrivate::m_vector
QVector< GeoDataGeometry * > m_vector
Definition: GeoDataMultiGeometry_p.h:58
Marble::GeoDataPolygon
A polygon that can have "holes".
Definition: GeoDataPolygon.h:81
Marble::GeoDataMultiGeometryId
Definition: Serializable.h:46
Marble::GeoDataPoint::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataPoint.cpp:100
GeoDataLineString.h
Marble::GeoDataMultiGeometry::constBegin
QVector< GeoDataGeometry * >::ConstIterator constBegin() const
Definition: GeoDataMultiGeometry.cpp:141
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
Marble::GeoDataModelId
Definition: Serializable.h:48
Marble::GeoDataMultiGeometry::last
GeoDataGeometry & last()
Definition: GeoDataMultiGeometry.cpp:107
Marble::GeoDataMultiGeometry::append
void append(GeoDataGeometry *other)
add an element
Definition: GeoDataMultiGeometry.cpp:182
Marble::GeoDataPolygon::unpack
virtual void unpack(QDataStream &stream)
Unserialize the Polygon from a stream.
Definition: GeoDataPolygon.cpp:136
GeoDataLinearRing.h
Marble::GeoDataMultiGeometry::operator<<
GeoDataMultiGeometry & operator<<(const GeoDataGeometry &value)
Definition: GeoDataMultiGeometry.cpp:190
Marble::GeoDataMultiGeometry::~GeoDataMultiGeometry
virtual ~GeoDataMultiGeometry()
Definition: GeoDataMultiGeometry.cpp:36
GeoDataPoint.h
Marble::GeoDataMultiGeometryPrivate
Definition: GeoDataMultiGeometry_p.h:21
Marble::GeoDataMultiGeometry::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Definition: GeoDataMultiGeometry.cpp:45
Marble::GeoDataLatLonAltBox::clear
virtual void clear()
Resets the bounding box to its uninitialised state (and thus contains nothing).
Definition: GeoDataLatLonAltBox.cpp:284
Marble::GeoDataMultiGeometry::constEnd
QVector< GeoDataGeometry * >::ConstIterator constEnd() const
Definition: GeoDataMultiGeometry.cpp:146
GeoDataMultiGeometry_p.h
Marble::GeoDataMultiGeometry
Definition: GeoDataMultiGeometry.h:33
Marble::GeoDataMultiGeometry::vector
QVector< GeoDataGeometry > vector() const
Definition: GeoDataMultiGeometry.cpp:69
Marble::GeoDataMultiGeometry::begin
QVector< GeoDataGeometry * >::Iterator begin()
Definition: GeoDataMultiGeometry.cpp:129
Marble::GeoDataMultiGeometry::clear
void clear()
Definition: GeoDataMultiGeometry.cpp:199
Marble::GeoDataGeometryPrivate::m_latLonAltBox
GeoDataLatLonAltBox m_latLonAltBox
Definition: GeoDataGeometry_p.h:71
Marble::GeoDataMultiGeometry::pack
virtual void pack(QDataStream &stream) const
Serialize the contents of the feature to stream.
Definition: GeoDataMultiGeometry.cpp:206
Marble::GeoDataMultiGeometry::childPosition
int childPosition(GeoDataGeometry *child)
returns the position of an item in the list
Definition: GeoDataMultiGeometry.cpp:167
Marble::GeoDataLineStringId
Definition: Serializable.h:43
Marble::GeoDataGeometry::GeoDataLineString
friend class GeoDataLineString
Definition: GeoDataGeometry.h:51
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
Marble::GeoDataPolygonId
Definition: Serializable.h:45
Marble::InvalidGeometryId
Definition: Serializable.h:41
Marble::GeoDataGeometry::geometryId
virtual EnumGeometryId geometryId() const
Definition: GeoDataGeometry.cpp:82
Marble::GeoDataMultiGeometry::at
GeoDataGeometry & at(int pos)
Definition: GeoDataMultiGeometry.cpp:84
Marble::GeoDataGeometry::GeoDataGeometry
GeoDataGeometry()
Definition: GeoDataGeometry.cpp:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:50 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