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

KDE's Doxygen guidelines are available online.