6#include "GeoDataMultiGeometry.h"
7#include "GeoDataMultiGeometry_p.h"
9#include "GeoDataLineString.h"
10#include "GeoDataLinearRing.h"
11#include "GeoDataPoint.h"
12#include "GeoDataPolygon.h"
13#include "GeoDataTypes.h"
15#include "MarbleDebug.h"
22GeoDataMultiGeometry::GeoDataMultiGeometry()
23 : GeoDataGeometry(new GeoDataMultiGeometryPrivate)
27GeoDataMultiGeometry::GeoDataMultiGeometry(
const GeoDataGeometry &other)
28 : GeoDataGeometry(other)
32GeoDataMultiGeometry::~GeoDataMultiGeometry() =
default;
34const char *GeoDataMultiGeometry::nodeType()
const
36 return GeoDataTypes::GeoDataMultiGeometryType;
39EnumGeometryId GeoDataMultiGeometry::geometryId()
const
41 return GeoDataMultiGeometryId;
44GeoDataGeometry *GeoDataMultiGeometry::copy()
const
46 return new GeoDataMultiGeometry(*
this);
49bool GeoDataMultiGeometry::operator==(
const GeoDataMultiGeometry &other)
const
51 Q_D(
const GeoDataMultiGeometry);
52 const GeoDataMultiGeometryPrivate *
const other_d = other.d_func();
58 for (; thisBegin != thisEnd && otherBegin != otherEnd; ++thisBegin, ++otherBegin) {
59 if (**thisBegin != **otherBegin) {
67const GeoDataLatLonAltBox &GeoDataMultiGeometry::latLonAltBox()
const
69 Q_D(
const GeoDataMultiGeometry);
74 d->m_latLonAltBox.clear();
75 for (; it !=
end; ++it) {
76 if (!(*it)->latLonAltBox().isEmpty()) {
77 if (d->m_latLonAltBox.isEmpty()) {
78 d->m_latLonAltBox = (*it)->latLonAltBox();
80 d->m_latLonAltBox |= (*it)->latLonAltBox();
84 return d->m_latLonAltBox;
87int GeoDataMultiGeometry::size()
const
89 Q_D(
const GeoDataMultiGeometry);
90 return d->m_vector.size();
95 Q_D(
const GeoDataMultiGeometry);
100GeoDataGeometry &GeoDataMultiGeometry::at(
int pos)
102 mDebug() <<
"detaching!";
105 Q_D(GeoDataMultiGeometry);
106 return *(d->m_vector[pos]);
109const GeoDataGeometry &GeoDataMultiGeometry::at(
int pos)
const
111 Q_D(
const GeoDataMultiGeometry);
112 return *(d->m_vector.at(pos));
115GeoDataGeometry &GeoDataMultiGeometry::operator[](
int pos)
119 Q_D(GeoDataMultiGeometry);
120 return *(d->m_vector[pos]);
123const GeoDataGeometry &GeoDataMultiGeometry::operator[](
int pos)
const
125 Q_D(
const GeoDataMultiGeometry);
126 return *(d->m_vector[pos]);
129GeoDataGeometry &GeoDataMultiGeometry::last()
133 Q_D(GeoDataMultiGeometry);
134 return *(d->m_vector.last());
137GeoDataGeometry &GeoDataMultiGeometry::first()
141 Q_D(GeoDataMultiGeometry);
142 return *(d->m_vector.first());
145const GeoDataGeometry &GeoDataMultiGeometry::last()
const
147 Q_D(
const GeoDataMultiGeometry);
148 return *(d->m_vector.last());
151const GeoDataGeometry &GeoDataMultiGeometry::first()
const
153 Q_D(
const GeoDataMultiGeometry);
154 return *(d->m_vector.first());
161 Q_D(GeoDataMultiGeometry);
162 return d->m_vector.begin();
169 Q_D(GeoDataMultiGeometry);
170 return d->m_vector.end();
175 Q_D(
const GeoDataMultiGeometry);
176 return d->m_vector.constBegin();
181 Q_D(
const GeoDataMultiGeometry);
182 return d->m_vector.constEnd();
193 return d->m_vector.at(i);
199 return d->m_vector.at(i);
208 for (
int i = 0; i < d->m_vector.size(); ++i) {
209 if (d->m_vector.at(i) ==
object) {
225 d->m_vector.append(other);
235 d->m_vector.append(g);
239void GeoDataMultiGeometry::clear()
243 Q_D(GeoDataMultiGeometry);
244 qDeleteAll(d->m_vector);
248void GeoDataMultiGeometry::pack(
QDataStream &stream)
const
250 Q_D(
const GeoDataMultiGeometry);
252 GeoDataGeometry::pack(stream);
254 stream << d->m_vector.size();
257 const GeoDataGeometry *geometry = *iterator;
258 stream << geometry->geometryId();
259 geometry->pack(stream);
263void GeoDataMultiGeometry::unpack(
QDataStream &stream)
267 Q_D(GeoDataMultiGeometry);
268 GeoDataGeometry::unpack(stream);
274 for (
int i = 0; i < size; i++) {
276 stream >> geometryId;
277 switch (geometryId) {
278 case InvalidGeometryId:
280 case GeoDataPointId: {
281 auto point =
new GeoDataPoint;
282 point->unpack(stream);
283 d->m_vector.append(point);
285 case GeoDataLineStringId: {
286 auto lineString =
new GeoDataLineString;
287 lineString->unpack(stream);
288 d->m_vector.append(lineString);
290 case GeoDataLinearRingId: {
291 auto linearRing =
new GeoDataLinearRing;
292 linearRing->unpack(stream);
293 d->m_vector.append(linearRing);
295 case GeoDataPolygonId: {
296 auto polygon =
new GeoDataPolygon;
297 polygon->unpack(stream);
298 d->m_vector.append(polygon);
300 case GeoDataMultiGeometryId: {
301 auto multiGeometry =
new GeoDataMultiGeometry;
302 multiGeometry->unpack(stream);
303 d->m_vector.append(multiGeometry);
A base class for all geodata features.
A class that can contain other GeoDataGeometry objects.
void setParent(GeoDataObject *parent)
Sets the parent of the object.
const QList< QKeySequence > & end()
Binds a QML item to a specific geodetic location in screen coordinates.