if (receiveFriendsLocationsCounter == 0) {
receiveFriendsLocationsCounter++;
-
- 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);
- }
-
+ updateFriendItemList(friendsList);
}
else {
receiveFriendsLocationsCounter++;
+ updateFriendLocationsAndImages(friendsList);
+ cleanOldFriendData(friendsList);
+ updateFriendItemList(friendsList);
+ }
+}
- QList<int> currentFriendList;
+void MapEngine::updateFriendItemList(const QList<User *> &friendsList)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ qDeleteAll(m_friendItems.begin(),m_friendItems.end());
+ m_friendItems.clear();
- //finds users that have still location available.
- //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_friendItems.count(); j++) {
+ 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);
+ }
+}
- if (m_friendItems.at(j)->userId() == friendsList.at(i)->userId()) {
- currentFriendList.append(j);
+void MapEngine::updateFriendLocationsAndImages(const QList<User *> &friendsList)
+{
+ for (int i=0; i<friendsList.count(); i++) {
- if (m_friendItems.at(j)->position()
- != convertLatLonToSceneCoordinate(friendsList.at(i)->coordinates()))
- m_friendItems.at(j)->setPosition(friendsList.at(i)->coordinates());
+ for (int j=0; j<m_friendItems.count(); j++) {
- if (m_friendItems.at(j)->profileImageUrl()
- != friendsList.at(i)->profileImageUrl()) {
- m_friendItems.at(j)->setPixmap(friendsList.at(i)->profileImage());
- }
+ 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());
}
}
}
+ }
+}
- // 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);
- }
+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;
}
}
Sami Rämö - sami.ramo@ixonos.com
Jussi Laitinen - jussi.laitinen@ixonos.com
Pekka Nissinen - pekka.nissinen@ixonos.com
+ 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
* @author Sami Rämö - sami.ramo (at) ixonos.com
* @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
* @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
+* @author Ville Tiensuu - ville.tiensuu (at) ixonos.com
*/
class MapEngine : public QObject
{
* @param user User info
*/
void receiveOwnLocation(User *user);
+
/**
* @brief Slot to catch friends location data
*
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
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
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; ///< Location of friends
+ QList<FriendLocationItem *> m_friendItems; ///< List of friendLocationItems
};
#endif // MAPENGINE_H