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

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • plugins
  • declarative
PositionSource.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 2011 Dennis Nienhüser <earthwings@gentoo.org>
9 // Copyright 2011 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
10 //
11 
12 #include "PositionSource.h"
13 
14 #include "MarbleDeclarativeWidget.h"
15 #include "MarbleModel.h"
16 #include "PluginManager.h"
17 #include "PositionTracking.h"
18 #include "PositionProviderPlugin.h"
19 
20 PositionSource::PositionSource( QObject* parent) : QObject( parent ),
21  m_active( false ),
22  m_hasPosition( false ),
23  m_position( 0 ),
24  m_marbleWidget( 0 ),
25  m_speed( 0.0 )
26 {
27  // nothing to do
28 }
29 
30 bool PositionSource::active() const
31 {
32  return m_active;
33 }
34 
35 void PositionSource::setActive( bool active )
36 {
37  if ( active != m_active ) {
38  if ( active ) {
39  start();
40  } else if ( m_marbleWidget ) {
41  Marble::PositionTracking *tracking = m_marbleWidget->model()->positionTracking();
42  tracking->setPositionProviderPlugin( 0 );
43  }
44 
45  if ( m_hasPosition ) {
46  m_hasPosition = false;
47  emit hasPositionChanged();
48  }
49 
50  m_active = active;
51  emit activeChanged();
52  }
53 }
54 
55 QString PositionSource::source() const
56 {
57  return m_source;
58 }
59 
60 void PositionSource::setSource( const QString &source )
61 {
62  if ( source != m_source ) {
63  m_source = source;
64  if ( m_hasPosition ) {
65  m_hasPosition = false;
66  emit hasPositionChanged();
67  }
68 
69  if ( active() ) {
70  start();
71  }
72  emit sourceChanged();
73  }
74 }
75 
76 bool PositionSource::hasPosition() const
77 {
78  return m_hasPosition;
79 }
80 
81 Coordinate* PositionSource::position()
82 {
83  return &m_position;
84 }
85 
86 void PositionSource::start()
87 {
88  if ( !m_marbleWidget ) {
89  return;
90  }
91 
92  const Marble::PluginManager* pluginManager = m_marbleWidget->model()->pluginManager();
93  foreach( const Marble::PositionProviderPlugin *plugin, pluginManager->positionProviderPlugins() ) {
94  if ( m_source.isEmpty() || plugin->nameId() == m_source ) {
95  Marble::PositionProviderPlugin* instance = plugin->newInstance();
96  instance->setMarbleModel( m_marbleWidget->model() );
97  Marble::PositionTracking *tracking = m_marbleWidget->model()->positionTracking();
98  tracking->setPositionProviderPlugin( instance );
99  break;
100  }
101  }
102 }
103 
104 MarbleWidget *PositionSource::map()
105 {
106  return m_marbleWidget;
107 }
108 
109 void PositionSource::setMap( MarbleWidget *map )
110 {
111  if ( map != m_marbleWidget ) {
112  m_marbleWidget = map;
113 
114  if ( m_marbleWidget ) {
115  connect( m_marbleWidget->model()->positionTracking(), SIGNAL(gpsLocation(GeoDataCoordinates,qreal)),
116  this, SLOT(updatePosition()) );
117  connect( m_marbleWidget->model()->positionTracking(), SIGNAL(statusChanged(PositionProviderStatus)),
118  this, SLOT(updatePosition()) );
119 
120  emit mapChanged();
121  }
122 
123  if ( active() ) {
124  start();
125  }
126  }
127 }
128 
129 qreal PositionSource::speed() const
130 {
131  return m_speed;
132 }
133 
134 void PositionSource::updatePosition()
135 {
136  if ( m_marbleWidget ) {
137  bool const hasPosition = m_marbleWidget->model()->positionTracking()->status() == Marble::PositionProviderStatusAvailable;
138 
139  if ( hasPosition ) {
140  Marble::GeoDataCoordinates position = m_marbleWidget->model()->positionTracking()->currentLocation();
141  m_position.setLongitude( position.longitude( Marble::GeoDataCoordinates::Degree ) );
142  m_position.setLatitude( position.latitude( Marble::GeoDataCoordinates::Degree ) );
143  m_position.setAltitude( position.altitude() );
144  }
145 
146  m_speed = m_marbleWidget->model()->positionTracking()->speed() * Marble::METER2KM / Marble::SEC2HOUR;
147  emit speedChanged();
148 
149  if ( hasPosition != m_hasPosition ) {
150  m_hasPosition = hasPosition;
151  emit hasPositionChanged();
152  }
153 
154  if ( hasPosition ) {
155  emit positionChanged();
156  }
157  }
158 }
159 
160 #include "PositionSource.moc"
PositionSource.h
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
PositionSource::source
QString source() const
Marble::PluginManager
The class that handles Marble's plugins.
Definition: PluginManager.h:45
tracking
Definition: position-tracking.qml:12
PositionProviderPlugin.h
PositionSource::hasPosition
bool hasPosition() const
MarbleDeclarativeWidget.h
PositionSource::activeChanged
void activeChanged()
MarbleModel.h
This file contains the headers for MarbleModel.
Marble::PluginManager::positionProviderPlugins
QList< const PositionProviderPlugin * > positionProviderPlugins() const
Returns all available PositionProviderPlugins.
Definition: PluginManager.cpp:84
PositionSource::map
MarbleWidget * map()
Marble::GeoDataCoordinates::latitude
qreal latitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
Definition: GeoDataCoordinates.cpp:751
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Coordinate
Represents a coordinate with the properties of a name and coordinates.
Definition: Coordinate.h:28
Marble::PositionProviderPlugin
The abstract class that provides position information.
Definition: PositionProviderPlugin.h:26
Marble::PositionTracking
Definition: PositionTracking.h:31
Marble::GeoDataCoordinates::altitude
qreal altitude() const
return the altitude of the Point in meters
Definition: GeoDataCoordinates.cpp:1197
PositionSource::position
Coordinate * position()
PositionSource::setMap
void setMap(MarbleWidget *map)
Definition: PositionSource.cpp:109
Marble::PositionProviderPlugin::setMarbleModel
void setMarbleModel(const MarbleModel *)
Definition: PositionProviderPlugin.cpp:42
QObject
QString::isEmpty
bool isEmpty() const
QString
PositionSource::PositionSource
PositionSource(QObject *parent=0)
Definition: PositionSource.cpp:20
Marble::METER2KM
const qreal METER2KM
Definition: MarbleGlobal.h:224
Marble::PluginInterface::nameId
virtual QString nameId() const =0
Returns the unique name of the plugin.
Marble::PositionProviderStatus
PositionProviderStatus
Definition: PositionProviderPluginInterface.h:25
Marble::GeoDataCoordinates::longitude
qreal longitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
Definition: GeoDataCoordinates.cpp:739
PositionSource::hasPositionChanged
void hasPositionChanged()
PositionSource::setSource
void setSource(const QString &source)
Definition: PositionSource.cpp:60
PositionSource::positionChanged
void positionChanged()
PositionSource::active
bool active() const
Coordinate::setLatitude
void setLatitude(qreal lat)
Change the latitude of the coordinate.
Definition: Coordinate.cpp:43
PluginManager.h
Marble::SEC2HOUR
const qreal SEC2HOUR
Definition: MarbleGlobal.h:236
Coordinate::setAltitude
void setAltitude(qreal alt)
Change the altitude of the coordinate.
Definition: Coordinate.cpp:54
PositionSource::speed
qreal speed() const
PositionSource::mapChanged
void mapChanged()
Marble::PositionProviderPlugin::newInstance
virtual PositionProviderPlugin * newInstance() const =0
Create a new PositionProvider Plugin and return it.
Marble::PositionProviderStatusAvailable
Definition: PositionProviderPluginInterface.h:29
Coordinate::setLongitude
void setLongitude(qreal lon)
Change the longitude of the coordinate.
Definition: Coordinate.cpp:32
Marble::PositionTracking::setPositionProviderPlugin
void setPositionProviderPlugin(PositionProviderPlugin *plugin)
Change the position provider to use.
Definition: PositionTracking.cpp:184
MarbleWidget
Wraps a Marble::MarbleWidget, providing access to important properties and methods.
Definition: MarbleDeclarativeWidget.h:50
PositionTracking.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
PositionSource::setActive
void setActive(bool active)
Definition: PositionSource.cpp:35
PositionSource::speedChanged
void speedChanged()
PositionSource::sourceChanged
void sourceChanged()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:41 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
  • 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