Marble

GeoDataRegion.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2009 Torsten Rahn <rahn@kde.org>
4//
5
6// Own
7#include "GeoDataRegion.h"
8
9// Private
10#include "GeoDataRegion_p.h"
11
12// GeoData
13#include "GeoDataFeature.h"
14#include "GeoDataGeometry.h"
15#include "GeoDataPlacemark.h"
16#include "GeoDataTypes.h"
17
18// std
19#include <algorithm>
20
21namespace Marble
22{
25 , d(new GeoDataRegionPrivate)
26{
27}
28
30 : GeoDataObject(other)
31 , d(new GeoDataRegionPrivate(*other.d))
32{
33}
34
37 , d(new GeoDataRegionPrivate(feature))
38{
39}
40
42{
43 delete d;
44}
45
46const char *GeoDataRegion::nodeType() const
47{
48 return GeoDataTypes::GeoDataRegionType;
49}
50
51bool GeoDataRegion::operator==(const GeoDataRegion &other) const
52{
53 return equals(other) && this->latLonAltBox() == other.latLonAltBox() && this->lod() == other.lod();
54}
55
56bool GeoDataRegion::operator!=(const GeoDataRegion &other) const
57{
58 return !this->operator==(other);
59}
60
62{
63 // FIXME: This isn't exactly what a 'const' function should do, is it?
64
65 // If the latLonAltBox hasn't been set try to determine it automatically
66 if (!d->m_latLonAltBox) {
67 // If there is a parent try to
68 if (d->m_parent) {
69 if (const GeoDataPlacemark *placemark = geodata_cast<GeoDataPlacemark>(d->m_parent)) {
70 const GeoDataGeometry *geometry = placemark->geometry();
71 if (geometry) {
72 d->m_latLonAltBox = new GeoDataLatLonAltBox(placemark->geometry()->latLonAltBox());
73 } else {
74 d->m_latLonAltBox = new GeoDataLatLonAltBox();
75 }
76 } else {
77 // If the parent is not a placemark then create a default LatLonAltBox
78 // FIXME: reference a shared object instead
79 d->m_latLonAltBox = new GeoDataLatLonAltBox();
80 }
81 } else {
82 // If there is no parent then create a default LatLonAltBox
83 // FIXME: reference a shared object instead
84 d->m_latLonAltBox = new GeoDataLatLonAltBox();
85 }
86 }
87
88 return *(d->m_latLonAltBox);
89}
90
92{
93 delete d->m_latLonAltBox;
94 d->m_latLonAltBox = new GeoDataLatLonAltBox(latLonAltBox);
95}
96
98{
99 // If the lod hasn't been set then return a shared one
100 if (!d->m_lod) {
101 // FIXME: reference a shared object instead
102 d->m_lod = new GeoDataLod();
103 }
104
105 return *(d->m_lod);
106}
107
109{
110 delete d->m_lod;
111 d->m_lod = new GeoDataLod(lod);
112}
113
115{
116 GeoDataObject::pack(stream);
117
118 d->m_lod->pack(stream);
119 d->m_latLonAltBox->pack(stream);
120}
121
123{
124 GeoDataObject::unpack(stream);
125
126 d->m_lod->unpack(stream);
127 d->m_latLonAltBox->unpack(stream);
128}
129
130GeoDataRegion &GeoDataRegion::operator=(const GeoDataRegion &other)
131{
132 // Self assignment
133 if (this == &other)
134 return *this;
135
136 GeoDataRegion temp(other);
137 swap(temp);
138 return *this;
139}
140
141void GeoDataRegion::swap(GeoDataRegion &other)
142{
143 std::swap(d, other.d);
144}
145
146}
A base class for all geodata features.
A base class for all geodata features.
A class that defines a 3D bounding box for geographic data.
The level of detail which indicates visibility and importance.
Definition GeoDataLod.h:38
A base class for all geodata objects.
virtual bool equals(const GeoDataObject &other) const
Compares the value of id and targetId of the two objects.
void pack(QDataStream &stream) const override
Reimplemented from Serializable.
void unpack(QDataStream &steam) override
Reimplemented from Serializable.
a class representing a point of interest on the map
GeoDataRegion describes the visibility and extent of a feature.
void setLod(const GeoDataLod &lod)
Sets a region's level of detail. The level of detail is set as a lod object.
void pack(QDataStream &stream) const override
Serialize the Region to a stream.
GeoDataLod & lod() const
Returns the region's level of detail. The level of detail is returned as a lod object....
void setLatLonAltBox(const GeoDataLatLonAltBox &latLonAltBox)
Sets the latLonAltBox of the region. Sets the geodesic bounding box that describes the extent of a fe...
~GeoDataRegion() override
Destroys a Region object.
void unpack(QDataStream &stream) override
Unserialize the Region from a stream.
GeoDataRegion()
Creates a new GeoDataRegion object that is not assigned to a feature. Naturally it's recommended to a...
const GeoDataLatLonAltBox & latLonAltBox() const
Returns a geodesic bounding box ("latLonAltBox") of the region. Returns a geodesic bounding box that ...
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
Binds a QML item to a specific geodetic location in screen coordinates.
T * geodata_cast(GeoDataObject *node)
Returns the given node cast to type T if the node was instantiated as type T; otherwise returns 0.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.