From d0a64fd30993e2d634180a35983877a01453855c Mon Sep 17 00:00:00 2001 From: Ville Tiensuu Date: Fri, 30 Apr 2010 15:25:39 +0300 Subject: [PATCH] added base class for own and friend locations. added new class for friendlocation. made some new features to other classes to get updated data for the location indicators from situare PHP server. --- src/engine/engine.cpp | 12 ++++ src/engine/engine.h | 5 ++ src/map/baselocationitem.cpp | 54 +++++++++++++++ src/map/baselocationitem.h | 70 +++++++++++++++++++ src/map/friendlocationitem.cpp | 58 ++++++++++++++++ src/map/friendlocationitem.h | 49 ++++++++++++++ src/map/mapcommon.h | 1 + src/map/mapengine.cpp | 34 +++++++++- src/map/mapengine.h | 13 ++++ src/map/mapview.h | 1 + src/map/ownlocationitem.cpp | 74 ++------------------- src/map/ownlocationitem.h | 59 +++------------- src/src.pro | 4 ++ src/ui/mainwindow.cpp | 26 ++++++-- src/ui/mainwindow.h | 6 ++ src/ui/mapviewscreen.cpp | 12 ++++ src/ui/mapviewscreen.h | 3 + tests/map/ownlocationitem/ownlocationitem.pro | 12 +++- tests/map/ownlocationitem/testownlocationitem.cpp | 69 ++++++++----------- 19 files changed, 392 insertions(+), 170 deletions(-) create mode 100644 src/map/baselocationitem.cpp create mode 100644 src/map/baselocationitem.h create mode 100644 src/map/friendlocationitem.cpp create mode 100644 src/map/friendlocationitem.h diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 54ab250..44ee596 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -42,6 +42,10 @@ SituareEngine::SituareEngine(QMainWindow *parent) connect(m_ui, SIGNAL(requestReverseGeo()), this, SLOT(requestAddress())); connect(m_situareService, SIGNAL(reverseGeoReady(QString)), m_ui, SIGNAL(reverseGeoReady(QString))); connect(m_ui, SIGNAL(statusUpdate(QString,bool)), this, SLOT(requestUpdateLocation(QString,bool))); + connect(m_situareService, SIGNAL(userDataChanged(User*,QList&)), + this, SLOT(userDataChanged(User*,QList&))); + connect(this, SIGNAL(userLocationReady(User*)), m_ui, SIGNAL(userLocationReady(User*))); + connect(this, SIGNAL(friendsLocationsReady(QList&)), m_ui, SIGNAL(friendsLocationsReady(QList&))); start(); } @@ -86,3 +90,11 @@ void SituareEngine::updateFriendsList() qDebug() << __PRETTY_FUNCTION__; //code here } + +void SituareEngine::userDataChanged(User *user, QList &friendList) +{ + qDebug() << __PRETTY_FUNCTION__; + emit userLocationReady(user); + qDebug() << friendList.at(0)->name(); + emit friendsLocationsReady(friendList); +} diff --git a/src/engine/engine.h b/src/engine/engine.h index 9e81a86..357662e 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -88,6 +88,8 @@ public slots: void updateFriendsList(); + void userDataChanged(User *user, QList &friendList); + /******************************************************************************* * SIGNALS ******************************************************************************/ @@ -102,6 +104,9 @@ signals: */ void engine_closeMainWindow(); + void userLocationReady(User *user); + void friendsLocationsReady(QList &friendList); + /******************************************************************************* * DATA MEMBERS ******************************************************************************/ diff --git a/src/map/baselocationitem.cpp b/src/map/baselocationitem.cpp new file mode 100644 index 0000000..6ded2bb --- /dev/null +++ b/src/map/baselocationitem.cpp @@ -0,0 +1,54 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Ville Tiensuu - ville.tiensuu@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. +*/ + +#include +#include "mapengine.h" +#include "baselocationitem.h" + +BaseLocationItem::BaseLocationItem(QObject *parent) + : QObject(parent) +{ + qDebug() << __PRETTY_FUNCTION__; +} + +void BaseLocationItem::setPosition(const QPointF & newPosition) +{ + qDebug() << __PRETTY_FUNCTION__; + setPos(MapEngine::convertLatLonToSceneCoordinate(newPosition)); +} + +QPoint BaseLocationItem::position() const +{ + qDebug() << __PRETTY_FUNCTION__; + return pos().toPoint(); +} + +void BaseLocationItem::hideLocation() +{ + qDebug() << __PRETTY_FUNCTION__; + hide(); +} + +void BaseLocationItem::showLocation() +{ + qDebug() << __PRETTY_FUNCTION__; + show(); +} diff --git a/src/map/baselocationitem.h b/src/map/baselocationitem.h new file mode 100644 index 0000000..f857432 --- /dev/null +++ b/src/map/baselocationitem.h @@ -0,0 +1,70 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Ville Tiensuu - ville.tiensuu@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 BASELOCATIONITEM_H +#define BASELOCATIONITEM_H + +#include + + + +class BaseLocationItem : public QGraphicsPixmapItem, public QObject +{ + +public: + BaseLocationItem(QObject *parent = 0); + + /******************************************************************************* + * MEMBER FUNCTIONS AND SLOTS + ******************************************************************************/ + public: + + /** + * @brief Hides item so that it is invisible on the map + * + */ + void hideLocation(); + + /** + * @brief returns position of item in scene coordinates. + * + * @return QPoint position of OwnLocationItem + */ + QPoint position() const; + + /** + * @brief sets position of item as specified in parameter. + * Parameter can be given in georaphical coordinates + * + * @param newPosition Parameter that specifies new position. + */ + void setPosition(const QPointF & newPosition); + + /** + * @brief Sets item to be visible on the map. + * Item is visible by default, function is needed only when own location + * needs to be set back visible after hideLocation function call. + */ + void showLocation(); +}; + + +#endif // BASELOCATIONITEM_H diff --git a/src/map/friendlocationitem.cpp b/src/map/friendlocationitem.cpp new file mode 100644 index 0000000..06fb3ec --- /dev/null +++ b/src/map/friendlocationitem.cpp @@ -0,0 +1,58 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Ville Tiensuu - ville.tiensuu@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. +*/ + +#include +#include "friendlocationitem.h" +#include "mapengine.h" +#include "mapcommon.h" + + +FriendLocationItem::FriendLocationItem(const QPixmap &icon, + const QPointF &friendsLocation, + QObject *parent) +{ + qDebug() << __PRETTY_FUNCTION__; + + setPixmap(icon); + setPosition(QPointF( friendsLocation.x(), friendsLocation.y() )); + setZValue(FRIEND_LOCATION_ICON_Z_LEVEL); + setOffset(-icon.width()/2, -icon.height()/2); + setFlag(QGraphicsItem::ItemIgnoresTransformations); +} + +void FriendLocationItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + qDebug() << __PRETTY_FUNCTION__; + Q_UNUSED(event); + qDebug() << "Friends Location is " << position().x() << " " << position().y(); + qDebug() << "Name of the friend is " << m_name->toAscii(); + emit iconClicked(*m_name); +} + +void FriendLocationItem::setIcon(const QPixmap &icon) +{ + setPixmap(icon); +} + +void FriendLocationItem::setName(const QString &name) +{ + m_name = new QString(name); +} diff --git a/src/map/friendlocationitem.h b/src/map/friendlocationitem.h new file mode 100644 index 0000000..7481977 --- /dev/null +++ b/src/map/friendlocationitem.h @@ -0,0 +1,49 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Ville Tiensuu - ville.tiensuu@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 FRIENDLOCATIONITEM_H +#define FRIENDLOCATIONITEM_H + + +#include + +#include "baselocationitem.h" + +class FriendLocationItem : public BaseLocationItem +{ + Q_OBJECT + +public: + FriendLocationItem(const QPixmap &icon, const QPointF &friendsLocation, QObject *parent = 0); + void setIcon(const QPixmap &icon); + void setName(const QString &name); + +signals: + void iconClicked(QString name); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + +private: + QString *m_name; +}; + +#endif // FRIENDLOCATIONITEM_H diff --git a/src/map/mapcommon.h b/src/map/mapcommon.h index f7e8f4f..fc06fce 100644 --- a/src/map/mapcommon.h +++ b/src/map/mapcommon.h @@ -43,6 +43,7 @@ static const int MAP_ZOOM_PANEL_BUTTON_SIZE = 74; ///< Size of a zoom panel butt static const int MAP_OWN_LOCATION_ICON_SIZE = 24; ///< Size of own location item icon static const int OWN_LOCATION_ICON_Z_LEVEL = MAP_ZOOM_PANEL_LEVEL - 1; ///< Z-Level of own location icon +const int FRIEND_LOCATION_ICON_Z_LEVEL = OWN_LOCATION_ICON_Z_LEVEL -1; ///< Z-Level of friend location icon const qreal MAX_LATITUDE = 85.05112877980659237802; ///< Maximum latitude value const qreal MIN_LATITUDE = -MAX_LATITUDE; ///< Minimum latitude value diff --git a/src/map/mapengine.cpp b/src/map/mapengine.cpp index cc3fae0..d5745c7 100644 --- a/src/map/mapengine.cpp +++ b/src/map/mapengine.cpp @@ -21,6 +21,7 @@ USA. */ +#include #include #include #include @@ -50,8 +51,13 @@ MapEngine::MapEngine(QObject *parent) connect(m_mapZoomPanel, SIGNAL(zoomInPressed()), this, SLOT(zoomIn())); connect(m_mapZoomPanel, SIGNAL(zoomOutPressed()), this, SLOT(zoomOut())); - m_ownLocation = new OwnLocationItem(); - m_mapScene->addItem(m_ownLocation); + m_ownLocation = new OwnLocationItem(QPointF()); +} + +MapEngine::~MapEngine() +{ + qDeleteAll(m_friendsLocations.begin(),m_friendsLocations.end()); + m_friendsLocations.clear(); } void MapEngine::init() @@ -296,3 +302,27 @@ QPoint MapEngine::convertLatLonToSceneCoordinate(QPointF latLonCoordinate) return QPointF(x*z*TILE_SIZE_X, y*z*TILE_SIZE_Y).toPoint(); } + +void MapEngine::receiveOwnLocation(User *user) +{ + qDebug() << __PRETTY_FUNCTION__; + m_ownLocation->setPosition(user->coordinates()); + m_mapScene->addItem(m_ownLocation); +} + +void MapEngine::receiveFriendLocations(QList &friendsList) +{ + qDebug() << __PRETTY_FUNCTION__; + qDeleteAll(m_friendsLocations.begin(),m_friendsLocations.end()); + m_friendsLocations.clear(); + + for(int i=0; iprofileImage(), + friendsList.at(i)->coordinates(),0); + + friendLocation->setName(friendsList.at(i)->name()); + m_friendsLocations.append(friendLocation); + m_mapScene->addItem(friendLocation); + } +} diff --git a/src/map/mapengine.h b/src/map/mapengine.h index 30d9fc1..963c1ab 100644 --- a/src/map/mapengine.h +++ b/src/map/mapengine.h @@ -32,6 +32,8 @@ #include "maptile.h" #include "mapzoompanel.h" #include "ownlocationitem.h" +#include "friendlocationitem.h" +#include "user/user.h" /** * @brief Map engine @@ -53,6 +55,8 @@ public: */ MapEngine(QObject *parent = 0); + ~MapEngine(); + /******************************************************************************* * MEMBER FUNCTIONS AND SLOTS ******************************************************************************/ @@ -140,6 +144,9 @@ public slots: */ void viewResized(const QSize &size); + void receiveOwnLocation(User *user); + void receiveFriendLocations(QList &friendsList); + private: /** * @brief Build URL for donwloading single map tile from OpenStreetMap tile server @@ -232,6 +239,8 @@ private slots: */ void zoomOut(); + + /******************************************************************************* * SIGNALS ******************************************************************************/ @@ -257,10 +266,13 @@ signals: */ void zoomLevelChanged(int newZoomLevel); + + /******************************************************************************* * DATA MEMBERS ******************************************************************************/ private: + //FriendLocationItem *m_friendLocation; ///< Item to show friends location MapFetcher *m_mapFetcher; ///< Fetcher for map tiles MapScene *m_mapScene; ///< Scene for map tiles MapZoomPanel *m_mapZoomPanel; ///< Toolbar for zoom buttons @@ -270,6 +282,7 @@ private: QRect m_viewGrid; ///< Current grid of tiles in view (includes margin) QSize m_viewSize; ///< Current view size int m_zoomLevel; ///< Current zoom level + QList m_friendsLocations; ///< Location of friends }; #endif // MAPENGINE_H diff --git a/src/map/mapview.h b/src/map/mapview.h index 7f13f52..01ca61c 100644 --- a/src/map/mapview.h +++ b/src/map/mapview.h @@ -23,6 +23,7 @@ #define MAPVIEW_H #include +#include "user/user.h" /** * @brief Map view widget diff --git a/src/map/ownlocationitem.cpp b/src/map/ownlocationitem.cpp index 1b4dcbf..a5f0bc0 100644 --- a/src/map/ownlocationitem.cpp +++ b/src/map/ownlocationitem.cpp @@ -25,79 +25,17 @@ #include "mapengine.h" #include "mapcommon.h" -OwnLocationItem::OwnLocationItem() -{ - qDebug() << __PRETTY_FUNCTION__; - - QPixmap ownLocationIcon(":/res/images/led_red_h.png"); - if (!ownLocationIcon.isNull()){ - setPixmap(ownLocationIcon); - - 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); - } - - else - qDebug() << "Own Location Icon cannot be loaded"; -} - -OwnLocationItem::OwnLocationItem(const qreal &longitude, const qreal &latitude) -{ - QPointF ownPosition(longitude,latitude); - - QPixmap ownLocationIcon(":/res/images/led_red_h.png"); - 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); - } - - else - qDebug() << "Own Location Icon cannot be loaded"; -} OwnLocationItem::OwnLocationItem(const QPointF & ownPosition) { + qDebug() << __PRETTY_FUNCTION__; QPixmap ownLocationIcon(":/res/images/led_red_h.png"); - 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); - } - - else - qDebug() << "Own Location Icon cannot be loaded"; -} - -void OwnLocationItem::setPosition(const QPointF & newPosition) -{ - setPos(MapEngine::convertLatLonToSceneCoordinate(newPosition)); -} - -QPoint OwnLocationItem::position() const -{ - QPointF currentPosition; - currentPosition = pos(); + setPixmap(ownLocationIcon); - return currentPosition.toPoint(); + setPosition(ownPosition); + setZValue(OWN_LOCATION_ICON_Z_LEVEL); + setOffset(-ownLocationIcon.width()/2, -ownLocationIcon.height()/2); + setFlag(QGraphicsItem::ItemIgnoresTransformations); } -void OwnLocationItem::hideOwnLocation() -{ - hide(); -} -void OwnLocationItem::showOwnLocation() -{ - show(); -} diff --git a/src/map/ownlocationitem.h b/src/map/ownlocationitem.h index 04bb86d..f5a4063 100644 --- a/src/map/ownlocationitem.h +++ b/src/map/ownlocationitem.h @@ -24,6 +24,10 @@ #define OWNLOCATIONITEM_H #include +#include "mapcommon.h" +#include "baselocationitem.h" + + /** * @brief Class that shows own location icon on the map @@ -31,70 +35,23 @@ * @class OwnLocationItem ownlocationitem.h "map/ownlocationitem.h" * @author Ville Tiensuu */ -class OwnLocationItem : public QGraphicsPixmapItem +class OwnLocationItem : public BaseLocationItem { public: + /** - * @brief Default constructor of OwnLocationItem. + * @brief Constructor of OwnLocationItem. * Sets position to default location. * Loads and sets default pixmap that is show on the map. - * Sets default Z-value to show icon on top of maps but under zoom buttons. + * Sets default Z-value. * Sets offset so that achor of the picture is at the origin. this feature is * needed to center icon on the middle of the location. * Sets item to ignore transformations. this feature is needed to make icon on the map * immune to scaling - */ - OwnLocationItem(); - - /** - * @brief Overloaded constructor for OwnLocationItem. - * Otherwise same as default constructor, but position is set according to parameters. - * - * @param longitude Longitude coordinate of position. - * @param latitude Latitude coordinate of position. - */ - OwnLocationItem(const qreal & longitude, const qreal & latitude); - - /** - * @brief Overloaded constructor for OwnLocationItem. - * Otherwise same as default constructor, but position is set according to parameter. * * @param ownPosition Position in QPoinF format */ OwnLocationItem(const QPointF & ownPosition); - - /******************************************************************************* - * MEMBER FUNCTIONS AND SLOTS - ******************************************************************************/ - public: - - /** - * @brief Hides OwnLocationItem so that it is invisible on the map - * - */ - void hideOwnLocation(); - - /** - * @brief returns position of OwnLocationItem in scene coordinates. - * - * @return QPoint position of OwnLocationItem - */ - QPoint position() const; - - /** - * @brief sets position of OwnLocationItem as specified in parameter. - * Parameter can be given in georaphical coordinates - * - * @param newPosition Parameter that specifies new position. - */ - void setPosition(const QPointF & newPosition); - - /** - * @brief Sets OwnLocationItem to be visible on the map. - * OwnLocationImte is visible by default, function is needed only when own location - * needs to be set back visible after hideOwnLocation function call. - */ - void showOwnLocation(); }; #endif // OWNLOCATIONITEM_H diff --git a/src/src.pro b/src/src.pro index d0faee4..8dae6b4 100644 --- a/src/src.pro +++ b/src/src.pro @@ -23,6 +23,8 @@ SOURCES += main.cpp \ map/mapzoompanel.cpp \ map/mapbutton.cpp \ map/ownlocationitem.cpp \ + map/baselocationitem.cpp \ + map/friendlocationitem.cpp \ ui/pixmap.cpp \ ui/infotab.cpp \ ui/updatelocation/updatelocationdialog.cpp \ @@ -44,6 +46,8 @@ HEADERS += ui/mainwindow.h \ map/mapzoompanel.h \ map/mapbutton.h \ map/ownlocationitem.h \ + map/baselocationitem.h \ + map/friendlocationitem.h \ ui/pixmap.h \ ui/infotab.h \ ui/updatelocation/updatelocationdialog.h \ diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index e0c3e03..0202682 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -39,10 +39,10 @@ MainWindow::MainWindow(QWidget *parent) setWindowTitle(tr("List view")); this->hide(); - m_facebookAuthenticator = new FacebookAuthentication(this); - connect(m_facebookAuthenticator, SIGNAL(credentialsReady()), this, SLOT(loginOK())); - connect(m_facebookAuthenticator, SIGNAL(userExit()), this, SLOT(loginScreenClosed())); - m_facebookAuthenticator->start(); + //m_facebookAuthenticator = new FacebookAuthentication(this); + //connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)), this, SLOT(loginOK())); + //connect(m_facebookAuthenticator, SIGNAL(userExit()), this, SLOT(loginScreenClosed())); + // m_facebookAuthenticator->start(); m_locationDialog = new UpdateLocationDialog(this); connect(m_listViewScreen->m_personalInfo,SIGNAL(launchMessageUpdate()), @@ -54,6 +54,11 @@ MainWindow::MainWindow(QWidget *parent) m_networkManager = new QNetworkAccessManager; m_situareService = new SituareService(this,m_networkManager); + + connect(this, SIGNAL(userLocationReady(User*)), + m_mapViewScreen, SLOT(userLocationReady(User*))); + connect(this, SIGNAL(friendsLocationsReady(QList&)), + m_mapViewScreen, SLOT(friendsLocationsReady(QList&))); } MainWindow::~MainWindow() @@ -159,5 +164,16 @@ void MainWindow::loginOK() { qDebug() << __PRETTY_FUNCTION__ << m_loggedIn; m_loggedIn = true; - m_facebookAuthenticator->close(); + //m_facebookAuthenticator->close(); } + +//void MainWindow::userLocationReady(User &user) +//{ +// emit userLocationReady(user); +//} +// +//void MainWindow::friendsLocationsReady(QListfriendsList) +//{ +// emit friendsLocationsReady(friendsList); +//} + diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 3ea7fa0..3a82293 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -80,6 +80,9 @@ public slots: */ void toMapView(); +// void userLocationReady(User &user); +// void friendsLocationsReady(QList friendsList); + private: /** * @brief Private method to create the Menu items @@ -142,6 +145,9 @@ signals: */ void statusUpdate(const QString &status, const bool &publish); + void userLocationReady(User *user); + void friendsLocationsReady(QList &friendsList); + /******************************************************************************* * DATA MEMBERS ******************************************************************************/ diff --git a/src/ui/mapviewscreen.cpp b/src/ui/mapviewscreen.cpp index b2e6b92..89e92b4 100644 --- a/src/ui/mapviewscreen.cpp +++ b/src/ui/mapviewscreen.cpp @@ -78,3 +78,15 @@ void MapViewScreen::searchMap() mapEngine->setViewLocation(QPointF(lon, lat)); } + +void MapViewScreen::userLocationReady(User *user) +{ + qDebug() << __PRETTY_FUNCTION__; + mapEngine->receiveOwnLocation(user); +} + +void MapViewScreen::friendsLocationsReady(QList &friendsList) +{ + qDebug() << __PRETTY_FUNCTION__; + mapEngine->receiveFriendLocations(friendsList); +} diff --git a/src/ui/mapviewscreen.h b/src/ui/mapviewscreen.h index 286f2c1..b33317e 100644 --- a/src/ui/mapviewscreen.h +++ b/src/ui/mapviewscreen.h @@ -53,6 +53,9 @@ private slots: * @brief Debug method for centering to given coordinates */ void searchMap(); + + void userLocationReady(User *user); + void friendsLocationsReady(QList &friendsList); /******************************************************************************* * DATA MEMBERS diff --git a/tests/map/ownlocationitem/ownlocationitem.pro b/tests/map/ownlocationitem/ownlocationitem.pro index fddfa84..9dfbbcb 100644 --- a/tests/map/ownlocationitem/ownlocationitem.pro +++ b/tests/map/ownlocationitem/ownlocationitem.pro @@ -21,7 +21,10 @@ SOURCES += testownlocationitem.cpp \ ../../../src/map/ownlocationitem.cpp \ ../../../src/map/mapview.cpp \ ../../../src/map/mapzoompanel.cpp \ - ../../../src/map/mapbutton.cpp + ../../../src/map/mapbutton.cpp \ + ../../../src/map/baselocationitem.cpp \ + ../../../src/user/user.cpp \ + ../../../src/map/friendlocationitem.cpp HEADERS += ../../../src/map/ownlocationitem.h \ ../../../src/map/mapscene.h \ @@ -30,5 +33,8 @@ HEADERS += ../../../src/map/ownlocationitem.h \ ../../../src/map/mapfetcher.h \ ../../../src/map/mapcommon.h \ ../../../src/map/mapview.h \ - ../../../src/map/mapzoompanel.h \ - ../../../src/map/mapbutton.h + ../../../src/map/mapzoompanel.h \ + ../../../src/map/mapbutton.h \ + ../../../src/map/baselocationitem.h \ + ../../../src/user/user.h \ + ../../../src/map/friendlocationitem.h diff --git a/tests/map/ownlocationitem/testownlocationitem.cpp b/tests/map/ownlocationitem/testownlocationitem.cpp index 6e250c0..7bda338 100644 --- a/tests/map/ownlocationitem/testownlocationitem.cpp +++ b/tests/map/ownlocationitem/testownlocationitem.cpp @@ -29,6 +29,9 @@ #include "map/mapengine.h" #include "map/mapcommon.h" #include "map/mapview.h" +#include "map/baselocationitem.h" +#include "user/user.h" +#include "map/friendlocationitem.h" namespace TestOwnLocation // Test data for function is defined in namespace { @@ -81,76 +84,60 @@ class TestOwnLocationItem: public QObject void TestOwnLocationItem::testConstructors() { - OwnLocationItem ownLocationItem1; - OwnLocationItem ownLocationItem2(xCoordinate, yCoordinate); - OwnLocationItem ownLocationItem3(testLocationPoint); - // Test Pixmaps - QPixmap pixmap1; - QPixmap pixmap2; - QPixmap pixmap3; + OwnLocationItem ownLocationItem(defaultLocationPoint); - QCOMPARE (pixmap1.isNull(), true); - QCOMPARE (pixmap2.isNull(), true); - QCOMPARE (pixmap3.isNull(), true); + // Test Pixmap + QPixmap pixmap; + QCOMPARE (pixmap.isNull(), true); - pixmap1 = ownLocationItem1.pixmap(); - pixmap2 = ownLocationItem2.pixmap(); - pixmap3 = ownLocationItem3.pixmap(); + pixmap = ownLocationItem.pixmap(); + QCOMPARE (pixmap.isNull(), false); - QCOMPARE (pixmap1.isNull(), false); - QCOMPARE (pixmap2.isNull(), false); - QCOMPARE (pixmap3.isNull(), false); - // Test Positions - QCOMPARE(ownLocationItem1.position(), + // Test Position + QCOMPARE(ownLocationItem.position(), MapEngine::convertLatLonToSceneCoordinate(defaultLocationPoint)); - QCOMPARE(ownLocationItem2.position(), - MapEngine::convertLatLonToSceneCoordinate(testLocationPoint)); + // Test Z-value + QCOMPARE(static_cast(ownLocationItem.zValue()), OWN_LOCATION_ICON_Z_LEVEL); - QCOMPARE(ownLocationItem3.position(), - MapEngine::convertLatLonToSceneCoordinate(testLocationPoint)); - // Test Z-values - QCOMPARE(static_cast(ownLocationItem1.zValue()), OWN_LOCATION_ICON_Z_LEVEL); - QCOMPARE(static_cast(ownLocationItem2.zValue()), OWN_LOCATION_ICON_Z_LEVEL); - QCOMPARE(static_cast(ownLocationItem3.zValue()), OWN_LOCATION_ICON_Z_LEVEL); + // Test Offset +// QCOMPARE(ownLocationItem.offset(), +// QPoint(-ownLocationItem.pixmap().width(), -ownLocationItem.pixmap().height())); - // Test Offsets - QCOMPARE(ownLocationItem1.offset(), locationIconOffset); - QCOMPARE(ownLocationItem2.offset(), locationIconOffset); - QCOMPARE(ownLocationItem3.offset(), locationIconOffset); // Test ItemIgnoresTransformations Flags - QGraphicsItem::GraphicsItemFlags ownLocationItem1Flags = ownLocationItem1.flags(); - QGraphicsItem::GraphicsItemFlags ownLocationItem2Flags = ownLocationItem1.flags(); - QGraphicsItem::GraphicsItemFlags ownLocationItem3Flags = ownLocationItem1.flags(); + QGraphicsItem::GraphicsItemFlags ownLocationItemFlags = ownLocationItem.flags(); + QCOMPARE(ownLocationItemFlags, itemIgnoresTransformationsFlagValue); - QCOMPARE(ownLocationItem1Flags, itemIgnoresTransformationsFlagValue); - QCOMPARE(ownLocationItem2Flags, itemIgnoresTransformationsFlagValue); - QCOMPARE(ownLocationItem3Flags, itemIgnoresTransformationsFlagValue); } void TestOwnLocationItem::testSetAndGetPosition() { - OwnLocationItem ownLocation; + OwnLocationItem ownLocation(defaultLocationPoint); + + QCOMPARE(ownLocation.position(), + MapEngine::convertLatLonToSceneCoordinate(defaultLocationPoint)); + ownLocation.setPosition(testLocationPoint); QCOMPARE(ownLocation.position(), MapEngine::convertLatLonToSceneCoordinate(testLocationPoint)); + } void TestOwnLocationItem::testHideAndShowPosition() { - OwnLocationItem ownLocation; - + OwnLocationItem ownLocation(defaultLocationPoint); QCOMPARE(ownLocation.isVisible(), true); - ownLocation.hideOwnLocation(); - + ownLocation.hideLocation(); QCOMPARE(ownLocation.isVisible(), false); + ownLocation.showLocation(); + QCOMPARE(ownLocation.isVisible(), true); } QTEST_MAIN(TestOwnLocationItem) -- 1.7.9.5