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

marble

  • kde-4.x
  • 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 <[email protected]>
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 #include "GeoDataTypes.h"
20 
21 #include "MarbleDebug.h"
22 
23 #include <QDataStream>
24 
25 
26 namespace Marble
27 {
28 
29 GeoDataMultiGeometry::GeoDataMultiGeometry()
30  : GeoDataGeometry( new GeoDataMultiGeometryPrivate )
31 {
32 }
33 
34 GeoDataMultiGeometry::GeoDataMultiGeometry( const GeoDataGeometry& other )
35  : GeoDataGeometry( other )
36 {
37 }
38 
39 GeoDataMultiGeometry::~GeoDataMultiGeometry()
40 {
41 }
42 
43 const char *GeoDataMultiGeometry::nodeType() const
44 {
45  return GeoDataTypes::GeoDataMultiGeometryType;
46 }
47 
48 EnumGeometryId GeoDataMultiGeometry::geometryId() const
49 {
50  return GeoDataMultiGeometryId;
51 }
52 
53 GeoDataGeometry *GeoDataMultiGeometry::copy() const
54 {
55  return new GeoDataMultiGeometry(*this);
56 }
57 
58 bool GeoDataMultiGeometry::operator==(const GeoDataMultiGeometry &other) const
59 {
60  Q_D(const GeoDataMultiGeometry);
61  const GeoDataMultiGeometryPrivate *const other_d = other.d_func();
62  QVector<GeoDataGeometry*>::const_iterator thisBegin = d->m_vector.constBegin();
63  QVector<GeoDataGeometry*>::const_iterator thisEnd = d->m_vector.constEnd();
64  QVector<GeoDataGeometry*>::const_iterator otherBegin = other_d->m_vector.constBegin();
65  QVector<GeoDataGeometry*>::const_iterator otherEnd = other_d->m_vector.constEnd();
66 
67  for (; thisBegin != thisEnd && otherBegin != otherEnd; ++thisBegin, ++otherBegin) {
68  if (**thisBegin != **otherBegin) {
69  return false;
70  }
71  }
72 
73  return true;
74 }
75 
76 const GeoDataLatLonAltBox& GeoDataMultiGeometry::latLonAltBox() const
77 {
78  Q_D(const GeoDataMultiGeometry);
79 
80  QVector<GeoDataGeometry*>::const_iterator it = d->m_vector.constBegin();
81  QVector<GeoDataGeometry*>::const_iterator end = d->m_vector.constEnd();
82 
83  d->m_latLonAltBox.clear();
84  for (; it != end; ++it) {
85  if ( !(*it)->latLonAltBox().isEmpty() ) {
86  if ( d->m_latLonAltBox.isEmpty() ) {
87  d->m_latLonAltBox = (*it)->latLonAltBox();
88  }
89  else {
90  d->m_latLonAltBox |= (*it)->latLonAltBox();
91  }
92  }
93  }
94  return d->m_latLonAltBox;
95 }
96 
97 int GeoDataMultiGeometry::size() const
98 {
99  Q_D(const GeoDataMultiGeometry);
100  return d->m_vector.size();
101 }
102 
103 QVector<GeoDataGeometry *> GeoDataMultiGeometry::vector()
104 {
105  Q_D(const GeoDataMultiGeometry);
106 
107  return d->m_vector;
108 }
109 
110 GeoDataGeometry& GeoDataMultiGeometry::at( int pos )
111 {
112  mDebug() << "detaching!";
113  detach();
114 
115  Q_D(GeoDataMultiGeometry);
116  return *(d->m_vector[pos]);
117 }
118 
119 const GeoDataGeometry& GeoDataMultiGeometry::at( int pos ) const
120 {
121  Q_D(const GeoDataMultiGeometry);
122  return *(d->m_vector.at(pos));
123 }
124 
125 GeoDataGeometry& GeoDataMultiGeometry::operator[]( int pos )
126 {
127  detach();
128 
129  Q_D(GeoDataMultiGeometry);
130  return *(d->m_vector[pos]);
131 }
132 
133 const GeoDataGeometry& GeoDataMultiGeometry::operator[]( int pos ) const
134 {
135  Q_D(const GeoDataMultiGeometry);
136  return *(d->m_vector[pos]);
137 }
138 
139 GeoDataGeometry& GeoDataMultiGeometry::last()
140 {
141  detach();
142 
143  Q_D(GeoDataMultiGeometry);
144  return *(d->m_vector.last());
145 }
146 
147 GeoDataGeometry& GeoDataMultiGeometry::first()
148 {
149  detach();
150 
151  Q_D(GeoDataMultiGeometry);
152  return *(d->m_vector.first());
153 }
154 
155 const GeoDataGeometry& GeoDataMultiGeometry::last() const
156 {
157  Q_D(const GeoDataMultiGeometry);
158  return *(d->m_vector.last());
159 }
160 
161 const GeoDataGeometry& GeoDataMultiGeometry::first() const
162 {
163  Q_D(const GeoDataMultiGeometry);
164  return *(d->m_vector.first());
165 }
166 
167 QVector<GeoDataGeometry*>::Iterator GeoDataMultiGeometry::begin()
168 {
169  detach();
170 
171  Q_D(GeoDataMultiGeometry);
172  return d->m_vector.begin();
173 }
174 
175 QVector<GeoDataGeometry*>::Iterator GeoDataMultiGeometry::end()
176 {
177  detach();
178 
179  Q_D(GeoDataMultiGeometry);
180  return d->m_vector.end();
181 }
182 
183 QVector<GeoDataGeometry*>::ConstIterator GeoDataMultiGeometry::constBegin() const
184 {
185  Q_D(const GeoDataMultiGeometry);
186  return d->m_vector.constBegin();
187 }
188 
189 QVector<GeoDataGeometry*>::ConstIterator GeoDataMultiGeometry::constEnd() const
190 {
191  Q_D(const GeoDataMultiGeometry);
192  return d->m_vector.constEnd();
193 }
194 
198 GeoDataGeometry* GeoDataMultiGeometry::child( int i )
199 {
200  detach();
201 
202  Q_D(GeoDataMultiGeometry);
203  return d->m_vector.at(i);
204 }
205 
206 const GeoDataGeometry* GeoDataMultiGeometry::child( int i ) const
207 {
208  Q_D(const GeoDataMultiGeometry);
209  return d->m_vector.at(i);
210 }
211 
215 int GeoDataMultiGeometry::childPosition( const GeoDataGeometry *object ) const
216 {
217  Q_D(const GeoDataMultiGeometry);
218  for (int i = 0; i < d->m_vector.size(); ++i) {
219  if (d->m_vector.at(i) == object) {
220  return i;
221  }
222  }
223  return -1;
224 }
225 
229 void GeoDataMultiGeometry::append( GeoDataGeometry *other )
230 {
231  detach();
232 
233  Q_D(GeoDataMultiGeometry);
234  other->setParent( this );
235  d->m_vector.append(other);
236 }
237 
238 
239 GeoDataMultiGeometry& GeoDataMultiGeometry::operator << ( const GeoDataGeometry& value )
240 {
241  detach();
242 
243  Q_D(GeoDataMultiGeometry);
244  GeoDataGeometry *g = value.copy();
245  g->setParent( this );
246  d->m_vector.append(g);
247  return *this;
248 }
249 
250 void GeoDataMultiGeometry::clear()
251 {
252  detach();
253 
254  Q_D(GeoDataMultiGeometry);
255  qDeleteAll(d->m_vector);
256  d->m_vector.clear();
257 }
258 
259 void GeoDataMultiGeometry::pack( QDataStream& stream ) const
260 {
261  Q_D(const GeoDataMultiGeometry);
262 
263  GeoDataGeometry::pack( stream );
264 
265  stream << d->m_vector.size();
266 
267  for( QVector<GeoDataGeometry*>::const_iterator iterator
268  = d->m_vector.constBegin();
269  iterator != d->m_vector.constEnd();
270  ++iterator ) {
271  const GeoDataGeometry *geometry = *iterator;
272  stream << geometry->geometryId();
273  geometry->pack( stream );
274  }
275 }
276 
277 void GeoDataMultiGeometry::unpack( QDataStream& stream )
278 {
279  detach();
280 
281  Q_D(GeoDataMultiGeometry);
282  GeoDataGeometry::unpack( stream );
283 
284  int size = 0;
285 
286  stream >> size;
287 
288  for( int i = 0; i < size; i++ ) {
289  int geometryId;
290  stream >> geometryId;
291  switch( geometryId ) {
292  case InvalidGeometryId:
293  break;
294  case GeoDataPointId:
295  {
296  GeoDataPoint *point = new GeoDataPoint;
297  point->unpack( stream );
298  d->m_vector.append(point);
299  }
300  break;
301  case GeoDataLineStringId:
302  {
303  GeoDataLineString *lineString = new GeoDataLineString;
304  lineString->unpack( stream );
305  d->m_vector.append(lineString);
306  }
307  break;
308  case GeoDataLinearRingId:
309  {
310  GeoDataLinearRing *linearRing = new GeoDataLinearRing;
311  linearRing->unpack( stream );
312  d->m_vector.append(linearRing);
313  }
314  break;
315  case GeoDataPolygonId:
316  {
317  GeoDataPolygon *polygon = new GeoDataPolygon;
318  polygon->unpack( stream );
319  d->m_vector.append(polygon);
320  }
321  break;
322  case GeoDataMultiGeometryId:
323  {
324  GeoDataMultiGeometry *multiGeometry = new GeoDataMultiGeometry;
325  multiGeometry->unpack( stream );
326  d->m_vector.append(multiGeometry);
327  }
328  break;
329  case GeoDataModelId:
330  break;
331  default: break;
332  };
333  }
334 }
335 
336 }
Marble::GeoDataPointId
Definition: Serializable.h:42
Marble::GeoDataPoint
A Geometry object representing a 3d point.
Definition: GeoDataPoint.h:47
Marble::GeoDataTypes::GeoDataMultiGeometryType
const char GeoDataMultiGeometryType[]
Definition: GeoDataTypes.cpp:57
Marble::GeoDataMultiGeometry::geometryId
EnumGeometryId geometryId() const override
Definition: GeoDataMultiGeometry.cpp:48
Marble::GeoDataPolygon::unpack
void unpack(QDataStream &stream) override
Unserialize the Polygon from a stream.
Definition: GeoDataPolygon.cpp:219
Marble::GeoDataMultiGeometry::nodeType
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
Definition: GeoDataMultiGeometry.cpp:43
Marble::GeoDataLinearRing
A LinearRing that allows to store a closed, contiguous set of line segments.
Definition: GeoDataLinearRing.h:67
GeoDataPolygon.h
Marble::GeoDataMultiGeometry::end
QVector< GeoDataGeometry * >::Iterator end()
Definition: GeoDataMultiGeometry.cpp:175
Marble::GeoDataPoint::unpack
void unpack(QDataStream &stream) override
Unserialize the contents of the feature from stream.
Definition: GeoDataPoint.cpp:121
Marble::GeoDataMultiGeometry::pack
void pack(QDataStream &stream) const override
Serialize the contents of the feature to stream.
Definition: GeoDataMultiGeometry.cpp:259
QDataStream
Marble::GeoDataMultiGeometry::copy
GeoDataGeometry * copy() const override
Definition: GeoDataMultiGeometry.cpp:53
Marble::GeoDataMultiGeometry::child
GeoDataGeometry * child(int)
returns the requested child item
Definition: GeoDataMultiGeometry.cpp:198
Marble::GeoDataGeometry
A base class for all geodata features.
Definition: GeoDataGeometry.h:43
QVector::constEnd
const_iterator constEnd() const
Marble::GeoDataGeometry::detach
void detach()
Definition: GeoDataGeometry.cpp:55
Marble::GeoDataGeometry::pack
void pack(QDataStream &stream) const override
Serialize the contents of the feature to stream.
Definition: GeoDataGeometry.cpp:161
Marble::GeoDataMultiGeometry::GeoDataMultiGeometry
GeoDataMultiGeometry()
Definition: GeoDataMultiGeometry.cpp:29
MarbleDebug.h
Marble::GeoDataMultiGeometry::size
int size() const
Definition: GeoDataMultiGeometry.cpp:97
Marble::GeoDataMultiGeometry::operator==
bool operator==(const GeoDataMultiGeometry &other) const
Definition: GeoDataMultiGeometry.cpp:58
Marble::GeoDataLinearRingId
Definition: Serializable.h:44
Marble::GeoDataObject::setParent
void setParent(GeoDataObject *parent)
Sets the parent of the object.
Definition: GeoDataObject.cpp:75
Marble::GeoDataMultiGeometry::operator[]
GeoDataGeometry & operator[](int pos)
Definition: GeoDataMultiGeometry.cpp:125
GeoDataMultiGeometry.h
Marble::GeoDataMultiGeometry::first
GeoDataGeometry & first()
Definition: GeoDataMultiGeometry.cpp:147
Marble::GeoDataMultiGeometryPrivate::m_vector
QVector< GeoDataGeometry * > m_vector
Definition: GeoDataMultiGeometry_p.h:63
Marble::GeoDataMultiGeometry::latLonAltBox
const GeoDataLatLonAltBox & latLonAltBox() const override
Definition: GeoDataMultiGeometry.cpp:76
Marble::GeoDataGeometry::copy
virtual GeoDataGeometry * copy() const =0
Marble::GeoDataPolygon
A polygon that can have "holes".
Definition: GeoDataPolygon.h:81
Marble::GeoDataMultiGeometryId
Definition: Serializable.h:46
GeoDataLineString.h
Marble::GeoDataMultiGeometry::constBegin
QVector< GeoDataGeometry * >::ConstIterator constBegin() const
Definition: GeoDataMultiGeometry.cpp:183
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:72
Marble::GeoDataModelId
Definition: Serializable.h:48
Marble::GeoDataMultiGeometry::last
GeoDataGeometry & last()
Definition: GeoDataMultiGeometry.cpp:139
Marble::GeoDataMultiGeometry::append
void append(GeoDataGeometry *other)
add an element
Definition: GeoDataMultiGeometry.cpp:229
GeoDataLinearRing.h
Marble::GeoDataMultiGeometry::operator<<
GeoDataMultiGeometry & operator<<(const GeoDataGeometry &value)
Definition: GeoDataMultiGeometry.cpp:239
Marble::GeoDataMultiGeometry::vector
QVector< GeoDataGeometry * > vector()
Definition: GeoDataMultiGeometry.cpp:103
QVector::constBegin
const_iterator constBegin() const
GeoDataPoint.h
QVector
Marble::GeoDataMultiGeometryPrivate
Definition: GeoDataMultiGeometry_p.h:28
Marble::GeoDataMultiGeometry::childPosition
int childPosition(const GeoDataGeometry *child) const
returns the position of an item in the list
Definition: GeoDataMultiGeometry.cpp:215
Marble::GeoDataMultiGeometry::~GeoDataMultiGeometry
~GeoDataMultiGeometry() override
Definition: GeoDataMultiGeometry.cpp:39
Marble::GeoDataMultiGeometry::constEnd
QVector< GeoDataGeometry * >::ConstIterator constEnd() const
Definition: GeoDataMultiGeometry.cpp:189
Marble::EnumGeometryId
EnumGeometryId
Definition: Serializable.h:40
GeoDataMultiGeometry_p.h
Marble::GeoDataMultiGeometry
A class that can contain other GeoDataGeometry objects.
Definition: GeoDataMultiGeometry.h:33
Marble::GeoDataMultiGeometry::begin
QVector< GeoDataGeometry * >::Iterator begin()
Definition: GeoDataMultiGeometry.cpp:167
Marble::GeoDataGeometry::geometryId
virtual EnumGeometryId geometryId() const =0
Marble::GeoDataMultiGeometry::clear
void clear()
Definition: GeoDataMultiGeometry.cpp:250
GeoDataTypes.h
Marble::GeoDataLineStringId
Definition: Serializable.h:43
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:47
Marble::GeoDataLineString::unpack
void unpack(QDataStream &stream) override
Unserialize the LineString from a stream.
Definition: GeoDataLineString.cpp:911
Marble::GeoDataGeometry::unpack
void unpack(QDataStream &stream) override
Unserialize the contents of the feature from stream.
Definition: GeoDataGeometry.cpp:169
Marble::GeoDataPolygonId
Definition: Serializable.h:45
Marble::InvalidGeometryId
Definition: Serializable.h:41
Marble::GeoDataMultiGeometry::unpack
void unpack(QDataStream &stream) override
Unserialize the contents of the feature from stream.
Definition: GeoDataMultiGeometry.cpp:277
Marble::GeoDataMultiGeometry::at
GeoDataGeometry & at(int pos)
Definition: GeoDataMultiGeometry.cpp:110
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Wed Dec 11 2019 06:11:03 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
  •   KmPlot
  • libkeduvocdocument
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   src
  •   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