Fixed last merge broken stuff and re-factored
authorSami Rämö <sami.ramo@ixonos.com>
Thu, 6 May 2010 10:57:08 +0000 (13:57 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Thu, 6 May 2010 10:57:08 +0000 (13:57 +0300)
src/engine/engine.cpp
src/map/frienditemshandler.cpp
src/map/frienditemshandler.h
src/map/mapengine.cpp
src/map/mapengine.h
src/ui/mainwindow.cpp
src/ui/mapviewscreen.cpp
src/ui/mapviewscreen.h

index 62ce97f..965f952 100644 (file)
@@ -75,7 +75,7 @@ void SituareEngine::loginOk()
     m_ui->show();
     m_situareService->fetchLocations(); // request user locations
 
-    m_situareService->debugData();
+//    m_situareService->debugData();
 }
 
 void SituareEngine::requestAddress()
index bed3192..46e1009 100644 (file)
 
 #include <QDebug>
 
+#include "friendgroupitem.h"
+#include "friendlocationitem.h"
+#include "mapengine.h"
+#include "mapscene.h"
+#include "user/user.h"
+
 #include "frienditemshandler.h"
 
-FriendItemsHandler::FriendItemsHandler(QObject *parent)
-    : QObject(parent)
+FriendItemsHandler::FriendItemsHandler(MapScene *mapScene, QObject *parent)
+    : QObject(parent),
+      m_mapScene(mapScene)
+{
+}
+
+FriendItemsHandler::~FriendItemsHandler()
 {
+    qDeleteAll(m_friendItems.begin(),m_friendItems.end());
+    m_friendItems.clear();
 }
 
 void FriendItemsHandler::checkFriendsForCollisions()
@@ -38,12 +51,12 @@ void FriendItemsHandler::checkFriendsForCollisions()
 //        m_mapScene->removeItem(item);
 //    }
 
-    int lastItem = m_friendsLocations.size() - 1;
+    int lastItem = m_friendItems.size() - 1;
     for (int checking = 0; checking <= lastItem; checking++) {
-        QRect beginItemRect = m_friendsLocations.at(checking)->sceneTransformedBoundingRect(m_zoomLevel);
+        QRect beginItemRect = m_friendItems.at(checking)->sceneTransformedBoundingRect(m_zoomLevel);
 
         // don't check items which are already part of a group (and thus unvisible)
-        if (m_friendsLocations.at(checking)->isPartOfGroup())
+        if (m_friendItems.at(checking)->isPartOfGroup())
             continue;
 
         // check all other items
@@ -54,18 +67,18 @@ void FriendItemsHandler::checkFriendsForCollisions()
                 continue;
 
             // don't check against items which are already part of a group (and thus unvisible)
-            if (m_friendsLocations.at(another)->isPartOfGroup())
+            if (m_friendItems.at(another)->isPartOfGroup())
                 continue;
 
             // does items collide
-            QRect iterItemRect = m_friendsLocations.at(another)->sceneTransformedBoundingRect(m_zoomLevel);
+            QRect iterItemRect = m_friendItems.at(another)->sceneTransformedBoundingRect(m_zoomLevel);
             if (beginItemRect.intersects(iterItemRect)) {
                 qWarning() << __PRETTY_FUNCTION__ << "collision found" << checking << another;
                 FriendGroupItem *group = new FriendGroupItem();
                 m_friendGroupItems.append(group);
-                group->setPos(m_friendsLocations.at(checking)->pos());
-                group->joinFriend(m_friendsLocations.at(checking));
-                group->joinFriend(m_friendsLocations.at(another));
+                group->setPos(m_friendItems.at(checking)->pos());
+                group->joinFriend(m_friendItems.at(checking));
+                group->joinFriend(m_friendItems.at(another));
                 m_mapScene->addItem(group);
                 break;
             }
@@ -78,14 +91,99 @@ void FriendItemsHandler::checkGroupsForCollisions()
 
 }
 
+void FriendItemsHandler::cleanOldFriendData(const QList<User *> &friendsList)
+{
+    bool friendGone = true;
+
+    for (int i=0; i<m_friendItems.count(); i++) {
+
+        for (int j=0; j<friendsList.count(); j++) {
+
+            if (m_friendItems.at(i)->userId() == friendsList.at(j)->userId())
+                friendGone = false;
+        }
+
+        if (friendGone) {
+            m_mapScene->removeItem(m_friendItems.at(i));
+            m_friendItems.removeAt(i);
+        }
+
+        friendGone = true;
+    }
+}
 void FriendItemsHandler::dropOutOfGroupFriends()
 {
 
 }
 
-void FriendItemsHandler::refactorFriendItems()
+void FriendItemsHandler::receiveFriendLocations(QList<User *> &friendsList)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    static int receiveFriendsLocationsCounter = 0;
+
+    if (receiveFriendsLocationsCounter == 0) {
+        receiveFriendsLocationsCounter++;
+        updateFriendItemList(friendsList);
+    }
+
+    else {
+        /// @todo VILLE: New friends are never added to list & scene
+        receiveFriendsLocationsCounter++;
+        updateFriendLocationsAndImages(friendsList);
+        cleanOldFriendData(friendsList);
+    }
+}
+
+void FriendItemsHandler::refactorFriendItems(int zoomLevel)
 {
+    m_zoomLevel = zoomLevel;
+
     dropOutOfGroupFriends();
     checkGroupsForCollisions();
     checkFriendsForCollisions();
 }
+
+void FriendItemsHandler::updateFriendItemList(const QList<User *> &friendsList)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    qDeleteAll(m_friendItems.begin(),m_friendItems.end());
+    m_friendItems.clear();
+
+
+    for (int i=0; i<friendsList.count(); i++) {
+        FriendLocationItem *friendLocation
+                = new FriendLocationItem(friendsList.at(i)->profileImage(),
+                                         friendsList.at(i)->coordinates(),0);
+
+        friendLocation->setUserId(friendsList.at(i)->userId());
+        m_friendItems.append(friendLocation);
+        m_mapScene->addItem(friendLocation);
+
+        //refactorFriendItems(m_zoomLevel);
+    }
+}
+
+void FriendItemsHandler::updateFriendLocationsAndImages(const QList<User *> &friendsList)
+{
+    for (int i=0; i<friendsList.count(); i++) {
+
+        for (int j=0; j<m_friendItems.count(); j++) {
+
+            if (m_friendItems.at(j)->userId() == friendsList.at(i)->userId()) {
+
+                if (m_friendItems.at(j)->position()
+                    != MapEngine::convertLatLonToSceneCoordinate(friendsList.at(i)->coordinates()))
+                    m_friendItems.at(j)->setPosition(friendsList.at(i)->coordinates());
+
+                if (m_friendItems.at(j)->profileImageUrl()
+                    != friendsList.at(i)->profileImageUrl()) {
+                    m_friendItems.at(j)->setPixmap(friendsList.at(i)->profileImage());
+                }
+            }
+        }
+    }
+}
+
+
index ad4a65b..95b24a8 100644 (file)
 #include <QList>
 #include <QObject>
 
+#include "user/user.h"
+
 class FriendGroupItem;
+class FriendLocationItem;
+class MapScene;
+
+/**
+ * @author Sami Rämö - sami.ramo@ixonos.com
+ * @author Ville Tiensuu - ville.tiensuu@ixonos.com
+ */
 
 class FriendItemsHandler : public QObject
 {
     Q_OBJECT
 
 public:
-    FriendItemsHandler(QObject *parent = 0);
+    FriendItemsHandler(MapScene *mapScene, QObject *parent = 0);
+
+    ~FriendItemsHandler();
+
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public:
 
+private:
     void checkFriendsForCollisions();
 
     void checkGroupsForCollisions();
 
-    void dropOutOfGroupFriends();
+    /**
+    * @brief clean old friend data from m_mapScene and m_friendItems
+    *
+    * @param friendsList QList item of friend information
+    */
+    void cleanOldFriendData(const QList<User *> &friendsList);
 
-    void refactorFriendItems();
+    void dropOutOfGroupFriends();
 
+    /**
+    * @brief updates data member m_friendItems from given parameter
+    *
+    * @param friendsList QList item of friend information
+    */
+    void updateFriendItemList(const QList<User *> &friendsList);
+
+    /**
+    * @brief updates data member m_friendItems values that differs from given parameter
+    *
+    * @param friendsList QList item of friend information
+    */
+    void updateFriendLocationsAndImages(const QList<User *> &friendsList);
+
+private slots:
+    /**
+    * @brief Slot to catch friends location data
+    *
+    * @param friendsList QList item of friend information
+    */
+    void receiveFriendLocations(QList<User *> &friendsList);
+
+    void refactorFriendItems(int zoomLevel);
+
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
 private:
     QList<FriendGroupItem *> m_friendGroupItems;
+    QList<FriendLocationItem *> m_friendItems; ///< List of friendLocationItems
+    MapScene *m_mapScene;
+    int m_zoomLevel; /// @todo default value?
 };
 
 #endif // FRIENDITEMSHANDLER_H
index e201a8e..a098db6 100644 (file)
@@ -61,13 +61,12 @@ MapEngine::MapEngine(QObject *parent)
     /// lisätään sceneen
     m_ownLocation = new OwnLocationItem(QPointF());
 
-    m_friendItemsHandler = new FriendItemsHandler(this);
-}
+    m_friendItemsHandler = new FriendItemsHandler(m_mapScene, this);
+    connect(this, SIGNAL(zoomLevelChanged(int)),
+            m_friendItemsHandler, SLOT(refactorFriendItems(int)));
 
-MapEngine::~MapEngine()
-{
-    qDeleteAll(m_friendItems.begin(),m_friendItems.end());
-    m_friendItems.clear();
+    connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
+            m_friendItemsHandler, SLOT(receiveFriendLocations(QList<User*>&)));
 }
 
 void MapEngine::init()
@@ -340,84 +339,3 @@ void MapEngine::receiveOwnLocation(User *user)
         }
     }
 }
-
-void MapEngine::receiveFriendLocations(QList<User *> &friendsList)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    static int receiveFriendsLocationsCounter = 0;
-
-    if (receiveFriendsLocationsCounter == 0) {
-        receiveFriendsLocationsCounter++;
-        updateFriendItemList(friendsList);
-    }
-
-    else {
-        receiveFriendsLocationsCounter++;
-        updateFriendLocationsAndImages(friendsList);
-        cleanOldFriendData(friendsList);        
-    }    
-}
-
-void MapEngine::updateFriendItemList(const QList<User *> &friendsList)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    qDeleteAll(m_friendItems.begin(),m_friendItems.end());
-    m_friendItems.clear();
-
-
-    for (int i=0; i<friendsList.count(); i++) {
-        FriendLocationItem *friendLocation
-                = new FriendLocationItem(friendsList.at(i)->profileImage(),
-                                         friendsList.at(i)->coordinates(),0);
-
-        friendLocation->setUserId(friendsList.at(i)->userId());
-        m_friendItems.append(friendLocation);
-        m_mapScene->addItem(friendLocation);
-
-        m_friendItemsHandler->refactorFriendItems();
-    }
-}
-
-void MapEngine::updateFriendLocationsAndImages(const QList<User *> &friendsList)
-{    
-    for (int i=0; i<friendsList.count(); i++) {
-
-        for (int j=0; j<m_friendItems.count(); j++) {
-
-            if (m_friendItems.at(j)->userId() == friendsList.at(i)->userId()) {                
-
-                if (m_friendItems.at(j)->position()
-                    != convertLatLonToSceneCoordinate(friendsList.at(i)->coordinates()))
-                    m_friendItems.at(j)->setPosition(friendsList.at(i)->coordinates());
-
-                if (m_friendItems.at(j)->profileImageUrl()
-                    != friendsList.at(i)->profileImageUrl()) {
-                    m_friendItems.at(j)->setPixmap(friendsList.at(i)->profileImage());
-                }
-            }
-        }
-    }
-}
-
-void MapEngine::cleanOldFriendData(const QList<User *> &friendsList)
-{
-    bool friendGone = true;
-
-    for (int i=0; i<m_friendItems.count(); i++) {
-
-        for (int j=0; j<friendsList.count(); j++) {
-
-            if (m_friendItems.at(i)->userId() == friendsList.at(j)->userId())
-                friendGone = false;
-        }
-
-        if (friendGone) {
-            m_mapScene->removeItem(m_friendItems.at(i));
-            m_friendItems.removeAt(i);
-        }
-
-        friendGone = true;
-    }
-}
index 3b72783..664bfa2 100644 (file)
@@ -33,7 +33,6 @@
 #include "maptile.h"
 #include "mapzoompanel.h"
 #include "ownlocationitem.h"
-#include "friendlocationitem.h"
 #include "user/user.h"
 
 class FriendItemsHandler;
@@ -60,8 +59,6 @@ public:
     */
     MapEngine(QObject *parent = 0);
 
-    ~MapEngine();
-
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
@@ -156,13 +153,6 @@ public slots:
     */
     void receiveOwnLocation(User *user);
 
-    /**
-    * @brief Slot to catch friends location data
-    *
-    * @param friendsList QList item of friend information
-    */
-    void receiveFriendLocations(QList<User *> &friendsList);
-
 private:
     /**
     * @brief Calculate grid of tile coordinates from current scene coordinate.
@@ -175,13 +165,6 @@ private:
     QRect calculateTileGrid(QPoint sceneCoordinate);
 
     /**
-    * @brief clean old friend data from m_mapScene and m_friendItems
-    *
-    * @param friendsList QList item of friend information
-    */
-    void cleanOldFriendData(const QList<User *> &friendsList);
-
-    /**
     * @brief Get new tiles.
     *
     * Calculates which tiles has to be fetched. Does emit fetchImage for tiles which
@@ -207,20 +190,6 @@ private:
     int tileMaxValue(int zoomLevel);
 
     /**
-    * @brief updates data member m_friendItems from given parameter
-    *
-    * @param friendsList QList item of friend information
-    */
-    void updateFriendItemList(const QList<User *> &friendsList);
-
-    /**
-    * @brief updates data member m_friendItems values that differs from given parameter
-    *
-    * @param friendsList QList item of friend information
-    */
-    void updateFriendLocationsAndImages(const QList<User *> &friendsList);
-
-    /**
     * @brief Updates the current view rect including margins
     *
     * Calculates tiles rect in scene based on m_viewTilesGrid and
@@ -273,6 +242,13 @@ signals:
     void fetchImage(int zoomLevel, int x, int y);
 
     /**
+    * @brief Signal when friend list locations are fetched
+    *
+    * @param friendsList Friends list data
+    */
+    void friendsLocationsReady(QList<User *> &friendsList);
+
+    /**
     * @brief Signal for view location change
     *
     * @param sceneCoordinate New scene coordinates
@@ -301,7 +277,6 @@ private:
     QSize m_viewSize; ///< Current view size
     bool m_zoomedIn; ///< Flag for checking if zoomed in when zoom is finished
     int m_zoomLevel; ///< Current zoom level
-    QList<FriendLocationItem *> m_friendItems; ///< List of friendLocationItems
 };
 
 #endif // MAPENGINE_H
index a2e2aac..bb618e0 100644 (file)
@@ -49,9 +49,9 @@ MainWindow::MainWindow(QWidget *parent)
             SIGNAL(statusUpdate(QString,bool)));
 
     connect(this, SIGNAL(userLocationReady(User*)),
-            m_mapViewScreen, SLOT(userLocationReady(User*)));
+            m_mapViewScreen, SIGNAL(userLocationReady(User*)));
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
-            m_mapViewScreen, SLOT(friendsLocationsReady(QList<User*>&)));
+            m_mapViewScreen, SIGNAL(friendsLocationsReady(QList<User*>&)));
 
     connect(this, SIGNAL(userLocationReady(User*)), m_listViewScreen,
             SLOT(userDataReceived(User*)));
index fc54e3f..3326b1a 100644 (file)
@@ -42,7 +42,10 @@ MapViewScreen::MapViewScreen(QWidget *parent)
     connect(mapView, SIGNAL(viewZoomFinished()), mapEngine, SLOT(viewZoomFinished()));
     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
             this, SLOT(drawOsmLicense(int, int)));
-
+    connect(this, SIGNAL(userLocationReady(User*)),
+            mapEngine, SLOT(receiveOwnLocation(User*)));
+    connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
+            mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
 
     QHBoxLayout *mapViewLayout = new QHBoxLayout;
     //DEBUG
@@ -92,18 +95,6 @@ void MapViewScreen::searchMap()
     mapEngine->setViewLocation(QPointF(lon, lat));
 }
 
-void MapViewScreen::userLocationReady(User *user)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-    mapEngine->receiveOwnLocation(user);
-}
-
-void MapViewScreen::friendsLocationsReady(QList<User *> &friendsList)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-    mapEngine->receiveFriendLocations(friendsList);
-}
-
 void MapViewScreen::drawOsmLicense(int width, int height)
 {
     qDebug() << __PRETTY_FUNCTION__ << width << "x" << height;
index c52b04e..08b3d89 100644 (file)
@@ -53,27 +53,32 @@ private slots:
     * @brief Debug method for centering to given coordinates
     */
     void searchMap();
-    
+
     /**
-    * @brief Slot to catch signal when user location is fetched
+    * @brief Slot for drawing the Open Street Map license text
     *
-    * @param user User data
+    * @param width Width of the viewport
+    * @param height Height of the viewport
     */
-    void userLocationReady(User *user);
+    void drawOsmLicense(int width, int height);
+
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+signals:
     /**
-    * @brief Slot to catch signal when friend list locations are fetched
+    * @brief Signal when user location is fetched
     *
-    * @param friendsList Friends list data
+    * @param user User data
     */
-    void friendsLocationsReady(QList<User *> &friendsList);
+    void userLocationReady(User *user);
 
     /**
-    * @brief Slot for drawing the Open Street Map license text
+    * @brief Signal when friend list locations are fetched
     *
-    * @param width Width of the viewport
-    * @param height Height of the viewport
+    * @param friendsList Friends list data
     */
-    void drawOsmLicense(int width, int height);
+    void friendsLocationsReady(QList<User *> &friendsList);
 
 /*******************************************************************************
  * DATA MEMBERS