small updates to own location feature
authorVille Tiensuu <ville.tiensuu@ixonos.com>
Thu, 29 Apr 2010 08:50:52 +0000 (11:50 +0300)
committerVille Tiensuu <ville.tiensuu@ixonos.com>
Thu, 29 Apr 2010 08:50:52 +0000 (11:50 +0300)
src/map/ownlocationitem.cpp
src/map/ownlocationitem.h
tests/map/ownlocationitem/ownlocationitem.pro
tests/map/ownlocationitem/testownlocationitem.cpp

index ef3d5ef..1b4dcbf 100644 (file)
@@ -30,15 +30,19 @@ OwnLocationItem::OwnLocationItem()
     qDebug() << __PRETTY_FUNCTION__;
 
     QPixmap ownLocationIcon(":/res/images/led_red_h.png");
-    setPixmap(ownLocationIcon);
+    if (!ownLocationIcon.isNull()){
+        setPixmap(ownLocationIcon);
 
-    QPointF defaultLocation(DEFAULT_LONGITUDE,DEFAULT_LATITUDE);
-    //QPoint position = MapEngine::convertLatLonToSceneCoordinate(home);
+        QPointF defaultLocation(DEFAULT_LONGITUDE,DEFAULT_LATITUDE);
 
-    setPos(MapEngine::convertLatLonToSceneCoordinate(defaultLocation));
-    setZValue(OWN_LOCATION_ICON_Z_LEVEL);
-    setOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
-    setFlag(QGraphicsItem::ItemIgnoresTransformations);
+        setPos(MapEngine::convertLatLonToSceneCoordinate(defaultLocation));
+        setZValue(OWN_LOCATION_ICON_Z_LEVEL);
+        setOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
+        setFlag(QGraphicsItem::ItemIgnoresTransformations);
+    }
+
+    else
+        qDebug() << "Own Location Icon cannot be loaded";
 }
 
 OwnLocationItem::OwnLocationItem(const qreal &longitude, const qreal &latitude)
@@ -46,23 +50,33 @@ OwnLocationItem::OwnLocationItem(const qreal &longitude, const qreal &latitude)
     QPointF ownPosition(longitude,latitude);
 
     QPixmap ownLocationIcon(":/res/images/led_red_h.png");
-    setPixmap(ownLocationIcon);
+    if (!ownLocationIcon.isNull()){
+        setPixmap(ownLocationIcon);
+
+        setPos(MapEngine::convertLatLonToSceneCoordinate(ownPosition));
+        setZValue(OWN_LOCATION_ICON_Z_LEVEL);
+        setOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
+        setFlag(QGraphicsItem::ItemIgnoresTransformations);
+    }
 
-    setPos(MapEngine::convertLatLonToSceneCoordinate(ownPosition));
-    setZValue(OWN_LOCATION_ICON_Z_LEVEL);
-    setOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
-    setFlag(QGraphicsItem::ItemIgnoresTransformations);
+    else
+        qDebug() << "Own Location Icon cannot be loaded";
 }
 
 OwnLocationItem::OwnLocationItem(const QPointF & ownPosition)
 {
     QPixmap ownLocationIcon(":/res/images/led_red_h.png");
-    setPixmap(ownLocationIcon);
+    if (!ownLocationIcon.isNull()){
+        setPixmap(ownLocationIcon);
+
+        setPos(MapEngine::convertLatLonToSceneCoordinate(ownPosition));
+        setZValue(OWN_LOCATION_ICON_Z_LEVEL);
+        setOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
+        setFlag(QGraphicsItem::ItemIgnoresTransformations);
+    }
 
-    setPos(MapEngine::convertLatLonToSceneCoordinate(ownPosition));
-    setZValue(OWN_LOCATION_ICON_Z_LEVEL);
-    setOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
-    setFlag(QGraphicsItem::ItemIgnoresTransformations);
+    else
+        qDebug() << "Own Location Icon cannot be loaded";
 }
 
 void OwnLocationItem::setPosition(const QPointF & newPosition)
index 96b83bf..04bb86d 100644 (file)
@@ -75,7 +75,7 @@ public:
     void hideOwnLocation();
 
     /**
-    * @brief returns position of OwnLocationItem
+    * @brief returns position of OwnLocationItem in scene coordinates.
     *
     * @return QPoint position of OwnLocationItem
     */
@@ -83,7 +83,7 @@ public:
 
     /**
     * @brief sets position of OwnLocationItem as specified in parameter.
-    *        Position defines where icon is show on the map.
+    *        Parameter can be given in georaphical coordinates
     *
     * @param newPosition Parameter that specifies new position.
     */
index b48aaae..fddfa84 100644 (file)
@@ -10,6 +10,8 @@ DEPENDPATH += .
 INCLUDEPATH += . \
      ../../../src/
 
+RESOURCES += ../../../images.qrc
+
 # Input
 SOURCES += testownlocationitem.cpp \
      ../../../src/map/mapscene.cpp \
index 2eedd2e..6e250c0 100644 (file)
@@ -85,6 +85,23 @@ class TestOwnLocationItem: public QObject
      OwnLocationItem ownLocationItem2(xCoordinate, yCoordinate);
      OwnLocationItem ownLocationItem3(testLocationPoint);
 
+     // Test Pixmaps
+     QPixmap pixmap1;
+     QPixmap pixmap2;
+     QPixmap pixmap3;
+
+     QCOMPARE (pixmap1.isNull(), true);
+     QCOMPARE (pixmap2.isNull(), true);
+     QCOMPARE (pixmap3.isNull(), true);
+
+     pixmap1 = ownLocationItem1.pixmap();
+     pixmap2 = ownLocationItem2.pixmap();
+     pixmap3 = ownLocationItem3.pixmap();
+
+     QCOMPARE (pixmap1.isNull(), false);
+     QCOMPARE (pixmap2.isNull(), false);
+     QCOMPARE (pixmap3.isNull(), false);
+
      // Test Positions
      QCOMPARE(ownLocationItem1.position(),
               MapEngine::convertLatLonToSceneCoordinate(defaultLocationPoint));