• 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
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()
41 {
42  return static_cast<GeoDataMultiGeometryPrivate*>(d);
43 }
44 
45 const GeoDataMultiGeometryPrivate* GeoDataMultiGeometry::p() const
46 {
47  return static_cast<GeoDataMultiGeometryPrivate*>(d);
48 }
49 
50 const GeoDataLatLonAltBox& GeoDataMultiGeometry::latLonAltBox() const
51 {
52  QVector<GeoDataGeometry*>::const_iterator it = p()->m_vector.constBegin();
53  QVector<GeoDataGeometry*>::const_iterator end = p()->m_vector.constEnd();
54 
55  p()->m_latLonAltBox.clear();
56  for (; it != end; ++it) {
57  if ( !(*it)->latLonAltBox().isEmpty() ) {
58  if ( p()->m_latLonAltBox.isEmpty() ) {
59  p()->m_latLonAltBox = (*it)->latLonAltBox();
60  }
61  else {
62  p()->m_latLonAltBox |= (*it)->latLonAltBox();
63  }
64  }
65  }
66  return p()->m_latLonAltBox;
67 }
68 
69 int GeoDataMultiGeometry::size() const
70 {
71  return p()->m_vector.size();
72 }
73 
74 QVector<GeoDataGeometry> GeoDataMultiGeometry::vector() const
75 {
76  QVector<GeoDataGeometry> results;
77 
78  QVector<GeoDataGeometry*>::const_iterator it = p()->m_vector.constBegin();
79  QVector<GeoDataGeometry*>::const_iterator end = p()->m_vector.constEnd();
80 
81  for (; it != end; ++it) {
82  GeoDataGeometry f = **it;
83  results.append( f );
84  }
85 
86  return results;
87 }
88 
89 GeoDataGeometry& GeoDataMultiGeometry::at( int pos )
90 {
91  mDebug() << "detaching!";
92  detach();
93  return *(p()->m_vector[ pos ]);
94 }
95 
96 const GeoDataGeometry& GeoDataMultiGeometry::at( int pos ) const
97 {
98  return *(p()->m_vector.at( pos ));
99 }
100 
101 GeoDataGeometry& GeoDataMultiGeometry::operator[]( int pos )
102 {
103  detach();
104  return *(p()->m_vector[ pos ]);
105 }
106 
107 const GeoDataGeometry& GeoDataMultiGeometry::operator[]( int pos ) const
108 {
109  return *(p()->m_vector[ pos ]);
110 }
111 
112 GeoDataGeometry& GeoDataMultiGeometry::last()
113 {
114  detach();
115  return *(p()->m_vector.last());
116 }
117 
118 GeoDataGeometry& GeoDataMultiGeometry::first()
119 {
120  detach();
121  return *(p()->m_vector.first());
122 }
123 
124 const GeoDataGeometry& GeoDataMultiGeometry::last() const
125 {
126  return *(p()->m_vector.last());
127 }
128 
129 const GeoDataGeometry& GeoDataMultiGeometry::first() const
130 {
131  return *(p()->m_vector.first());
132 }
133 
134 QVector<GeoDataGeometry*>::Iterator GeoDataMultiGeometry::begin()
135 {
136  detach();
137  return p()->m_vector.begin();
138 }
139 
140 QVector<GeoDataGeometry*>::Iterator GeoDataMultiGeometry::end()
141 {
142  detach();
143  return p()->m_vector.end();
144 }
145 
146 QVector<GeoDataGeometry*>::ConstIterator GeoDataMultiGeometry::constBegin() const
147 {
148  return p()->m_vector.constBegin();
149 }
150 
151 QVector<GeoDataGeometry*>::ConstIterator GeoDataMultiGeometry::constEnd() const
152 {
153  return p()->m_vector.constEnd();
154 }
155 
159 GeoDataGeometry* GeoDataMultiGeometry::child( int i )
160 {
161  return p()->m_vector.at( i );
162 }
163 
164 const GeoDataGeometry* GeoDataMultiGeometry::child( int i ) const
165 {
166  return p()->m_vector.at( i );
167 }
168 
172 int GeoDataMultiGeometry::childPosition( const GeoDataGeometry *object ) const
173 {
174  for ( int i=0; i< p()->m_vector.size(); i++ )
175  {
176  if ( p()->m_vector.at( i ) == object )
177  {
178  return i;
179  }
180  }
181  return -1;
182 }
183 
187 void GeoDataMultiGeometry::append( GeoDataGeometry *other )
188 {
189  detach();
190  other->setParent( this );
191  p()->m_vector.append( other );
192 }
193 
194 
195 GeoDataMultiGeometry& GeoDataMultiGeometry::operator << ( const GeoDataGeometry& value )
196 {
197  detach();
198  GeoDataGeometry *g = new GeoDataGeometry( value );
199  g->setParent( this );
200  p()->m_vector.append( g );
201  return *this;
202 }
203 
204 void GeoDataMultiGeometry::clear()
205 {
206  detach();
207  qDeleteAll(p()->m_vector);
208  p()->m_vector.clear();
209 }
210 
211 void GeoDataMultiGeometry::pack( QDataStream& stream ) const
212 {
213  GeoDataGeometry::pack( stream );
214 
215  stream << p()->m_vector.size();
216 
217  for( QVector<GeoDataGeometry*>::const_iterator iterator
218  = p()->m_vector.constBegin();
219  iterator != p()->m_vector.constEnd();
220  ++iterator ) {
221  const GeoDataGeometry *geometry = *iterator;
222  stream << geometry->geometryId();
223  geometry->pack( stream );
224  }
225 }
226 
227 void GeoDataMultiGeometry::unpack( QDataStream& stream )
228 {
229  detach();
230  GeoDataGeometry::unpack( stream );
231 
232  int size = 0;
233 
234  stream >> size;
235 
236  for( int i = 0; i < size; i++ ) {
237  int geometryId;
238  stream >> geometryId;
239  switch( geometryId ) {
240  case InvalidGeometryId:
241  break;
242  case GeoDataPointId:
243  {
244  GeoDataPoint *point = new GeoDataPoint;
245  point->unpack( stream );
246  p()->m_vector.append( point );
247  }
248  break;
249  case GeoDataLineStringId:
250  {
251  GeoDataLineString *lineString = new GeoDataLineString;
252  lineString->unpack( stream );
253  p()->m_vector.append( lineString );
254  }
255  break;
256  case GeoDataLinearRingId:
257  {
258  GeoDataLinearRing *linearRing = new GeoDataLinearRing;
259  linearRing->unpack( stream );
260  p()->m_vector.append( linearRing );
261  }
262  break;
263  case GeoDataPolygonId:
264  {
265  GeoDataPolygon *polygon = new GeoDataPolygon;
266  polygon->unpack( stream );
267  p()->m_vector.append( polygon );
268  }
269  break;
270  case GeoDataMultiGeometryId:
271  {
272  GeoDataMultiGeometry *multiGeometry = new GeoDataMultiGeometry;
273  multiGeometry->unpack( stream );
274  p()->m_vector.append( multiGeometry );
275  }
276  break;
277  case GeoDataModelId:
278  break;
279  default: break;
280  };
281  }
282 }
283 
284 }
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:227
Marble::GeoDataGeometry::GeoDataPoint
friend class GeoDataPoint
Definition: GeoDataGeometry.h:49
Marble::GeoDataGeometry::GeoDataPolygon
friend class GeoDataPolygon
Definition: GeoDataGeometry.h:50
QVector::append
void append(const T &value)
GeoDataPolygon.h
Marble::GeoDataMultiGeometry::end
QVector< GeoDataGeometry * >::Iterator end()
Definition: GeoDataMultiGeometry.cpp:140
QDataStream
Marble::GeoDataMultiGeometry::child
GeoDataGeometry * child(int)
returns the requested child item
Definition: GeoDataMultiGeometry.cpp:159
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:662
MarbleDebug.h
Marble::GeoDataMultiGeometry::size
int size() const
Definition: GeoDataMultiGeometry.cpp:69
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:101
GeoDataMultiGeometry.h
Marble::GeoDataMultiGeometry::first
GeoDataGeometry & first()
Definition: GeoDataMultiGeometry.cpp:118
Marble::GeoDataMultiGeometryPrivate::m_vector
QVector< GeoDataGeometry * > m_vector
Definition: GeoDataMultiGeometry_p.h:59
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:111
GeoDataLineString.h
Marble::GeoDataMultiGeometry::constBegin
QVector< GeoDataGeometry * >::ConstIterator constBegin() const
Definition: GeoDataMultiGeometry.cpp:146
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:112
Marble::GeoDataMultiGeometry::append
void append(GeoDataGeometry *other)
add an element
Definition: GeoDataMultiGeometry.cpp:187
Marble::GeoDataPolygon::unpack
virtual void unpack(QDataStream &stream)
Unserialize the Polygon from a stream.
Definition: GeoDataPolygon.cpp:174
GeoDataLinearRing.h
Marble::GeoDataMultiGeometry::operator<<
GeoDataMultiGeometry & operator<<(const GeoDataGeometry &value)
Definition: GeoDataMultiGeometry.cpp:195
Marble::GeoDataMultiGeometry::~GeoDataMultiGeometry
virtual ~GeoDataMultiGeometry()
Definition: GeoDataMultiGeometry.cpp:36
GeoDataPoint.h
QVector
Marble::GeoDataMultiGeometryPrivate
Definition: GeoDataMultiGeometry_p.h:21
Marble::GeoDataMultiGeometry::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Definition: GeoDataMultiGeometry.cpp:50
Marble::GeoDataMultiGeometry::childPosition
int childPosition(const GeoDataGeometry *child) const
returns the position of an item in the list
Definition: GeoDataMultiGeometry.cpp:172
Marble::GeoDataLatLonAltBox::clear
virtual void clear()
Resets the bounding box to its uninitialised state (and thus contains nothing).
Definition: GeoDataLatLonAltBox.cpp:283
Marble::GeoDataMultiGeometry::constEnd
QVector< GeoDataGeometry * >::ConstIterator constEnd() const
Definition: GeoDataMultiGeometry.cpp:151
GeoDataMultiGeometry_p.h
Marble::GeoDataMultiGeometry
Definition: GeoDataMultiGeometry.h:33
Marble::GeoDataMultiGeometry::vector
QVector< GeoDataGeometry > vector() const
Definition: GeoDataMultiGeometry.cpp:74
Marble::GeoDataMultiGeometry::begin
QVector< GeoDataGeometry * >::Iterator begin()
Definition: GeoDataMultiGeometry.cpp:134
Marble::GeoDataMultiGeometry::clear
void clear()
Definition: GeoDataMultiGeometry.cpp:204
Marble::GeoDataGeometryPrivate::m_latLonAltBox
GeoDataLatLonAltBox m_latLonAltBox
Definition: GeoDataGeometry_p.h:74
Marble::GeoDataMultiGeometry::pack
virtual void pack(QDataStream &stream) const
Serialize the contents of the feature to stream.
Definition: GeoDataMultiGeometry.cpp:211
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:36
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:89
Marble::GeoDataGeometry::GeoDataGeometry
GeoDataGeometry()
Definition: GeoDataGeometry.cpp:28
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