Incorporated changes from bus project.
[ptas] / src / gpscontroller_p.cpp
index 41086b0..bdea8e3 100644 (file)
 QTM_USE_NAMESPACE
 
 GpsControllerPrivate::GpsControllerPrivate() :
-  m_gps(0),
-  m_liveLocation( new Location( "livegps" ) ),
-  m_fakeLocationLabel(),
-  m_useFakeLocation(false)
+    m_gps(0),
+    m_liveLocation(new Location("livegps")),
+    m_fakeLocationLabel(),
+    m_useFakeLocation(false)
 {
 }
 
 GpsControllerPrivate::~GpsControllerPrivate()
 {
-  delete m_gps;
-  m_gps = 0;
-  delete m_liveLocation;
-  m_liveLocation = 0;
+    delete m_gps;
+    m_gps = 0;
+    delete m_liveLocation;
+    m_liveLocation = 0;
 }
 
 void GpsControllerPrivate::init()
 {
-  m_gps = QGeoPositionInfoSource::createDefaultSource(this);
-  connect(
-      m_gps, SIGNAL( positionUpdated( QGeoPositionInfo ) ),
-      this, SLOT( updateLocation( QGeoPositionInfo ) )
-  );
+    m_gps = QGeoPositionInfoSource::createDefaultSource(this);
+    connect(
+                m_gps, SIGNAL(positionUpdated(QGeoPositionInfo)),
+                this, SLOT(updateLocation(QGeoPositionInfo))
+                );
 }
 
 void GpsControllerPrivate::startGps()
 {
-  m_gps->startUpdates();
+    m_gps->startUpdates();
 }
 
 void GpsControllerPrivate::stopGps()
 {
-  m_gps->stopUpdates();
+    m_gps->stopUpdates();
 }
 
 QGeoPositionInfoSource *GpsControllerPrivate::gps()
 {
-  return m_gps;
+    return m_gps;
 }
 
-void GpsControllerPrivate::setGps( QGeoPositionInfoSource *gps )
+void GpsControllerPrivate::setGps(QGeoPositionInfoSource *gps)
 {
-  m_gps = gps;
+    m_gps = gps;
 }
 
 Location *GpsControllerPrivate::liveLocation()
 {
-  m_mostRecentlyReportedLocation = m_liveLocation;
-  return m_liveLocation;
+    m_mostRecentlyReportedLocation = m_liveLocation;
+    return m_liveLocation;
 }
 
 Location *GpsControllerPrivate::fakeLocation()
 {
-  Locations locations;
-  Location  *location = locations.location( fakeLocationLabel() );
-  m_mostRecentlyReportedLocation = location;
-  return location;
+    Locations locations;
+    Location  *location = locations.location(fakeLocationLabel());
+    m_mostRecentlyReportedLocation = location;
+    return location;
 }
 
 QString GpsControllerPrivate::fakeLocationLabel()
 {
-  return m_fakeLocationLabel;
+    return m_fakeLocationLabel;
 }
 
-void GpsControllerPrivate::setFakeLocationLabel( const QString &label )
+void GpsControllerPrivate::setFakeLocationLabel(const QString &label)
 {
-  m_fakeLocationLabel = label;
+    m_fakeLocationLabel = label;
 }
 
 bool GpsControllerPrivate::useFakeLocation()
 {
-  return m_useFakeLocation;
+    return m_useFakeLocation;
 }
 
-void GpsControllerPrivate::setUseFakeLocation( bool useFake )
+void GpsControllerPrivate::setUseFakeLocation(bool useFake)
 {
-  m_useFakeLocation = useFake;
+    m_useFakeLocation = useFake;
 }
 
-void GpsControllerPrivate::updateLocation( QGeoPositionInfo positionInfo )
+void GpsControllerPrivate::updateLocation(QGeoPositionInfo positionInfo)
 {
-  m_liveLocation->setLocation( positionInfo );
+    qDebug() << Q_FUNC_INFO;
+    bool wasInvalid = !m_liveLocation->isValid();
+    qDebug() << "wasInvalid/" << wasInvalid;
+
+    m_liveLocation->setLocation(positionInfo);
+    if (wasInvalid) {
+        emit locationChanged(m_liveLocation);
+    }
 }
 
 Location *GpsControllerPrivate::mostRecentlyReportedLocation()
 {
-  return m_mostRecentlyReportedLocation;
+    return m_mostRecentlyReportedLocation;
 }