Marble

GeoDataRegion.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2009 Torsten Rahn <[email protected]>
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 
23 namespace 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 
50 const char* GeoDataRegion::nodeType() const
51 {
52  return GeoDataTypes::GeoDataRegionType;
53 }
54 
55 bool GeoDataRegion::operator==(const GeoDataRegion& other) const
56 {
57  return equals(other)
58  && this->latLonAltBox() == other.latLonAltBox()
59  && this->lod() == other.lod();
60 }
61 
62 bool 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 
128 void 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 
145 GeoDataRegion &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 
155 void GeoDataRegion::swap( GeoDataRegion & other )
156 {
157  std::swap( d, other.d );
158 }
159 
160 }
161 
A class that defines a 3D bounding box for geographic data.
void unpack(QDataStream &stream) override
Unserialize the Region from a stream.
void setLatLonAltBox(const GeoDataLatLonAltBox &latLonAltBox)
Sets the latLonAltBox of the region. Sets the geodesic bounding box that describes the extent of a fe...
A base class for all geodata features.
const GeoDataLatLonAltBox & latLonAltBox() const
Returns a geodesic bounding box ("latLonAltBox") of the region. Returns a geodesic bounding box that ...
~GeoDataRegion() override
Destroys a Region object.
A base class for all geodata features.
A base class for all geodata objects.
Definition: GeoDataObject.h:43
void pack(QDataStream &stream) const override
Reimplemented from Serializable.
Binds a QML item to a specific geodetic location in screen coordinates.
virtual bool equals(const GeoDataObject &other) const
Compares the value of id and targetId of the two objects.
void setLod(const GeoDataLod &lod)
Sets a region's level of detail. The level of detail is set as a lod object.
GeoDataRegion()
Creates a new GeoDataRegion object that is not assigned to a feature. Naturally it's recommended to a...
a class representing a point of interest on the map
void pack(QDataStream &stream) const override
Serialize the Region to a stream.
GeoDataRegion describes the visibility and extent of a feature.
Definition: GeoDataRegion.h:43
GeoDataLod & lod() const
Returns the region's level of detail. The level of detail is returned as a lod object....
void unpack(QDataStream &steam) override
Reimplemented from Serializable.
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
The level of detail which indicates visibility and importance.
Definition: GeoDataLod.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Oct 2 2023 03:52:08 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.