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
7// Own
8#include "GeoDataRegion.h"
9
10// Private
11#include "GeoDataRegion_p.h"
12
13// GeoData
14#include "GeoDataFeature.h"
15#include "GeoDataPlacemark.h"
16#include "GeoDataGeometry.h"
17#include "GeoDataTypes.h"
18
19// std
20#include <algorithm>
21
22
23namespace Marble
24{
26 : GeoDataObject(),
27 d( new GeoDataRegionPrivate )
28{
29}
30
32 : GeoDataObject( other ),
33 d( new GeoDataRegionPrivate( *other.d ) )
34{
35}
36
38 : GeoDataObject(),
39 d( new GeoDataRegionPrivate( feature ) )
40{
41}
42
43
45{
46 delete d;
47}
48
49
50const char* GeoDataRegion::nodeType() const
51{
52 return GeoDataTypes::GeoDataRegionType;
53}
54
55bool GeoDataRegion::operator==(const GeoDataRegion& other) const
56{
57 return equals(other)
58 && this->latLonAltBox() == other.latLonAltBox()
59 && this->lod() == other.lod();
60}
61
62bool GeoDataRegion::operator!=(const GeoDataRegion& other) const
63{
64 return !this->operator==(other);
65}
66
68{
69 // FIXME: This isn't exactly what a 'const' function should do, is it?
70
71 // If the latLonAltBox hasn't been set try to determine it automatically
72 if ( !d->m_latLonAltBox ) {
73 // If there is a parent try to
74 if ( d->m_parent ) {
75
76 if (const GeoDataPlacemark *placemark = geodata_cast<GeoDataPlacemark>(d->m_parent)) {
77 const GeoDataGeometry * geometry = placemark->geometry();
78 if ( geometry ) {
79 d->m_latLonAltBox = new GeoDataLatLonAltBox( placemark->geometry()->latLonAltBox() );
80 }
81 else {
82 d->m_latLonAltBox = new GeoDataLatLonAltBox();
83 }
84 }
85 else {
86 // If the parent is not a placemark then create a default LatLonAltBox
87 // FIXME: reference a shared object instead
88 d->m_latLonAltBox = new GeoDataLatLonAltBox();
89 }
90 }
91 else {
92 // If there is no parent then create a default LatLonAltBox
93 // FIXME: reference a shared object instead
94 d->m_latLonAltBox = new GeoDataLatLonAltBox();
95 }
96 }
97
98 return *(d->m_latLonAltBox);
99}
100
101
103{
104 delete d->m_latLonAltBox;
105 d->m_latLonAltBox = new GeoDataLatLonAltBox( latLonAltBox );
106}
107
108
110{
111 // If the lod hasn't been set then return a shared one
112 if ( !d->m_lod ) {
113 // FIXME: reference a shared object instead
114 d->m_lod = new GeoDataLod();
115 }
116
117 return *(d->m_lod);
118}
119
120
122{
123 delete d->m_lod;
124 d->m_lod = new GeoDataLod( lod );
125}
126
127
128void GeoDataRegion::pack( QDataStream& stream ) const
129{
130 GeoDataObject::pack( stream );
131
132 d->m_lod->pack( stream );
133 d->m_latLonAltBox->pack( stream );
134}
135
136
138{
139 GeoDataObject::unpack( stream );
140
141 d->m_lod->unpack( stream );
142 d->m_latLonAltBox->unpack( stream );
143}
144
145GeoDataRegion &GeoDataRegion::operator=( const GeoDataRegion& other )
146{
147 // Self assignment
148 if ( this == &other ) return *this;
149
150 GeoDataRegion temp( other );
151 swap( temp );
152 return *this;
153}
154
155void GeoDataRegion::swap( GeoDataRegion & other )
156{
157 std::swap( d, other.d );
158}
159
160}
161
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:40
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 Fri Jul 26 2024 11:57:57 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.