Added functionality to get the latest own location from handset values
authorlampehe-local <henri.lampela@ixonos.com>
Mon, 17 May 2010 11:21:07 +0000 (14:21 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Mon, 17 May 2010 11:21:07 +0000 (14:21 +0300)
or from GPS

src/engine/engine.cpp
src/engine/engine.h
src/ui/mainwindow.cpp

index 83c1834..f6ce461 100644 (file)
@@ -38,7 +38,8 @@ const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";
 SituareEngine::SituareEngine(QMainWindow *parent)
     : QObject(parent),
       m_autoCenteringEnabled(false),
-      m_gpsEnabled(false)
+      m_gpsEnabled(false),
+      m_latestLocation()
 {
     qDebug() << __PRETTY_FUNCTION__;
     m_ui = new MainWindow;
@@ -106,7 +107,7 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     enableGPS(gpsEnabled.toBool());
     enableAutoCentering(autoCenteringEnabled.toBool());
 
-connect(this, SIGNAL(requestOwnLocation()),
+    connect(this, SIGNAL(requestOwnLocation()),
             m_ui, SIGNAL(requestOwnLocation()));
     connect(m_ui, SIGNAL(ownLocation(QPointF)),
             this, SLOT(receiveOwnLocation(QPointF)));
@@ -154,14 +155,14 @@ void SituareEngine::requestAddress()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QPointF coordinates;
-
-    if (m_gpsEnabled)
-        coordinates = m_gps->lastPosition();
-    else
-        coordinates = QPointF(0, 0);    //Manual position from map
-
-    m_situareService->reverseGeo(coordinates);
+    if (m_gpsEnabled) {
+        m_latestLocation = m_gps->lastPosition();
+        m_situareService->reverseGeo(m_latestLocation);
+    }
+    else {
+        emit requestOwnLocation();
+        m_situareService->reverseGeo(m_latestLocation);
+    }
 }
 
 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
@@ -170,14 +171,14 @@ void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
 
     m_ui->toggleProgressIndicator(true);
 
-    QPointF coordinates;
-
-    if (m_gpsEnabled)
-        coordinates = m_gps->lastPosition();
-    else
-        coordinates = QPointF(0, 0);    //Manual position from map
-
-    m_situareService->updateLocation(coordinates, status, publish);
+    if (m_gpsEnabled) {
+        m_latestLocation = m_gps->lastPosition();
+        m_situareService->updateLocation(m_latestLocation, status, publish);
+    }
+    else {
+        emit requestOwnLocation();
+        m_situareService->updateLocation(m_latestLocation, status, publish);
+    }
 }
 
 void SituareEngine::updateWasSuccessful()
@@ -245,4 +246,5 @@ void SituareEngine::receiveOwnLocation(QPointF ownLocation)
 {
     qWarning() << __PRETTY_FUNCTION__;
     qWarning() << ownLocation.x() << "  " << ownLocation.y();
+    m_latestLocation = ownLocation;
 }
index 58ff600..0d77f77 100644 (file)
@@ -161,6 +161,7 @@ private:
     GPSPositionInterface *m_gps;   ///< Instance of the gps position
     MainWindow *m_ui; ///< Instance of the MainWindow UI
     SituareService *m_situareService; ///< Instance of the situare server communication service
+    QPointF m_latestLocation; ///< Placeholder for user's latest asked location
 };
 
 #endif // ENGINE_H
index fb20774..f1063bc 100644 (file)
@@ -51,7 +51,7 @@ MainWindow::MainWindow(QWidget *parent)
     setCentralWidget(m_mapViewScreen);
     createMenus();
     setWindowTitle(tr("Situare"));
-       show();
+    show();
 
     m_locationDialog = new UpdateLocationDialog(this);
 
@@ -77,7 +77,7 @@ MainWindow::MainWindow(QWidget *parent)
     connect(this, SIGNAL(zoomOutKeyPressed()),
             m_mapViewScreen, SIGNAL(zoomOutKeyPressed()));
 
-connect(this, SIGNAL(requestOwnLocation()),
+    connect(this, SIGNAL(requestOwnLocation()),
             m_mapViewScreen, SIGNAL(requestOwnLocation()));
     connect(m_mapViewScreen, SIGNAL(ownLocation(QPointF)),
             this, SIGNAL(ownLocation(QPointF)));
@@ -120,18 +120,18 @@ void MainWindow::createMenus()
     m_gpsToggleAct->setChecked(true);
     connect(m_gpsToggleAct, SIGNAL(toggled(bool)),
         this, SLOT(gpsToggled(bool)));
-connect(m_gpsToggleAct, SIGNAL(toggled(bool)),
-            m_mapViewScreen, SLOT(setOwnLocationCrosshairVisibility(bool)));
+    connect(m_gpsToggleAct, SIGNAL(toggled(bool)),
+    m_mapViewScreen, SLOT(setOwnLocationCrosshairVisibility(bool)));
     m_autoCenteringAct = new QAction(tr("Auto centering"), this);
     m_autoCenteringAct->setCheckable(true);
     m_autoCenteringAct->setChecked(true);
     connect(m_autoCenteringAct, SIGNAL(toggled(bool)),
         this, SLOT(autoCenteringToggled(bool)));    
        
-       m_viewMenu = menuBar()->addMenu(tr("Main"));
+    m_viewMenu = menuBar()->addMenu(tr("Main"));
 
     m_viewMenu->addAction(m_toSettingsAct);
-       m_viewMenu->addAction(m_gpsToggleAct);
+    m_viewMenu->addAction(m_gpsToggleAct);
     m_viewMenu->addAction(m_autoCenteringAct);
     m_viewMenu->setObjectName(tr("Menu"));
 }