Changeset View
Changeset View
Standalone View
Standalone View
src/lib/marble/geodata/data/GeoDataMultiGeometry.cpp
Show All 33 Lines | 33 | GeoDataMultiGeometry::GeoDataMultiGeometry( const GeoDataGeometry& other ) | |||
---|---|---|---|---|---|
34 | : GeoDataGeometry( other ) | 34 | : GeoDataGeometry( other ) | ||
35 | { | 35 | { | ||
36 | } | 36 | } | ||
37 | 37 | | |||
38 | GeoDataMultiGeometry::~GeoDataMultiGeometry() | 38 | GeoDataMultiGeometry::~GeoDataMultiGeometry() | ||
39 | { | 39 | { | ||
40 | } | 40 | } | ||
41 | 41 | | |||
42 | GeoDataMultiGeometryPrivate* GeoDataMultiGeometry::p() | | |||
43 | { | | |||
44 | return static_cast<GeoDataMultiGeometryPrivate*>(d); | | |||
45 | } | | |||
46 | | ||||
47 | const GeoDataMultiGeometryPrivate* GeoDataMultiGeometry::p() const | | |||
48 | { | | |||
49 | return static_cast<GeoDataMultiGeometryPrivate*>(d); | | |||
50 | } | | |||
51 | | ||||
52 | const GeoDataLatLonAltBox& GeoDataMultiGeometry::latLonAltBox() const | 42 | const GeoDataLatLonAltBox& GeoDataMultiGeometry::latLonAltBox() const | ||
53 | { | 43 | { | ||
54 | QVector<GeoDataGeometry*>::const_iterator it = p()->m_vector.constBegin(); | 44 | Q_D(const GeoDataMultiGeometry); | ||
55 | QVector<GeoDataGeometry*>::const_iterator end = p()->m_vector.constEnd(); | | |||
56 | 45 | | |||
57 | p()->m_latLonAltBox.clear(); | 46 | QVector<GeoDataGeometry*>::const_iterator it = d->m_vector.constBegin(); | ||
47 | QVector<GeoDataGeometry*>::const_iterator end = d->m_vector.constEnd(); | ||||
48 | | ||||
49 | d->m_latLonAltBox.clear(); | ||||
58 | for (; it != end; ++it) { | 50 | for (; it != end; ++it) { | ||
59 | if ( !(*it)->latLonAltBox().isEmpty() ) { | 51 | if ( !(*it)->latLonAltBox().isEmpty() ) { | ||
60 | if ( p()->m_latLonAltBox.isEmpty() ) { | 52 | if ( d->m_latLonAltBox.isEmpty() ) { | ||
61 | p()->m_latLonAltBox = (*it)->latLonAltBox(); | 53 | d->m_latLonAltBox = (*it)->latLonAltBox(); | ||
62 | } | 54 | } | ||
63 | else { | 55 | else { | ||
64 | p()->m_latLonAltBox |= (*it)->latLonAltBox(); | 56 | d->m_latLonAltBox |= (*it)->latLonAltBox(); | ||
65 | } | 57 | } | ||
66 | } | 58 | } | ||
67 | } | 59 | } | ||
68 | return p()->m_latLonAltBox; | 60 | return d->m_latLonAltBox; | ||
69 | } | 61 | } | ||
70 | 62 | | |||
71 | int GeoDataMultiGeometry::size() const | 63 | int GeoDataMultiGeometry::size() const | ||
72 | { | 64 | { | ||
73 | return p()->m_vector.size(); | 65 | Q_D(const GeoDataMultiGeometry); | ||
66 | return d->m_vector.size(); | ||||
74 | } | 67 | } | ||
75 | 68 | | |||
76 | QVector<GeoDataGeometry> GeoDataMultiGeometry::vector() const | 69 | QVector<GeoDataGeometry> GeoDataMultiGeometry::vector() const | ||
77 | { | 70 | { | ||
71 | Q_D(const GeoDataMultiGeometry); | ||||
78 | QVector<GeoDataGeometry> results; | 72 | QVector<GeoDataGeometry> results; | ||
79 | 73 | | |||
80 | QVector<GeoDataGeometry*>::const_iterator it = p()->m_vector.constBegin(); | 74 | QVector<GeoDataGeometry*>::const_iterator it = d->m_vector.constBegin(); | ||
81 | QVector<GeoDataGeometry*>::const_iterator end = p()->m_vector.constEnd(); | 75 | QVector<GeoDataGeometry*>::const_iterator end = d->m_vector.constEnd(); | ||
82 | 76 | | |||
83 | for (; it != end; ++it) { | 77 | for (; it != end; ++it) { | ||
84 | GeoDataGeometry f = **it; | 78 | GeoDataGeometry f = **it; | ||
85 | results.append( f ); | 79 | results.append( f ); | ||
86 | } | 80 | } | ||
87 | 81 | | |||
88 | return results; | 82 | return results; | ||
89 | } | 83 | } | ||
90 | 84 | | |||
91 | GeoDataGeometry& GeoDataMultiGeometry::at( int pos ) | 85 | GeoDataGeometry& GeoDataMultiGeometry::at( int pos ) | ||
92 | { | 86 | { | ||
93 | mDebug() << "detaching!"; | 87 | mDebug() << "detaching!"; | ||
94 | detach(); | 88 | detach(); | ||
95 | return *(p()->m_vector[ pos ]); | 89 | | ||
90 | Q_D(GeoDataMultiGeometry); | ||||
91 | return *(d->m_vector[pos]); | ||||
96 | } | 92 | } | ||
97 | 93 | | |||
98 | const GeoDataGeometry& GeoDataMultiGeometry::at( int pos ) const | 94 | const GeoDataGeometry& GeoDataMultiGeometry::at( int pos ) const | ||
99 | { | 95 | { | ||
100 | return *(p()->m_vector.at( pos )); | 96 | Q_D(const GeoDataMultiGeometry); | ||
97 | return *(d->m_vector.at(pos)); | ||||
101 | } | 98 | } | ||
102 | 99 | | |||
103 | GeoDataGeometry& GeoDataMultiGeometry::operator[]( int pos ) | 100 | GeoDataGeometry& GeoDataMultiGeometry::operator[]( int pos ) | ||
104 | { | 101 | { | ||
105 | detach(); | 102 | detach(); | ||
106 | return *(p()->m_vector[ pos ]); | 103 | | ||
104 | Q_D(GeoDataMultiGeometry); | ||||
105 | return *(d->m_vector[pos]); | ||||
107 | } | 106 | } | ||
108 | 107 | | |||
109 | const GeoDataGeometry& GeoDataMultiGeometry::operator[]( int pos ) const | 108 | const GeoDataGeometry& GeoDataMultiGeometry::operator[]( int pos ) const | ||
110 | { | 109 | { | ||
111 | return *(p()->m_vector[ pos ]); | 110 | Q_D(const GeoDataMultiGeometry); | ||
111 | return *(d->m_vector[pos]); | ||||
112 | } | 112 | } | ||
113 | 113 | | |||
114 | GeoDataGeometry& GeoDataMultiGeometry::last() | 114 | GeoDataGeometry& GeoDataMultiGeometry::last() | ||
115 | { | 115 | { | ||
116 | detach(); | 116 | detach(); | ||
117 | return *(p()->m_vector.last()); | 117 | | ||
118 | Q_D(GeoDataMultiGeometry); | ||||
119 | return *(d->m_vector.last()); | ||||
118 | } | 120 | } | ||
119 | 121 | | |||
120 | GeoDataGeometry& GeoDataMultiGeometry::first() | 122 | GeoDataGeometry& GeoDataMultiGeometry::first() | ||
121 | { | 123 | { | ||
122 | detach(); | 124 | detach(); | ||
123 | return *(p()->m_vector.first()); | 125 | | ||
126 | Q_D(GeoDataMultiGeometry); | ||||
127 | return *(d->m_vector.first()); | ||||
124 | } | 128 | } | ||
125 | 129 | | |||
126 | const GeoDataGeometry& GeoDataMultiGeometry::last() const | 130 | const GeoDataGeometry& GeoDataMultiGeometry::last() const | ||
127 | { | 131 | { | ||
128 | return *(p()->m_vector.last()); | 132 | Q_D(const GeoDataMultiGeometry); | ||
133 | return *(d->m_vector.last()); | ||||
129 | } | 134 | } | ||
130 | 135 | | |||
131 | const GeoDataGeometry& GeoDataMultiGeometry::first() const | 136 | const GeoDataGeometry& GeoDataMultiGeometry::first() const | ||
132 | { | 137 | { | ||
133 | return *(p()->m_vector.first()); | 138 | Q_D(const GeoDataMultiGeometry); | ||
139 | return *(d->m_vector.first()); | ||||
134 | } | 140 | } | ||
135 | 141 | | |||
136 | QVector<GeoDataGeometry*>::Iterator GeoDataMultiGeometry::begin() | 142 | QVector<GeoDataGeometry*>::Iterator GeoDataMultiGeometry::begin() | ||
137 | { | 143 | { | ||
138 | detach(); | 144 | detach(); | ||
139 | return p()->m_vector.begin(); | 145 | | ||
146 | Q_D(GeoDataMultiGeometry); | ||||
147 | return d->m_vector.begin(); | ||||
140 | } | 148 | } | ||
141 | 149 | | |||
142 | QVector<GeoDataGeometry*>::Iterator GeoDataMultiGeometry::end() | 150 | QVector<GeoDataGeometry*>::Iterator GeoDataMultiGeometry::end() | ||
143 | { | 151 | { | ||
144 | detach(); | 152 | detach(); | ||
145 | return p()->m_vector.end(); | 153 | | ||
154 | Q_D(GeoDataMultiGeometry); | ||||
155 | return d->m_vector.end(); | ||||
146 | } | 156 | } | ||
147 | 157 | | |||
148 | QVector<GeoDataGeometry*>::ConstIterator GeoDataMultiGeometry::constBegin() const | 158 | QVector<GeoDataGeometry*>::ConstIterator GeoDataMultiGeometry::constBegin() const | ||
149 | { | 159 | { | ||
150 | return p()->m_vector.constBegin(); | 160 | Q_D(const GeoDataMultiGeometry); | ||
161 | return d->m_vector.constBegin(); | ||||
151 | } | 162 | } | ||
152 | 163 | | |||
153 | QVector<GeoDataGeometry*>::ConstIterator GeoDataMultiGeometry::constEnd() const | 164 | QVector<GeoDataGeometry*>::ConstIterator GeoDataMultiGeometry::constEnd() const | ||
154 | { | 165 | { | ||
155 | return p()->m_vector.constEnd(); | 166 | Q_D(const GeoDataMultiGeometry); | ||
167 | return d->m_vector.constEnd(); | ||||
156 | } | 168 | } | ||
157 | 169 | | |||
158 | /** | 170 | /** | ||
159 | * @brief returns the requested child item | 171 | * @brief returns the requested child item | ||
160 | */ | 172 | */ | ||
161 | GeoDataGeometry* GeoDataMultiGeometry::child( int i ) | 173 | GeoDataGeometry* GeoDataMultiGeometry::child( int i ) | ||
162 | { | 174 | { | ||
163 | detach(); | 175 | detach(); | ||
164 | return p()->m_vector.at( i ); | 176 | | ||
177 | Q_D(GeoDataMultiGeometry); | ||||
178 | return d->m_vector.at(i); | ||||
165 | } | 179 | } | ||
166 | 180 | | |||
167 | const GeoDataGeometry* GeoDataMultiGeometry::child( int i ) const | 181 | const GeoDataGeometry* GeoDataMultiGeometry::child( int i ) const | ||
168 | { | 182 | { | ||
169 | return p()->m_vector.at( i ); | 183 | Q_D(const GeoDataMultiGeometry); | ||
184 | return d->m_vector.at(i); | ||||
170 | } | 185 | } | ||
171 | 186 | | |||
172 | /** | 187 | /** | ||
173 | * @brief returns the position of an item in the list | 188 | * @brief returns the position of an item in the list | ||
174 | */ | 189 | */ | ||
175 | int GeoDataMultiGeometry::childPosition( const GeoDataGeometry *object ) const | 190 | int GeoDataMultiGeometry::childPosition( const GeoDataGeometry *object ) const | ||
176 | { | 191 | { | ||
177 | for ( int i=0; i< p()->m_vector.size(); i++ ) | 192 | Q_D(const GeoDataMultiGeometry); | ||
178 | { | 193 | for (int i = 0; i < d->m_vector.size(); ++i) { | ||
179 | if ( p()->m_vector.at( i ) == object ) | 194 | if (d->m_vector.at(i) == object) { | ||
180 | { | | |||
181 | return i; | 195 | return i; | ||
182 | } | 196 | } | ||
183 | } | 197 | } | ||
184 | return -1; | 198 | return -1; | ||
185 | } | 199 | } | ||
186 | 200 | | |||
187 | /** | 201 | /** | ||
188 | * @brief add an element | 202 | * @brief add an element | ||
189 | */ | 203 | */ | ||
190 | void GeoDataMultiGeometry::append( GeoDataGeometry *other ) | 204 | void GeoDataMultiGeometry::append( GeoDataGeometry *other ) | ||
191 | { | 205 | { | ||
192 | detach(); | 206 | detach(); | ||
207 | | ||||
208 | Q_D(GeoDataMultiGeometry); | ||||
193 | other->setParent( this ); | 209 | other->setParent( this ); | ||
194 | p()->m_vector.append( other ); | 210 | d->m_vector.append(other); | ||
195 | } | 211 | } | ||
196 | 212 | | |||
197 | 213 | | |||
198 | GeoDataMultiGeometry& GeoDataMultiGeometry::operator << ( const GeoDataGeometry& value ) | 214 | GeoDataMultiGeometry& GeoDataMultiGeometry::operator << ( const GeoDataGeometry& value ) | ||
199 | { | 215 | { | ||
200 | detach(); | 216 | detach(); | ||
217 | | ||||
218 | Q_D(GeoDataMultiGeometry); | ||||
201 | GeoDataGeometry *g = new GeoDataGeometry( value ); | 219 | GeoDataGeometry *g = new GeoDataGeometry( value ); | ||
202 | g->setParent( this ); | 220 | g->setParent( this ); | ||
203 | p()->m_vector.append( g ); | 221 | d->m_vector.append(g); | ||
204 | return *this; | 222 | return *this; | ||
205 | } | 223 | } | ||
206 | 224 | | |||
207 | void GeoDataMultiGeometry::clear() | 225 | void GeoDataMultiGeometry::clear() | ||
208 | { | 226 | { | ||
209 | detach(); | 227 | detach(); | ||
210 | qDeleteAll(p()->m_vector); | 228 | | ||
211 | p()->m_vector.clear(); | 229 | Q_D(GeoDataMultiGeometry); | ||
230 | qDeleteAll(d->m_vector); | ||||
231 | d->m_vector.clear(); | ||||
212 | } | 232 | } | ||
213 | 233 | | |||
214 | void GeoDataMultiGeometry::pack( QDataStream& stream ) const | 234 | void GeoDataMultiGeometry::pack( QDataStream& stream ) const | ||
215 | { | 235 | { | ||
236 | Q_D(const GeoDataMultiGeometry); | ||||
237 | | ||||
216 | GeoDataGeometry::pack( stream ); | 238 | GeoDataGeometry::pack( stream ); | ||
217 | 239 | | |||
218 | stream << p()->m_vector.size(); | 240 | stream << d->m_vector.size(); | ||
219 | 241 | | |||
220 | for( QVector<GeoDataGeometry*>::const_iterator iterator | 242 | for( QVector<GeoDataGeometry*>::const_iterator iterator | ||
221 | = p()->m_vector.constBegin(); | 243 | = d->m_vector.constBegin(); | ||
222 | iterator != p()->m_vector.constEnd(); | 244 | iterator != d->m_vector.constEnd(); | ||
223 | ++iterator ) { | 245 | ++iterator ) { | ||
224 | const GeoDataGeometry *geometry = *iterator; | 246 | const GeoDataGeometry *geometry = *iterator; | ||
225 | stream << geometry->geometryId(); | 247 | stream << geometry->geometryId(); | ||
226 | geometry->pack( stream ); | 248 | geometry->pack( stream ); | ||
227 | } | 249 | } | ||
228 | } | 250 | } | ||
229 | 251 | | |||
230 | void GeoDataMultiGeometry::unpack( QDataStream& stream ) | 252 | void GeoDataMultiGeometry::unpack( QDataStream& stream ) | ||
231 | { | 253 | { | ||
232 | detach(); | 254 | detach(); | ||
255 | | ||||
256 | Q_D(GeoDataMultiGeometry); | ||||
233 | GeoDataGeometry::unpack( stream ); | 257 | GeoDataGeometry::unpack( stream ); | ||
234 | 258 | | |||
235 | int size = 0; | 259 | int size = 0; | ||
236 | 260 | | |||
237 | stream >> size; | 261 | stream >> size; | ||
238 | 262 | | |||
239 | for( int i = 0; i < size; i++ ) { | 263 | for( int i = 0; i < size; i++ ) { | ||
240 | int geometryId; | 264 | int geometryId; | ||
241 | stream >> geometryId; | 265 | stream >> geometryId; | ||
242 | switch( geometryId ) { | 266 | switch( geometryId ) { | ||
243 | case InvalidGeometryId: | 267 | case InvalidGeometryId: | ||
244 | break; | 268 | break; | ||
245 | case GeoDataPointId: | 269 | case GeoDataPointId: | ||
246 | { | 270 | { | ||
247 | GeoDataPoint *point = new GeoDataPoint; | 271 | GeoDataPoint *point = new GeoDataPoint; | ||
248 | point->unpack( stream ); | 272 | point->unpack( stream ); | ||
249 | p()->m_vector.append( point ); | 273 | d->m_vector.append(point); | ||
250 | } | 274 | } | ||
251 | break; | 275 | break; | ||
252 | case GeoDataLineStringId: | 276 | case GeoDataLineStringId: | ||
253 | { | 277 | { | ||
254 | GeoDataLineString *lineString = new GeoDataLineString; | 278 | GeoDataLineString *lineString = new GeoDataLineString; | ||
255 | lineString->unpack( stream ); | 279 | lineString->unpack( stream ); | ||
256 | p()->m_vector.append( lineString ); | 280 | d->m_vector.append(lineString); | ||
257 | } | 281 | } | ||
258 | break; | 282 | break; | ||
259 | case GeoDataLinearRingId: | 283 | case GeoDataLinearRingId: | ||
260 | { | 284 | { | ||
261 | GeoDataLinearRing *linearRing = new GeoDataLinearRing; | 285 | GeoDataLinearRing *linearRing = new GeoDataLinearRing; | ||
262 | linearRing->unpack( stream ); | 286 | linearRing->unpack( stream ); | ||
263 | p()->m_vector.append( linearRing ); | 287 | d->m_vector.append(linearRing); | ||
264 | } | 288 | } | ||
265 | break; | 289 | break; | ||
266 | case GeoDataPolygonId: | 290 | case GeoDataPolygonId: | ||
267 | { | 291 | { | ||
268 | GeoDataPolygon *polygon = new GeoDataPolygon; | 292 | GeoDataPolygon *polygon = new GeoDataPolygon; | ||
269 | polygon->unpack( stream ); | 293 | polygon->unpack( stream ); | ||
270 | p()->m_vector.append( polygon ); | 294 | d->m_vector.append(polygon); | ||
271 | } | 295 | } | ||
272 | break; | 296 | break; | ||
273 | case GeoDataMultiGeometryId: | 297 | case GeoDataMultiGeometryId: | ||
274 | { | 298 | { | ||
275 | GeoDataMultiGeometry *multiGeometry = new GeoDataMultiGeometry; | 299 | GeoDataMultiGeometry *multiGeometry = new GeoDataMultiGeometry; | ||
276 | multiGeometry->unpack( stream ); | 300 | multiGeometry->unpack( stream ); | ||
277 | p()->m_vector.append( multiGeometry ); | 301 | d->m_vector.append(multiGeometry); | ||
278 | } | 302 | } | ||
279 | break; | 303 | break; | ||
280 | case GeoDataModelId: | 304 | case GeoDataModelId: | ||
281 | break; | 305 | break; | ||
282 | default: break; | 306 | default: break; | ||
283 | }; | 307 | }; | ||
284 | } | 308 | } | ||
285 | } | 309 | } | ||
286 | 310 | | |||
287 | } | 311 | } |