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()
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);
}
}
}