Marble

GeoDataMultiTrack.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2012 Thibaut Gridel <tgridel@free.fr>
4
5#include "GeoDataMultiTrack.h"
6#include "GeoDataMultiTrack_p.h"
7
8#include "GeoDataLineString.h"
9#include "GeoDataLinearRing.h"
10#include "GeoDataPoint.h"
11#include "GeoDataPolygon.h"
12#include "GeoDataTrack.h"
13#include "GeoDataTypes.h"
14
15#include "MarbleDebug.h"
16
17#include <QDataStream>
18
19
20namespace Marble
21{
22
23GeoDataMultiTrack::GeoDataMultiTrack()
24 : GeoDataGeometry( new GeoDataMultiTrackPrivate )
25{
26}
27
28GeoDataMultiTrack::GeoDataMultiTrack( const GeoDataGeometry& other )
29 : GeoDataGeometry( other )
30{
31}
32
33GeoDataMultiTrack::~GeoDataMultiTrack()
34{
35}
36
37const char *GeoDataMultiTrack::nodeType() const
38{
39 return GeoDataTypes::GeoDataMultiTrackType;
40}
41
42EnumGeometryId GeoDataMultiTrack::geometryId() const
43{
44 return GeoDataMultiTrackId;
45}
46
47GeoDataGeometry *GeoDataMultiTrack::copy() const
48{
49 return new GeoDataMultiTrack(*this);
50}
51
52bool GeoDataMultiTrack::operator==( const GeoDataMultiTrack& other ) const
53{
54 if ( !equals(other) ) return false;
55
56 Q_D(const GeoDataMultiTrack);
57 const GeoDataMultiTrackPrivate *other_d = other.d_func();
58
59 QVector<GeoDataTrack*>::const_iterator d_it = d->m_vector.constBegin();
60 QVector<GeoDataTrack*>::const_iterator d_end = d->m_vector.constEnd();
61 QVector<GeoDataTrack*>::const_iterator other_it = other_d->m_vector.constBegin();
62 QVector<GeoDataTrack*>::const_iterator other_end = other_d->m_vector.constEnd();
63
64
65 for (; d_it != d_end && other_it != other_end; ++d_it, ++other_it) {
66 if ( **d_it != **other_it ) return false;
67 }
68
69 return d_it == d_end && other_it == other_end;
70}
71
72bool GeoDataMultiTrack::operator!=( const GeoDataMultiTrack& other ) const
73{
74 return !this->operator==( other );
75}
76
77const GeoDataLatLonAltBox& GeoDataMultiTrack::latLonAltBox() const
78{
79 Q_D(const GeoDataMultiTrack);
80
81 QVector<GeoDataTrack*>::const_iterator it = d->m_vector.constBegin();
82 QVector<GeoDataTrack*>::const_iterator end = d->m_vector.constEnd();
83
84 d->m_latLonAltBox.clear();
85 for (; it != end; ++it) {
86 if ( !(*it)->latLonAltBox().isEmpty() ) {
87 if (d->m_latLonAltBox.isEmpty() ) {
88 d->m_latLonAltBox = (*it)->latLonAltBox();
89 }
90 else {
91 d->m_latLonAltBox |= (*it)->latLonAltBox();
92 }
93 }
94 }
95 return d->m_latLonAltBox;
96}
97
98int GeoDataMultiTrack::size() const
99{
100 Q_D(const GeoDataMultiTrack);
101 return d->m_vector.size();
102}
103
104QVector<GeoDataTrack> GeoDataMultiTrack::vector() const
105{
106 Q_D(const GeoDataMultiTrack);
107
108 QVector<GeoDataTrack> results;
109 results.reserve(d->m_vector.size());
110
111 QVector<GeoDataTrack*>::const_iterator it = d->m_vector.constBegin();
112 QVector<GeoDataTrack*>::const_iterator end = d->m_vector.constEnd();
113
114 for (; it != end; ++it) {
115 const GeoDataTrack f(**it);
116 results.append( f );
117 }
118
119 return results;
120}
121
122GeoDataTrack& GeoDataMultiTrack::at( int pos )
123{
124 mDebug() << "detaching!";
125 detach();
126
127 Q_D(GeoDataMultiTrack);
128 return *(d->m_vector[pos]);
129}
130
131const GeoDataTrack& GeoDataMultiTrack::at( int pos ) const
132{
133 Q_D(const GeoDataMultiTrack);
134 return *(d->m_vector.at(pos));
135}
136
137GeoDataTrack& GeoDataMultiTrack::operator[]( int pos )
138{
139 detach();
140
141 Q_D(GeoDataMultiTrack);
142 return *(d->m_vector[pos]);
143}
144
145const GeoDataTrack& GeoDataMultiTrack::operator[]( int pos ) const
146{
147 Q_D(const GeoDataMultiTrack);
148 return *(d->m_vector[pos]);
149}
150
151GeoDataTrack& GeoDataMultiTrack::last()
152{
153 detach();
154
155 Q_D(GeoDataMultiTrack);
156 return *(d->m_vector.last());
157}
158
159GeoDataTrack& GeoDataMultiTrack::first()
160{
161 detach();
162
163 Q_D(GeoDataMultiTrack);
164 return *(d->m_vector.first());
165}
166
167const GeoDataTrack& GeoDataMultiTrack::last() const
168{
169 Q_D(const GeoDataMultiTrack);
170 return *(d->m_vector.last());
171}
172
173const GeoDataTrack& GeoDataMultiTrack::first() const
174{
175 Q_D(const GeoDataMultiTrack);
176 return *(d->m_vector.first());
177}
178
179QVector<GeoDataTrack*>::Iterator GeoDataMultiTrack::begin()
180{
181 detach();
182
183 Q_D(GeoDataMultiTrack);
184 return d->m_vector.begin();
185}
186
187QVector<GeoDataTrack*>::Iterator GeoDataMultiTrack::end()
188{
189 detach();
190
191 Q_D(GeoDataMultiTrack);
192 return d->m_vector.end();
193}
194
195QVector<GeoDataTrack*>::ConstIterator GeoDataMultiTrack::constBegin() const
196{
197 Q_D(const GeoDataMultiTrack);
198 return d->m_vector.constBegin();
199}
200
201QVector<GeoDataTrack*>::ConstIterator GeoDataMultiTrack::constEnd() const
202{
203 Q_D(const GeoDataMultiTrack);
204 return d->m_vector.constEnd();
205}
206
207/**
208 * @brief returns the requested child item
209 */
210GeoDataTrack* GeoDataMultiTrack::child( int i )
211{
212 detach();
213
214 Q_D(const GeoDataMultiTrack);
215 return d->m_vector.at(i);
216}
217
218const GeoDataTrack* GeoDataMultiTrack::child( int i ) const
219{
220 Q_D(const GeoDataMultiTrack);
221 return d->m_vector.at(i);
222}
223
224/**
225 * @brief returns the position of an item in the list
226 */
227int GeoDataMultiTrack::childPosition( const GeoDataTrack *object ) const
228{
229 Q_D(const GeoDataMultiTrack);
230 for (int i = 0; i < d->m_vector.size(); ++i) {
231 if (d->m_vector.at(i) == object) {
232 return i;
233 }
234 }
235 return -1;
236}
237
238/**
239* @brief add an element
240*/
241void GeoDataMultiTrack::append( GeoDataTrack *other )
242{
243 detach();
244
245 Q_D(GeoDataMultiTrack);
246 other->setParent( this );
247 d->m_vector.append(other);
248}
249
250
251GeoDataMultiTrack& GeoDataMultiTrack::operator << ( const GeoDataTrack& value )
252{
253 detach();
254
255 Q_D(GeoDataMultiTrack);
256 GeoDataTrack *g = new GeoDataTrack( value );
257 g->setParent( this );
258 d->m_vector.append(g);
259 return *this;
260}
261
262void GeoDataMultiTrack::clear()
263{
264 detach();
265
266 Q_D(GeoDataMultiTrack);
267 qDeleteAll(d->m_vector);
268 d->m_vector.clear();
269}
270
271void GeoDataMultiTrack::pack( QDataStream& stream ) const
272{
273 Q_D(const GeoDataMultiTrack);
274
275 GeoDataGeometry::pack( stream );
276
277 stream << d->m_vector.size();
278
280 = d->m_vector.constBegin();
281 iterator != d->m_vector.constEnd();
282 ++iterator ) {
283 const GeoDataTrack *geometry = *iterator;
284 stream << geometry->geometryId();
285 geometry->pack( stream );
286 }
287}
288
289void GeoDataMultiTrack::unpack( QDataStream& stream )
290{
291 detach();
292
293 Q_D(GeoDataMultiTrack);
294 GeoDataGeometry::unpack( stream );
295
296 int size = 0;
297
298 stream >> size;
299
300 for( int i = 0; i < size; i++ ) {
301 int geometryId;
302 stream >> geometryId;
303 switch( geometryId ) {
304 case InvalidGeometryId:
305 break;
306 case GeoDataTrackId:
307 {
308 GeoDataTrack *track = new GeoDataTrack;
309 track->unpack( stream );
310 d->m_vector.append( track );
311 }
312 break;
313 case GeoDataModelId:
314 break;
315 default: break;
316 };
317 }
318}
319
320}
const QList< QKeySequence > & end()
bool equals(const QVariant &lhs, const QVariant &rhs)
Binds a QML item to a specific geodetic location in screen coordinates.
void append(QList< T > &&value)
void reserve(qsizetype size)
bool operator==(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.