• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • geodata
  • data
GeoDataPlacemark.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2004-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 // Copyright 2008-2009 Patrick Spendrin <ps_ml@gmx.de>
11 //
12 
13 
14 // Own
15 #include "GeoDataPlacemark.h"
16 
17 // Private
18 #include "GeoDataPlacemark_p.h"
19 
20 #include "GeoDataMultiGeometry.h"
21 #include "GeoDataCoordinates.h"
22 
23 // Qt
24 #include <QDataStream>
25 #include "MarbleDebug.h"
26 #include "GeoDataTrack.h"
27 
28 namespace Marble
29 {
30 GeoDataPlacemark::GeoDataPlacemark()
31  : GeoDataFeature( new GeoDataPlacemarkPrivate )
32 {
33  p()->m_geometry->setParent( this );
34 }
35 
36 GeoDataPlacemark::GeoDataPlacemark( const GeoDataPlacemark& other )
37 : GeoDataFeature( other )
38 {
39  p()->m_geometry->setParent( this );
40 }
41 
42 GeoDataPlacemark::GeoDataPlacemark( const QString& name )
43  : GeoDataFeature( new GeoDataPlacemarkPrivate )
44 {
45  d->m_name = name;
46  p()->m_geometry->setParent( this );
47 }
48 
49 GeoDataPlacemark::~GeoDataPlacemark()
50 {
51 }
52 
53 bool GeoDataPlacemark::operator==( const GeoDataPlacemark& other ) const
54 {
55  return p() == other.p();
56 }
57 
58 GeoDataPlacemarkPrivate* GeoDataPlacemark::p() const
59 {
60  return static_cast<GeoDataPlacemarkPrivate*>(d);
61 }
62 
63 GeoDataGeometry* GeoDataPlacemark::geometry() const
64 {
65  return p()->m_geometry;
66 }
67 
68 const GeoDataLookAt *GeoDataPlacemark::lookAt() const
69 {
70  return dynamic_cast<const GeoDataLookAt*>( abstractView() );
71 }
72 
73 GeoDataLookAt *GeoDataPlacemark::lookAt()
74 {
75  return dynamic_cast<GeoDataLookAt*>( abstractView() );
76 }
77 
78 GeoDataCoordinates GeoDataPlacemark::coordinate( const QDateTime &dateTime, bool *iconAtCoordinates ) const
79 {
80  bool hasIcon = false;
81  GeoDataCoordinates coord;
82 
83  if( p()->m_geometry ) {
84  // Beware: comparison between pointers, not strings.
85  if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataPointType ) {
86  hasIcon = true;
87  coord = static_cast<GeoDataPoint *>( p()->m_geometry )->coordinates();
88  } else if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) {
89  GeoDataMultiGeometry *multiGeometry = static_cast<GeoDataMultiGeometry *>( p()->m_geometry );
90 
91  QVector<GeoDataGeometry*>::ConstIterator it = multiGeometry->constBegin();
92  QVector<GeoDataGeometry*>::ConstIterator end = multiGeometry->constEnd();
93  for ( ; it != end; ++it ) {
94  if ( (*it)->nodeType() == GeoDataTypes::GeoDataPointType ) {
95  hasIcon = true;
96  break;
97  }
98  }
99 
100  coord = p()->m_geometry->latLonAltBox().center();
101  } else if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataTrackType ) {
102  GeoDataTrack *track = static_cast<GeoDataTrack *>( p()->m_geometry );
103  hasIcon = track->size() != 0 && track->firstWhen() <= dateTime;
104  coord = track->coordinatesAt( dateTime );
105  } else {
106  coord = p()->m_geometry->latLonAltBox().center();
107  }
108  }
109 
110  if ( iconAtCoordinates != 0 ) {
111  *iconAtCoordinates = hasIcon;
112  }
113  return coord;
114 }
115 
116 void GeoDataPlacemark::coordinate( qreal& lon, qreal& lat, qreal& alt ) const
117 {
118  coordinate().geoCoordinates( lon, lat, alt );
119 }
120 
121 void GeoDataPlacemark::setCoordinate( qreal lon, qreal lat, qreal alt, GeoDataPoint::Unit _unit)
122 {
123  setGeometry( new GeoDataPoint(lon, lat, alt, _unit ) );
124 }
125 
126 void GeoDataPlacemark::setCoordinate( const GeoDataCoordinates &point )
127 {
128  setGeometry ( new GeoDataPoint( point ) );
129 }
130 
131 void GeoDataPlacemark::setCoordinate( const GeoDataPoint &point )
132 {
133  setGeometry ( new GeoDataPoint( point ) );
134 }
135 
136 void GeoDataPlacemark::setGeometry( GeoDataGeometry *entry )
137 {
138  detach();
139  delete p()->m_geometry;
140  p()->m_geometry = entry;
141  p()->m_geometry->setParent( this );
142 }
143 
144 qreal GeoDataPlacemark::area() const
145 {
146  return p()->m_area;
147 }
148 
149 void GeoDataPlacemark::setArea( qreal area )
150 {
151  detach();
152  p()->m_area = area;
153 }
154 
155 qint64 GeoDataPlacemark::population() const
156 {
157  return p()->m_population;
158 }
159 
160 void GeoDataPlacemark::setPopulation( qint64 population )
161 {
162  detach();
163  p()->m_population = population;
164 }
165 
166 const QString GeoDataPlacemark::state() const
167 {
168  return p()->m_state;
169 }
170 
171 void GeoDataPlacemark::setState( const QString &state )
172 {
173  detach();
174  p()->m_state = state;
175 }
176 
177 const QString GeoDataPlacemark::countryCode() const
178 {
179  return p()->m_countrycode;
180 }
181 
182 void GeoDataPlacemark::setCountryCode( const QString &countrycode )
183 {
184  detach();
185  p()->m_countrycode = countrycode;
186 }
187 
188 void GeoDataPlacemark::pack( QDataStream& stream ) const
189 {
190  GeoDataFeature::pack( stream );
191 
192  stream << p()->m_countrycode;
193  stream << p()->m_area;
194  stream << p()->m_population;
195  if ( p()->m_geometry )
196  {
197  stream << p()->m_geometry->geometryId();
198  p()->m_geometry->pack( stream );
199  }
200  else
201  {
202  stream << InvalidGeometryId;
203  }
204 }
205 
206 QXmlStreamWriter& GeoDataPlacemark::pack( QXmlStreamWriter& stream ) const
207 {
208  stream.writeStartElement( "placemark" );
209 
210  stream.writeEndElement();
211  return stream;
212 }
213 
214 QXmlStreamWriter& GeoDataPlacemark::operator <<( QXmlStreamWriter& stream ) const
215 {
216  pack( stream );
217  return stream;
218 }
219 
220 void GeoDataPlacemark::unpack( QDataStream& stream )
221 {
222  detach();
223  GeoDataFeature::unpack( stream );
224 
225  stream >> p()->m_countrycode;
226  stream >> p()->m_area;
227  stream >> p()->m_population;
228  int geometryId;
229  stream >> geometryId;
230  switch( geometryId ) {
231  case InvalidGeometryId:
232  break;
233  case GeoDataPointId:
234  {
235  GeoDataPoint* point = new GeoDataPoint;
236  point->unpack( stream );
237  delete p()->m_geometry;
238  p()->m_geometry = point;
239  }
240  break;
241  case GeoDataLineStringId:
242  {
243  GeoDataLineString* lineString = new GeoDataLineString;
244  lineString->unpack( stream );
245  delete p()->m_geometry;
246  p()->m_geometry = lineString;
247  }
248  break;
249  case GeoDataLinearRingId:
250  {
251  GeoDataLinearRing* linearRing = new GeoDataLinearRing;
252  linearRing->unpack( stream );
253  delete p()->m_geometry;
254  p()->m_geometry = linearRing;
255  }
256  break;
257  case GeoDataPolygonId:
258  {
259  GeoDataPolygon* polygon = new GeoDataPolygon;
260  polygon->unpack( stream );
261  delete p()->m_geometry;
262  p()->m_geometry = polygon;
263  }
264  break;
265  case GeoDataMultiGeometryId:
266  {
267  GeoDataMultiGeometry* multiGeometry = new GeoDataMultiGeometry;
268  multiGeometry->unpack( stream );
269  delete p()->m_geometry;
270  p()->m_geometry = multiGeometry;
271  }
272  break;
273  case GeoDataModelId:
274  break;
275  default: break;
276  };
277 }
278 
279 }
Marble::GeoDataCoordinates::Unit
Unit
enum used constructor to specify the units used
Definition: GeoDataCoordinates.h:64
Marble::GeoDataPointId
Definition: Serializable.h:42
Marble::GeoDataPoint
A Geometry object representing a 3d point.
Definition: GeoDataPoint.h:47
GeoDataCoordinates.h
QXmlStreamWriter
Marble::GeoDataPlacemark::lookAt
const GeoDataLookAt * lookAt() const
Returns GeoDataLookAt object if lookAt is setup earlier otherwise It will convert GeoDataCoordinates ...
Definition: GeoDataPlacemark.cpp:68
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataGeometry::nodeType
virtual const char * nodeType() const
Provides type information for downcasting a GeoData.
Definition: GeoDataGeometry.cpp:77
Marble::GeoDataTypes::GeoDataMultiGeometryType
const char * GeoDataMultiGeometryType
Definition: GeoDataTypes.cpp:56
Marble::GeoDataTrack
A geometry for tracking objects made of (time, coordinates) pairs.
Definition: GeoDataTrack.h:54
Marble::GeoDataTypes::GeoDataPointType
const char * GeoDataPointType
Definition: GeoDataTypes.cpp:64
Marble::GeoDataPlacemark::pack
virtual void pack(QDataStream &stream) const
Serialize the Placemark to a data stream.
Definition: GeoDataPlacemark.cpp:188
Marble::GeoDataLinearRing
A LinearRing that allows to store a closed, contiguous set of line segments.
Definition: GeoDataLinearRing.h:68
Marble::GeoDataPlacemarkPrivate::nodeType
virtual const char * nodeType() const
Definition: GeoDataPlacemark_p.h:89
Marble::GeoDataMultiGeometry::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataMultiGeometry.cpp:222
Marble::GeoDataFeaturePrivate::m_name
QString m_name
Definition: GeoDataFeature_p.h:179
Marble::GeoDataPlacemarkPrivate
Definition: GeoDataPlacemark_p.h:23
Marble::GeoDataGeometry
A base class for all geodata features.
Definition: GeoDataGeometry.h:47
Marble::GeoDataPlacemark::~GeoDataPlacemark
~GeoDataPlacemark()
Delete the placemark.
Definition: GeoDataPlacemark.cpp:49
Marble::GeoDataPlacemark::coordinate
GeoDataCoordinates coordinate(const QDateTime &dateTime=QDateTime(), bool *iconAtCoordinates=0) const
Return the coordinates of the placemark at time dateTime as a GeoDataCoordinates. ...
Definition: GeoDataPlacemark.cpp:78
GeoDataPlacemark_p.h
Marble::GeoDataPlacemark::setCoordinate
void setCoordinate(qreal longitude, qreal latitude, qreal altitude=0, GeoDataCoordinates::Unit _unit=GeoDataCoordinates::Radian)
Set the coordinate of the placemark in longitude and latitude.
Definition: GeoDataPlacemark.cpp:121
Marble::GeoDataPlacemark::setState
void setState(const QString &state)
Set the state state of the placemark.
Definition: GeoDataPlacemark.cpp:171
Marble::GeoDataFeature::pack
virtual void pack(QDataStream &stream) const
Serialize the contents of the feature to stream.
Definition: GeoDataFeature.cpp:754
Marble::GeoDataLineString::unpack
virtual void unpack(QDataStream &stream)
Unserialize the LineString from a stream.
Definition: GeoDataLineString.cpp:627
Marble::GeoDataPlacemark::geometry
GeoDataGeometry * geometry() const
The geometry of the GeoDataPlacemark is to be rendered to the marble map along with the icon at the c...
Definition: GeoDataPlacemark.cpp:63
MarbleDebug.h
GeoDataTrack.h
Marble::GeoDataLinearRingId
Definition: Serializable.h:44
Marble::GeoDataPlacemark::population
qint64 population() const
Return the population of the placemark.
Definition: GeoDataPlacemark.cpp:155
Marble::GeoDataGeometry::pack
virtual void pack(QDataStream &stream) const
Serialize the contents of the feature to stream.
Definition: GeoDataGeometry.cpp:127
Marble::GeoDataObject::setParent
virtual void setParent(GeoDataObject *parent)
Sets the parent of the object.
Definition: GeoDataObject.cpp:70
GeoDataMultiGeometry.h
Marble::GeoDataFeature::abstractView
const GeoDataAbstractView * abstractView() const
Get the Abstract view of the feature.
Definition: GeoDataFeature.cpp:535
Marble::GeoDataCoordinates::geoCoordinates
void geoCoordinates(qreal &lon, qreal &lat, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
use this function to get the longitude and latitude with one call - use the unit parameter to switch ...
Definition: GeoDataCoordinates.cpp:715
Marble::GeoDataPolygon
A polygon that can have "holes".
Definition: GeoDataPolygon.h:81
Marble::GeoDataPlacemarkPrivate::m_countrycode
QString m_countrycode
Definition: GeoDataPlacemark_p.h:101
Marble::GeoDataMultiGeometryId
Definition: Serializable.h:46
Marble::GeoDataPoint::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataPoint.cpp:100
Marble::GeoDataFeature::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataFeature.cpp:769
Marble::GeoDataPlacemark::GeoDataPlacemark
GeoDataPlacemark()
Create a new placemark.
Definition: GeoDataPlacemark.cpp:30
Marble::GeoDataPlacemarkPrivate::m_area
qreal m_area
Definition: GeoDataPlacemark_p.h:102
Marble::GeoDataFeature::d
GeoDataFeaturePrivate * d
Definition: GeoDataFeature.h:484
Marble::GeoDataPlacemark::operator<<
virtual QXmlStreamWriter & operator<<(QXmlStreamWriter &stream) const
Definition: GeoDataPlacemark.cpp:214
Marble::GeoDataMultiGeometry::constBegin
QVector< GeoDataGeometry * >::ConstIterator constBegin() const
Definition: GeoDataMultiGeometry.cpp:141
GeoDataPlacemark.h
Marble::GeoDataTrack::size
int size() const
Returns the number of points in the track.
Definition: GeoDataTrack.cpp:67
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
Marble::GeoDataModelId
Definition: Serializable.h:48
Marble::GeoDataPlacemarkPrivate::m_population
qint64 m_population
Definition: GeoDataPlacemark_p.h:103
Marble::GeoDataPlacemark::operator==
bool operator==(const GeoDataPlacemark &other) const
comparison operator is implemented slightly different than one would expect.
Definition: GeoDataPlacemark.cpp:53
Marble::GeoDataLatLonAltBox::center
virtual GeoDataCoordinates center() const
returns the center of this box
Definition: GeoDataLatLonAltBox.cpp:152
Marble::GeoDataPlacemark::state
const QString state() const
Return the state of the placemark.
Definition: GeoDataPlacemark.cpp:166
Marble::GeoDataPlacemark::setPopulation
void setPopulation(qint64 population)
Sets the population of the placemark.
Definition: GeoDataPlacemark.cpp:160
Marble::GeoDataPolygon::unpack
virtual void unpack(QDataStream &stream)
Unserialize the Polygon from a stream.
Definition: GeoDataPolygon.cpp:136
Marble::GeoDataTrack::coordinatesAt
GeoDataCoordinates coordinatesAt(const QDateTime &when) const
If interpolate() is true, return the coordinates interpolated from the time values before and after w...
Definition: GeoDataTrack.cpp:110
Marble::GeoDataLookAt
Definition: GeoDataLookAt.h:23
Marble::GeoDataTrack::firstWhen
QDateTime firstWhen() const
Return the time value of the first point in the track, or an invalid QDateTime if the track is empty...
Definition: GeoDataTrack.cpp:82
Marble::GeoDataPlacemark::countryCode
const QString countryCode() const
Return the country code of the placemark.
Definition: GeoDataPlacemark.cpp:177
Marble::GeoDataPlacemark::unpack
virtual void unpack(QDataStream &stream)
Deserialize the Placemark from a data stream.
Definition: GeoDataPlacemark.cpp:220
Marble::GeoDataPlacemarkPrivate::m_state
QString m_state
Definition: GeoDataPlacemark_p.h:104
Marble::GeoDataFeature
A base class for all geodata features.
Definition: GeoDataFeature.h:55
Marble::GeoDataFeature::name
QString name() const
The name of the feature.
Definition: GeoDataFeature.cpp:480
Marble::GeoDataMultiGeometry::constEnd
QVector< GeoDataGeometry * >::ConstIterator constEnd() const
Definition: GeoDataMultiGeometry.cpp:146
Marble::GeoDataMultiGeometry
Definition: GeoDataMultiGeometry.h:33
Marble::GeoDataPlacemark::area
qreal area() const
Return the area size of the feature in square km.
Definition: GeoDataPlacemark.cpp:144
Marble::GeoDataPlacemark::setArea
void setArea(qreal area)
Set the area size of the feature in square km.
Definition: GeoDataPlacemark.cpp:149
Marble::GeoDataGeometry::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Definition: GeoDataGeometry.cpp:122
Marble::GeoDataLineStringId
Definition: Serializable.h:43
Marble::GeoDataTypes::GeoDataTrackType
const char * GeoDataTrackType
Definition: GeoDataTypes.cpp:77
Marble::GeoDataPlacemark::setCountryCode
void setCountryCode(const QString &code)
Set the country code of the placemark.
Definition: GeoDataPlacemark.cpp:182
Marble::GeoDataPlacemark
a class representing a point of interest on the map
Definition: GeoDataPlacemark.h:54
Marble::GeoDataFeature::detach
virtual void detach()
Definition: GeoDataFeature.cpp:734
Marble::GeoDataPolygonId
Definition: Serializable.h:45
Marble::InvalidGeometryId
Definition: Serializable.h:41
Marble::GeoDataPlacemarkPrivate::m_geometry
GeoDataGeometry * m_geometry
Definition: GeoDataPlacemark_p.h:100
Marble::GeoDataGeometry::geometryId
virtual EnumGeometryId geometryId() const
Definition: GeoDataGeometry.cpp:82
Marble::GeoDataPlacemark::setGeometry
void setGeometry(GeoDataGeometry *entry)
Sets the current Geometry of this Placemark.
Definition: GeoDataPlacemark.cpp:136
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal