From 0e46d580c2d370a10154d681e5c4c7f94f2c9e67 Mon Sep 17 00:00:00 2001 From: Ville Tiensuu Date: Thu, 29 Apr 2010 11:50:52 +0300 Subject: [PATCH] small updates to own location feature --- src/map/ownlocationitem.cpp | 48 +++++++++++++-------- src/map/ownlocationitem.h | 4 +- tests/map/ownlocationitem/ownlocationitem.pro | 2 + tests/map/ownlocationitem/testownlocationitem.cpp | 17 ++++++++ 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/map/ownlocationitem.cpp b/src/map/ownlocationitem.cpp index ef3d5ef..1b4dcbf 100644 --- a/src/map/ownlocationitem.cpp +++ b/src/map/ownlocationitem.cpp @@ -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) diff --git a/src/map/ownlocationitem.h b/src/map/ownlocationitem.h index 96b83bf..04bb86d 100644 --- a/src/map/ownlocationitem.h +++ b/src/map/ownlocationitem.h @@ -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. */ diff --git a/tests/map/ownlocationitem/ownlocationitem.pro b/tests/map/ownlocationitem/ownlocationitem.pro index b48aaae..fddfa84 100644 --- a/tests/map/ownlocationitem/ownlocationitem.pro +++ b/tests/map/ownlocationitem/ownlocationitem.pro @@ -10,6 +10,8 @@ DEPENDPATH += . INCLUDEPATH += . \ ../../../src/ +RESOURCES += ../../../images.qrc + # Input SOURCES += testownlocationitem.cpp \ ../../../src/map/mapscene.cpp \ diff --git a/tests/map/ownlocationitem/testownlocationitem.cpp b/tests/map/ownlocationitem/testownlocationitem.cpp index 2eedd2e..6e250c0 100644 --- a/tests/map/ownlocationitem/testownlocationitem.cpp +++ b/tests/map/ownlocationitem/testownlocationitem.cpp @@ -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)); -- 1.7.9.5