Modified GPS & map related signals and slots
authorSami Rämö <sami.ramo@ixonos.com>
Fri, 14 May 2010 12:42:02 +0000 (15:42 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Fri, 14 May 2010 12:42:02 +0000 (15:42 +0300)
 - Also added some more logic to GPSLocationItem

12 files changed:
images.qrc
src/gps/gpscommon.h [new file with mode: 0644]
src/gps/gpsposition.cpp
src/gps/gpsposition.h
src/map/gpslocationitem.cpp
src/map/gpslocationitem.h
src/map/mapengine.cpp
src/map/mapengine.h
src/src.pro
src/ui/mainwindow.cpp
src/ui/mapviewscreen.cpp
src/ui/mapviewscreen.h

index 2cbca22..1a8f687 100644 (file)
@@ -26,7 +26,6 @@
         <file>res/images/list_item_bottom.png</file>
         <file>res/images/list_item_middle.png</file>
         <file>res/images/list_item_top.png</file>
-        <file>res/dummy/nmealog.txt</file>
         <file>res/images/gps_pos_accurate.png</file>
         <file>res/images/gps_pos_coarse.png</file>
     </qresource>
diff --git a/src/gps/gpscommon.h b/src/gps/gpscommon.h
new file mode 100644 (file)
index 0000000..a7380cc
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Sami Rämö - sami.ramo@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+*/
+
+
+#ifndef GPSCOMMON_H
+#define GPSCOMMON_H
+
+const int GPS_ACCURACY_UNDEFINED = -1; ///< Value used when accuracy is undefined
+
+#endif // GPSCOMMON_H
index 676fda1..a89413a 100644 (file)
@@ -27,6 +27,7 @@
 #include <QDebug>
 #include <QTimer>
 
+#include "gpscommon.h"
 #include "gpsposition.h"
 #include "gpspositioninterface.h"
 
@@ -152,8 +153,8 @@ qreal GPSPosition::biggerAccuracy(QGeoPositionInfo positionInfo)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    qreal horizontalAccuracy = ACCURACY_UNDEFINED;
-    qreal verticalAccuracy = ACCURACY_UNDEFINED;
+    qreal horizontalAccuracy = GPS_ACCURACY_UNDEFINED;
+    qreal verticalAccuracy = GPS_ACCURACY_UNDEFINED;
 
     if (positionInfo.hasAttribute(QGeoPositionInfo::HorizontalAccuracy))
         horizontalAccuracy = positionInfo.attribute(QGeoPositionInfo::HorizontalAccuracy);
@@ -166,5 +167,9 @@ qreal GPSPosition::biggerAccuracy(QGeoPositionInfo positionInfo)
     if (horizontalAccuracy > accuracy)
         accuracy = horizontalAccuracy;
 
+    qWarning() << __PRETTY_FUNCTION__ << "accuracy, h:" << horizontalAccuracy
+                                      << "v:" << verticalAccuracy
+                                      << "return:" << accuracy;
+
     return accuracy;
 }
index c2fa7d4..fdb536a 100644 (file)
@@ -131,7 +131,6 @@ private:
     int m_updateInterval;                       ///< GPS update interval
 };
 
-const int ACCURACY_UNDEFINED = 1;               ///< Undefined accuracy
 const int DEFAULT_UPDATE_INTERVAL = 5000;       ///< Default update interval
 
 #endif // GPSPOSITION_H
index d5ebd8c..55019eb 100644 (file)
     USA.
 */
 
-const int ACCURATE_LIMIT = 10; // this and lower values (in meter) are considered as accurate
+const int ACCURATE_LIMIT = 250; // this and lower values (in meters) are considered as accurate
+
+#include <QDebug>
+#include <QGraphicsPixmapItem>
+
+#include "../gps/gpscommon.h"
+#include "mapcommon.h"
 
 #include "gpslocationitem.h"
 
-GPSLocationItem::GPSLocationItem(QObject *parent) :
-    QGraphicsPixmapItem(parent)
+GPSLocationItem::GPSLocationItem()
+    : m_currentAccuracy(NOT_SET)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    accuratePixmap = QPixmap(":/res/images/gps_pos_accurate.png");
-    coarsePixmap = QPixmap(":/res/images/gps_pos_coarse.png");
+    m_accuratePixmap = QPixmap(":/res/images/gps_pos_accurate.png");
+    m_coarsePixmap = QPixmap(":/res/images/gps_pos_coarse.png");
 
     setPos(QPoint(UNDEFINED, UNDEFINED));
     setZValue(OWN_LOCATION_ICON_Z_LEVEL);
-    setOffset(-accuratePixmap.width()/2, -accuratePixmap.height()/2);
+    setOffset(-m_accuratePixmap.width() / 2, -m_accuratePixmap.height() / 2);
+    setFlag(QGraphicsItem::ItemIgnoresTransformations);
 }
 
-GPSLocationItem::updatePosition(QPoint scenePosition, qreal accuracy)
+void GPSLocationItem::updatePosition(QPoint scenePosition, qreal accuracy)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     setPos(scenePosition);
 
-    /// @todo MAGIC NUMBER
-    if (accuracy != -1 && accuracy <= ACCURATE_LIMIT) {
-        setPixmap(accuratePixmap);
+    if (accuracy != GPS_ACCURACY_UNDEFINED  // accuracy must be defined
+        && accuracy <= ACCURATE_LIMIT       // and smaller than limit
+        && m_currentAccuracy != ACCURATE) { // and accurate pixmap not yet set
+            setPixmap(m_accuratePixmap);
+            m_currentAccuracy = ACCURATE;
     }
-    else {
-        setPixmap(coarsePixmap);
+    else if (m_currentAccuracy != COARSE) { // coarse pixmap not yet set
+        setPixmap(m_coarsePixmap);
+        m_currentAccuracy = COARSE;
     }
 }
index bf7660b..457d0ef 100644 (file)
 
 #include <QGraphicsPixmapItem>
 
+/**
+  * @brief Class for indicating current position accuired from GPS on the map.
+  *
+  * Also GPS fix accuracy is indicated by using two different color indicator images
+  * based on current accuracy
+  */
 class GPSLocationItem : public QGraphicsPixmapItem
 {
-    Q_OBJECT
 public:
-    explicit GPSLocationItem(QObject *parent = 0);
+    /**
+      * @brief Constructor
+      */
+    GPSLocationItem();
 
-public slots:
+public:
+    /**
+      * @brief Update position item
+      *
+      * @param scenePosition Scene coordinate
+      * @param accuracy Accuracy of the GPS fix
+      */
     void updatePosition(QPoint scenePosition, qreal accuracy);
 
 private:
-    QPixmap accuratePixmap;
-    QPixmap coarsePixmap;
+    /**
+      * @brief Enum for current pixmap state
+      */
+    enum Accuracy { NOT_SET, ACCURATE, COARSE };
+
+    QPixmap m_accuratePixmap; ///< pixmap used when GPS fix is accurate
+    QPixmap m_coarsePixmap; ///< pixmap used when GPS fix is coarse
+    Accuracy m_currentAccuracy; ///< current accuracy
 };
 
 #endif // GPSLOCATIONITEM_H
index 99cbf7b..afeee24 100644 (file)
@@ -153,7 +153,7 @@ void MapEngine::setLocation(QPoint sceneCoordinate)
     qDebug() << __PRETTY_FUNCTION__;
 
     if (disableAutoCentering(sceneCoordinate))
-        emit mapScrolled();
+        emit mapScrolledManually();
 
     m_sceneCoordinate = sceneCoordinate;
     emit locationChanged(m_sceneCoordinate);
index f4dccc0..aee3f7f 100644 (file)
@@ -107,13 +107,6 @@ public:
     QGraphicsScene* scene();
 
     /**
-    * @brief Set auto centering.
-    *
-    * @param enabled true if enabled, false otherwise
-    */
-    void setAutoCentering(bool enabled);
-
-    /**
     * @brief Return tile path created from tile values.
     *
     * @param zoomLevel tile's zoom level
@@ -221,6 +214,15 @@ private:
     void updateViewTilesSceneRect();
 
 private slots:
+    /**
+      * @brief Slot for GPS position updates
+      *
+      * GPS location item is updated and map centered to new location (if automatic
+      * centering is enabled).
+      *
+      * @param position New coordinates from GPS
+      * @param accuracy Accuracy of the GPS fix
+      */
     void gpsPositionUpdate(QPointF position, qreal accuracy);
 
     /**
@@ -235,6 +237,13 @@ private slots:
     void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
 
     /**
+    * @brief Set auto centering.
+    *
+    * @param enabled true if enabled, false otherwise
+    */
+    void setAutoCentering(bool enabled);
+
+    /**
     * @brief Slot for actions after view zoom is finished
     *
     * Does run removeOutOfViewTiles
@@ -283,7 +292,7 @@ signals:
     /**
     * @brief Signal to notify map scrolling.
     */
-    void mapScrolled();
+    void mapScrolledManually();
 
     /**
     * @brief Signal for zoom level change
@@ -299,7 +308,7 @@ private:
     bool m_autoCenteringEnabled;    ///< Auto centering enabled
     QPoint m_centerTile; ///< Current center tile
     FriendItemsHandler *m_friendItemsHandler; ///< Handler for friend and group items
-    GPSLocationItem *m_gpsLocationItem;
+    GPSLocationItem *m_gpsLocationItem; ///< Item pointing current location from GPS
     QPoint m_lastManualPosition;  ///< Last manually set position in scene coordinate
     MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
     MapScene *m_mapScene; ///< Scene for map tiles
index 66db2e5..6fdae18 100644 (file)
@@ -81,7 +81,8 @@ HEADERS += ui/mainwindow.h \
     map/frienditemshandler.h \
     gps/gpspositioninterface.h \
     map/gpslocationitem.h \
-    situarecommon.h
+    situarecommon.h \
+    gps/gpscommon.h
 QT += network \
     webkit
 DEFINES += QT_NO_DEBUG_OUTPUT
index 5f02de0..4e61a88 100644 (file)
@@ -66,9 +66,9 @@ MainWindow::MainWindow(QWidget *parent)
             m_mapViewScreen, SIGNAL(friendsLocationsReady(QList<User*>&)));
 
        connect(this, SIGNAL(autoCentering(bool)),
-            m_mapViewScreen, SLOT(enableAutoCentering(bool)));
+            m_mapViewScreen, SIGNAL(enableAutoCentering(bool)));
     connect(this, SIGNAL(positionReceived(QPointF, qreal)),
-            m_mapViewScreen, SLOT(positionReceived(QPointF, qreal)));
+            m_mapViewScreen, SIGNAL(positionReceived(QPointF, qreal)));
     connect(m_mapViewScreen, SIGNAL(mapLocationChanged()), this, SLOT(mapLocationChanged()));
 
     connect(this, SIGNAL(zoomInKeyPressed()),
index 3f0eeee..8e16f44 100644 (file)
@@ -29,8 +29,7 @@
 #include "panelsidebar.h"
 
 MapViewScreen::MapViewScreen(QWidget *parent)
-   : QWidget(parent),
-     m_autoCenteringEnabled(false)
+   : QWidget(parent)
 {
     MapView *mapView = new MapView(this);
     mapEngine = new MapEngine(this);
@@ -79,7 +78,13 @@ MapViewScreen::MapViewScreen(QWidget *parent)
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
 
-    connect(mapEngine, SIGNAL(mapScrolled()), this, SLOT(locationChanged()));
+    connect(mapEngine, SIGNAL(mapScrolledManually()),
+            this, SIGNAL(mapLocationChanged()));
+
+    connect(this, SIGNAL(positionReceived(QPointF,qreal)),
+            mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
+    connect(this, SIGNAL(enableAutoCentering(bool)),
+            mapEngine, SLOT(setAutoCentering(bool)));
 
     QHBoxLayout *mapViewLayout = new QHBoxLayout;
 
@@ -113,27 +118,3 @@ void MapViewScreen::drawOsmLicense(int width, int height)
     osmLicense->move(width - osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
                      height - osmLicense->fontMetrics().height());
 }
-
-void MapViewScreen::locationChanged()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if (m_autoCenteringEnabled)
-        emit mapLocationChanged();
-}
-
-void MapViewScreen::positionReceived(QPointF position, qreal accuracy)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if (m_autoCenteringEnabled)
-        mapEngine->setViewLocation(position);
-}
-
-void MapViewScreen::enableAutoCentering(bool enabled)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_autoCenteringEnabled = enabled;
-    mapEngine->setAutoCentering(enabled);
-}
index d9a3de9..aff0b5e 100644 (file)
@@ -31,8 +31,6 @@
 
 /**
 * @brief Map View class. Used to display Map
-*
-* @class MapViewScreen mainwindow.h "src/ui/mainwindow.h"
 */
 class MapViewScreen : public QWidget
 {
@@ -50,14 +48,6 @@ public:
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
 private slots:
-
-    /**
-    * @brief Slot for enabling auto centering.
-    *
-    * @param enabled true if map should center to GPS position, false otherwise
-    */
-    void enableAutoCentering(bool enabled);
-
     /**
     * @brief Slot for drawing the Open Street Map license text
     *
@@ -66,24 +56,18 @@ private slots:
     */
     void drawOsmLicense(int width, int height);
 
-    /**
-    * @brief Slot for map location change.
-    */
-    void locationChanged();
-
-    /**
-    * @brief Slot for GPS position.
-    *
-    * @param position latitude and longitude values
-    * @param accuracy coordinate accuracy in metres
-    */
-    void positionReceived(QPointF position, qreal accuracy);
-
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
 signals:
     /**
+    * @brief Signal for enabling auto centering.
+    *
+    * @param enabled true if map should center to GPS position, false otherwise
+    */
+    void enableAutoCentering(bool enabled);
+
+    /**
     * @brief Signal when friend list locations are fetched
     *
     * Forwarded to map engine and friends list panel
@@ -95,7 +79,15 @@ signals:
        /**
     * @brief Signal for map location change.
     */
-    void mapLocationChanged();  
+    void mapLocationChanged();
+
+    /**
+    * @brief Slot for GPS position.
+    *
+    * @param position latitude and longitude values
+    * @param accuracy coordinate accuracy in metres
+    */
+    void positionReceived(QPointF position, qreal accuracy);
 
     /**
     * @brief Signal when user location is fetched
@@ -118,7 +110,6 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    bool m_autoCenteringEnabled;        ///< Enable
     FriendListPanel *friendsListPanel; ///< Instance of friends list panel
     MapEngine *mapEngine; ///< MapEngine
     QLabel *osmLicense; ///< Label for Open Street Map license