Changes: added ut_gpscontroller
[ptas] / zouba / src / gpscontroller_p.cpp
1 #include "gpscontroller_p.h"
2
3 #include "location.h"
4
5 #include <QObject>
6 #include <QGeoPositionInfo>
7 #include <QGeoPositionInfoSource>
8 #include <QDebug>
9
10 QTM_USE_NAMESPACE
11
12 GpsControllerPrivate::GpsControllerPrivate() :
13   m_gps(0),
14   m_currentLocation(0),
15   m_useFakeLocation(false)
16 {
17 }
18
19 GpsControllerPrivate::~GpsControllerPrivate()
20 {
21   delete m_gps;
22   m_gps = 0;
23   delete m_currentLocation;
24   m_currentLocation = 0;
25 }
26
27 void GpsControllerPrivate::init()
28 {
29   m_gps = QGeoPositionInfoSource::createDefaultSource(this);
30   connect(
31       m_gps, SIGNAL( positionUpdated( QGeoPositionInfo ) ),
32       this, SLOT( updateLocation( QGeoPositionInfo ) )
33   );
34 }
35
36 void GpsControllerPrivate::startGps()
37 {
38   m_gps->startUpdates();
39 }
40
41 void GpsControllerPrivate::stopGps()
42 {
43   m_gps->stopUpdates();
44 }
45
46 QGeoPositionInfoSource *GpsControllerPrivate::gps()
47 {
48   return m_gps;
49 }
50
51 void GpsControllerPrivate::setGps( QGeoPositionInfoSource *gps )
52 {
53   m_gps = gps;
54 }
55
56 Location *GpsControllerPrivate::currentLocation()
57 {
58   return m_currentLocation;
59 }
60
61 void GpsControllerPrivate::setCurrentLocation( Location *location )
62 {
63   delete m_currentLocation;
64   m_currentLocation = location;
65 }
66
67 bool GpsControllerPrivate::useFakeLocation()
68 {
69   return m_useFakeLocation;
70 }
71
72 void GpsControllerPrivate::setUseFakeLocation( bool useFake )
73 {
74   m_useFakeLocation = useFake;
75 }
76
77 void GpsControllerPrivate::updateLocation( QGeoPositionInfo positionInfo )
78 {
79   if ( !m_useFakeLocation ) {
80     delete m_currentLocation;
81     m_currentLocation = new Location( positionInfo );
82   }
83 }
84