Marble

PlacemarkPositionProviderPlugin.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2011 Guillaume Martres <smarter@ubuntu.com>
4// SPDX-FileCopyrightText: 2011, 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
5//
6
7#include "PlacemarkPositionProviderPlugin.h"
8
9#include "GeoDataPlacemark.h"
10#include "MarbleClock.h"
11#include "MarbleModel.h"
12#include "MarbleDebug.h"
13
14#include <QIcon>
15
16using namespace Marble;
17
18PlacemarkPositionProviderPlugin::PlacemarkPositionProviderPlugin( MarbleModel *marbleModel, QObject* parent )
19 : PositionProviderPlugin(parent),
20 m_marbleModel( marbleModel ),
21 m_placemark( nullptr ),
22 m_speed( 0 ),
23 m_direction( 0.0 ),
24 m_status( PositionProviderStatusUnavailable ),
25 m_isInitialized( false )
26{
27 m_accuracy.level = GeoDataAccuracy::Detailed;
28}
29
30QString PlacemarkPositionProviderPlugin::name() const
31{
32 return tr( "Placemark position provider Plugin" );
33}
34
35QString PlacemarkPositionProviderPlugin::nameId() const
36{
37 return QStringLiteral("Placemark");
38}
39
40QString PlacemarkPositionProviderPlugin::guiString() const
41{
42 return tr( "Placemark" );
43}
44
45QString PlacemarkPositionProviderPlugin::version() const
46{
47 return QStringLiteral("1.0");
48}
49
50QString PlacemarkPositionProviderPlugin::description() const
51{
52 return tr( "Reports the position of a placemark" );
53}
54
55QString PlacemarkPositionProviderPlugin::copyrightYears() const
56{
57 return QStringLiteral("2011, 2012");
58}
59
60QVector<PluginAuthor> PlacemarkPositionProviderPlugin::pluginAuthors() const
61{
63 << PluginAuthor(QStringLiteral("Guillaume Martres"), QStringLiteral("smarter@ubuntu.com"))
64 << PluginAuthor(QStringLiteral("Bernhard Beschow"), QStringLiteral("bbeschow@cs.tu-berlin.de"));
65}
66
67QIcon PlacemarkPositionProviderPlugin::icon() const
68{
69 return QIcon();
70}
71
72void PlacemarkPositionProviderPlugin::initialize()
73{
74 if ( m_marbleModel ) {
75 setPlacemark( m_marbleModel->trackedPlacemark() );
76 connect( m_marbleModel, SIGNAL(trackedPlacemarkChanged(const GeoDataPlacemark*)),
77 this, SLOT(setPlacemark(const GeoDataPlacemark*)) );
78 } else {
79 mDebug() << "PlacemarkPositionProviderPlugin: MarbleModel not set, cannot track placemarks.";
80 }
81 m_isInitialized = true;
82}
83
84bool PlacemarkPositionProviderPlugin::isInitialized() const
85{
86 return m_isInitialized;
87}
88
89PositionProviderPlugin* PlacemarkPositionProviderPlugin::newInstance() const
90{
91 return new PlacemarkPositionProviderPlugin( m_marbleModel );
92}
93
94PositionProviderStatus PlacemarkPositionProviderPlugin::status() const
95{
96 return m_status;
97}
98
99GeoDataCoordinates PlacemarkPositionProviderPlugin::position() const
100{
101 return m_coordinates;
102}
103
104GeoDataAccuracy PlacemarkPositionProviderPlugin::accuracy() const
105{
106 return m_accuracy;
107}
108
109qreal PlacemarkPositionProviderPlugin::speed() const
110{
111 return m_speed;
112}
113
114qreal PlacemarkPositionProviderPlugin::direction() const
115{
116 return m_direction;
117}
118
119QDateTime PlacemarkPositionProviderPlugin::timestamp() const
120{
121 return m_marbleModel->clockDateTime();
122}
123
124void PlacemarkPositionProviderPlugin::setPlacemark( const GeoDataPlacemark *placemark )
125{
126 const GeoDataPlacemark *const oldPlacemark = m_placemark;
127
128 if ( oldPlacemark != nullptr ) {
129 emit statusChanged( PositionProviderStatusUnavailable );
130 }
131
132 m_placemark = placemark;
133 m_timestamp = placemark ? m_marbleModel->clockDateTime() : QDateTime();
134 GeoDataCoordinates const newCoordinates = placemark ? placemark->coordinate( m_timestamp ) : GeoDataCoordinates();
135 if ( m_coordinates.isValid() && newCoordinates.isValid() ) {
136 m_direction = m_coordinates.bearing( newCoordinates, GeoDataCoordinates::Degree, GeoDataCoordinates::FinalBearing );
137 }
138 m_coordinates = newCoordinates;
139 m_status = placemark ? PositionProviderStatusAvailable : PositionProviderStatusUnavailable;
140 m_speed = 0.0;
141
142 disconnect( m_marbleModel->clock(), SIGNAL(timeChanged()), this, SLOT(updatePosition()) );
143 if ( placemark ) {
144 connect( m_marbleModel->clock(), SIGNAL(timeChanged()), this, SLOT(updatePosition()) );
145 }
146
147 if ( oldPlacemark != m_placemark && m_placemark != nullptr ) {
148 emit statusChanged( m_status );
149 }
150
151 if ( m_status == PositionProviderStatusAvailable ) {
152 emit positionChanged( m_coordinates, m_accuracy );
153 }
154}
155
156void PlacemarkPositionProviderPlugin::updatePosition()
157{
158 if ( m_placemark == nullptr ) {
159 return;
160 }
161
162 Q_ASSERT( m_marbleModel && "MarbleModel missing in PlacemarkPositionProviderPlugin" );
163
164 const GeoDataCoordinates previousCoordinates = m_coordinates;
165 m_coordinates = m_placemark->coordinate( m_marbleModel->clock()->dateTime() );
166 m_direction = previousCoordinates.bearing( m_coordinates, GeoDataCoordinates::Degree, GeoDataCoordinates::FinalBearing );
167
168 if ( m_timestamp.isValid() ) {
169 const qreal averageAltitude = ( m_coordinates.altitude() + m_coordinates.altitude() ) / 2.0 + m_marbleModel->planetRadius();
170 const qreal distance = previousCoordinates.sphericalDistanceTo(m_coordinates) * averageAltitude;
171 const qreal seconds = m_timestamp.msecsTo( m_marbleModel->clockDateTime() ) / 1000.0;
172 m_speed = ( seconds > 0 ) ? ( distance / seconds ) : 0;
173 }
174 else {
175 m_speed = 0;
176 }
177
178 m_timestamp = m_marbleModel->clockDateTime();
179
180 emit positionChanged( m_coordinates, m_accuracy );
181}
182
183#include "moc_PlacemarkPositionProviderPlugin.cpp"
This file contains the headers for MarbleModel.
A 3d point representation.
qreal bearing(const GeoDataCoordinates &other, Unit unit=Radian, BearingType type=InitialBearing) const
Returns the bearing (true bearing, the angle between the line defined by this point and the other and...
qreal altitude() const
return the altitude of the Point in meters
a class representing a point of interest on the map
GeoDataCoordinates coordinate(const QDateTime &dateTime=QDateTime(), bool *iconAtCoordinates=nullptr) const
Return the coordinates of the placemark at time dateTime as a GeoDataCoordinates.
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition MarbleModel.h:87
const GeoDataPlacemark * trackedPlacemark() const
Returns the placemark being tracked by this model or 0 if no placemark is currently tracked.
The abstract class that provides position information.
Binds a QML item to a specific geodetic location in screen coordinates.
KOSM_EXPORT double distance(const std::vector< const OSM::Node * > &path, Coordinate coord)
bool isValid() const const
qint64 msecsTo(const QDateTime &other) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
T qobject_cast(QObject *object)
QString tr(const char *sourceText, const char *disambiguation, int n)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.