3ca884713e7b11e86bfa4ed7df6c67cd8dfeb914
[ptas] / zouba / src / gpscontroller.cpp
1 #include "gpscontroller.h"
2
3 #include <QObject>
4 #include <QGeoPositionInfo>
5 #include <QGeoPositionInfoSource>
6 #include <QDebug>
7
8 QTM_USE_NAMESPACE
9
10 GpsController::GpsController() :
11   m_location( QGeoPositionInfoSource::createDefaultSource(this) ),
12   m_currentLocation(0),
13   m_useFakeLocation(false)
14 {
15   connect( 
16       m_location, SIGNAL( positionUpdated( QGeoPositionInfo ) ),
17       this, SLOT( updateLocation( QGeoPositionInfo ) )
18   );
19
20   m_location->startUpdates();
21 }
22
23 GpsController::~GpsController()
24 {
25   delete m_location;
26   m_location = 0;
27   delete m_currentLocation;
28   m_currentLocation = 0;
29 }
30
31 void GpsController::updateLocation( QGeoPositionInfo positionInfo )
32 {
33   delete m_currentLocation;
34   m_currentLocation = new Location( positionInfo );
35 }
36
37 void GpsController::getGps()
38 {
39   if ( m_currentLocation != 0 ) {
40     emit locationChanged( m_currentLocation );
41   }
42 }
43
44 void GpsController::useLiveGps()
45 {
46   m_location->startUpdates();
47   m_useFakeLocation=false;
48   m_currentLocation=0;
49 }
50
51 void GpsController::useFakeGps( Location *fakeLocation )
52 {
53   m_location->stopUpdates();
54   m_useFakeLocation=true;
55   delete m_currentLocation;
56   m_currentLocation = new Location( *fakeLocation );
57   emit locationChanged( m_currentLocation );
58 }