Basic Functionality ready for updating own and friends location on the
authorVille Tiensuu <ville.tiensuu@ixonos.com>
Wed, 5 May 2010 09:32:22 +0000 (12:32 +0300)
committerVille Tiensuu <ville.tiensuu@ixonos.com>
Wed, 5 May 2010 09:32:22 +0000 (12:32 +0300)
map

src/map/friendlocationitem.cpp
src/map/friendlocationitem.h
src/map/mapengine.cpp
src/map/mapengine.h

index 39027ce..58fbd6e 100644 (file)
@@ -59,3 +59,14 @@ void FriendLocationItem::setUserId(const QString &userId)
 {
     m_userId = userId;
 }
+
+void FriendLocationItem::setProfileImageUrl(const QUrl &url)
+{
+    m_profileImageUrl = url;
+}
+
+QUrl FriendLocationItem::profileImageUrl() const
+{
+    return m_profileImageUrl;
+}
+
index c4a6b15..ad99a9e 100644 (file)
 
 
 #include <QObject>
+#include <QUrl>
 
 #include "baselocationitem.h"
 
+
+
 /**
 * @brief Class that shows friends location icons on the map
 *
@@ -69,6 +72,9 @@ public:
     */
     void setUserId(const QString &userId);
 
+    void setProfileImageUrl(const QUrl &url);
+    QUrl profileImageUrl() const;
+
 signals:
 
    /**
@@ -89,6 +95,7 @@ protected:
 
 private:
     QString m_userId; ///< Friends user ID
+    QUrl m_profileImageUrl; ///< Friends Facebook profile image URL
 };
 
 #endif // FRIENDLOCATIONITEM_H
index d2089d8..3bf699b 100644 (file)
@@ -60,8 +60,8 @@ MapEngine::MapEngine(QObject *parent)
 
 MapEngine::~MapEngine()
 {
-    qDeleteAll(m_friendsLocations.begin(),m_friendsLocations.end());
-    m_friendsLocations.clear();
+    qDeleteAll(m_friendItems.begin(),m_friendItems.end());
+    m_friendItems.clear();
 }
 
 void MapEngine::init()
@@ -314,74 +314,83 @@ QPoint MapEngine::convertLatLonToSceneCoordinate(QPointF latLonCoordinate)
 
 void MapEngine::receiveOwnLocation(User *user)
 {
-   // qDebug() << __PRETTY_FUNCTION__;
-    m_ownLocation->setPosition(user->coordinates());
-    m_mapScene->addItem(m_ownLocation);
+    qDebug() << __PRETTY_FUNCTION__;
+
+    static int receiveOwnLocationCounter = 0;
+
+    if  (receiveOwnLocationCounter == 0) {
+        receiveOwnLocationCounter++;
+
+        m_ownLocation->setPosition(user->coordinates());
+        m_mapScene->addItem(m_ownLocation);
+    }
+
+    else {
+        receiveOwnLocationCounter++;
+
+        if (m_ownLocation->position()
+            != convertLatLonToSceneCoordinate(user->coordinates())) {
+            m_ownLocation->setPosition(user->coordinates());
+        }
+    }
 }
 
 void MapEngine::receiveFriendLocations(QList<User *> &friendsList)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    //qDeleteAll(m_friendsLocations.begin(), m_friendsLocations.end());
-    //m_friendsLocations.clear();
-
-
-    static int friendReceiveCounter = 0;
 
-    qDebug() << friendReceiveCounter << "TIME IN THIS FUNCTION";
+    static int receiveFriendsLocationsCounter = 0;
 
-    if (friendReceiveCounter == 0){
-        friendReceiveCounter++;
+    if (receiveFriendsLocationsCounter == 0) {
+        receiveFriendsLocationsCounter++;
 
-        for(int i=0; i<friendsList.count(); i++) {
+        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_friendsLocations.append(friendLocation);
+            m_friendItems.append(friendLocation);
             m_mapScene->addItem(friendLocation);
         }
 
     }
 
     else {
-        friendReceiveCounter++;
-        QList<int> currentFriendList;
+        receiveFriendsLocationsCounter++;
 
-        //remember to check Qt style about inner loops
+        QList<int> currentFriendList;        
 
         //finds users that have still location available.
-        //stores their index in to currentFriendlist
-        //check if their location is changed
-        //set new location to changed items
-        for(int i=0; i<friendsList.count(); i++) {
-            qDebug() << "friendsList Count : " << friendsList.count();
+        //stores their index in to currentFriendlist       
+        //set new location if it is changed
+        //set new profile picture if it is chenged
+        for (int i=0; i<friendsList.count(); i++) {
 
-            for(int j=0; j<m_friendsLocations.count(); j++){
-                qDebug() << "m_friendsLocations Count : " << m_friendsLocations.count();
+            for (int j=0; j<m_friendItems.count(); j++) {
 
-                if (m_friendsLocations.at(j)->userId() == friendsList.at(i)->userId()){
-                    currentFriendList.append(j);
-                    qDebug() << "i: " << i;
-                    qDebug() << "j: " << j;
+                if (m_friendItems.at(j)->userId() == friendsList.at(i)->userId()) {
+                    currentFriendList.append(j);                   
 
-                    if (m_friendsLocations.at(j)->position()
-                        != convertLatLonToSceneCoordinate(friendsList.at(i)->coordinates())){
+                    if (m_friendItems.at(j)->position()
+                        != convertLatLonToSceneCoordinate(friendsList.at(i)->coordinates()))
+                        m_friendItems.at(j)->setPosition(friendsList.at(i)->coordinates());
 
-                        m_friendsLocations.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());
                     }
                 }
             }
         }
 
-        // now numbers that are not on the currentFriendList needs to be removed from scene.
-        // users that are not available are also removed from m_friendLocations
-        int m_friendsLocationsOriginalCount = m_friendsLocations.count();
-        for(int i=0; i<m_friendsLocationsOriginalCount; i++){
-            if(currentFriendList.contains(i) == false){
-                m_mapScene->removeItem(m_friendsLocations.at(i));
-                m_friendsLocations.removeAt(i);
+        // clean scene and m_friendItems list:
+        // (remove such user who don't has logged out from siture)
+        int m_friendItemsOriginalCount = m_friendItems.count();
+        for (int i=0; i<m_friendItemsOriginalCount; i++) {
+            if (currentFriendList.contains(i) == false) {
+                m_mapScene->removeItem(m_friendItems.at(i));
+                m_friendItems.removeAt(i);
             }
         }
     }
index 15bb3ef..3b7c598 100644 (file)
@@ -274,7 +274,7 @@ 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_friendsLocations; ///< Location of friends
+    QList<FriendLocationItem *> m_friendItems; ///< Location of friends
 };
 
 #endif // MAPENGINE_H