2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 #ifndef FRIENDITEMSHANDLER_H
24 #define FRIENDITEMSHANDLER_H
26 #include <QLinkedList>
29 #include "user/user.h"
31 class FriendGroupItem;
32 class FriendLocationItem;
36 * @brief Handler for friend and friend group items
38 * Handles all friend map items. Colliding items and groups are grouped. All items are owned
41 * @author Sami Rämö - sami.ramo@ixonos.com
42 * @author Ville Tiensuu - ville.tiensuu@ixonos.com
44 class FriendItemsHandler : public QObject
52 * @param mapScene MapScene object
53 * @param parent Parent QObject
55 FriendItemsHandler(MapScene *mapScene, QObject *parent = 0);
57 /*******************************************************************************
58 * MEMBER FUNCTIONS AND SLOTS
59 ******************************************************************************/
62 * @brief Add new FriendLocationItem
64 * New FriendLocationItem is created, values are set and item is added to map.
65 * Item is also added to m_friendItems list.
67 * @param friendData Data for new friend
69 void addFriendItem(User *friendData);
72 * @brief Group colliding friends
74 * Call checkFriendForCollidingFriends() for all visible FriendLocationItem items.
76 void checkAllFriendsForCollidingFriends();
79 * @brief Join friends to colliding group
81 * Call checkGroupForCollidingFriends() for all FriendGroupItem items.
83 void checkAllGroupsForCollidingFriends();
86 * @brief Check single FriendLocationItem for colliding FriendLocationItem items
88 * Check FriendLocationItem against another visible FriendLocationItem items. If collision is
89 * found, then new FriendGroupItem is made and colliding FriendLocationItem items are joined
90 * to this new FriendGroupItem.
92 * @param item FriendLocationItem to be checked
94 void checkFriendForCollidingFriends(FriendLocationItem *item);
97 * @brief Check single FriendGroupItem for colliding FriendLocationItem
99 * Check FriendGroupItem against all visible FriendLocationItem items. Colliding
100 * FriendLocationItem items are joiden to given FriendGroupItem.
102 * @param group FriendGroupItem to be checked
104 void checkGroupForCollidingFriends(FriendGroupItem *group);
107 * @brief Check single FriendGroupItem for colliding FriendGroupItem items
109 * Colliding FriendGroupItem items are merged. Item given as parameter remains and colliding
110 * items are deleted after their friend items are merged to remaining group.
112 * @param group FriendGroupItem to be checked
114 void checkGroupForCollidingGroups(FriendGroupItem *group);
117 * @brief clean old friend data from m_mapScene and m_friendItems
119 * @param friendsList QList item of friend information
121 void cleanOldFriendData(const QList<User *> &friendsList);
124 * @brief Delete FriendLocationItem
126 * Drops item from all groups, removes it from scene and deletes the item.
128 * @param item Item to be deleted
130 void deleteFriendItem(FriendLocationItem *item);
133 * @brief Drop FriendLocationItem from all FriendGroupItem groups
135 * @param item Item to be dropped.
137 void dropFriendFromAllGroups(FriendLocationItem *item);
140 * @brief Drop all FriendLocationItem items, which are out of FriendGroupItem boundaries,
141 * from all FriendGroupItem items.
143 void dropOutOfGroupFriends();
146 * @brief Merge all colliding groups
148 * Calls checkGroupForCollidingGroups() for all FriendGroupItem items.
150 void mergeCollidingGroups();
153 * @brief Update FriendLocationItem data
155 * Position and image are updated.
157 * @param friendItem Item to be updated
158 * @param friendData New data for the item
160 void updateFriendItem(FriendLocationItem *friendItem, User *friendData);
163 * @brief updates data member m_friendItems from given parameter
165 * @param friendsList QList item of friend information
167 void updateFriendItemList(const QList<User *> &friendsList);
170 * @brief updates data member m_friendItems values that differs from given parameter
172 * @param friendsList QList item of friend information
174 void updateFriendLocationsAndImages(const QList<User *> &friendsList);
178 * @brief Slot for upgrading friend items and groups
180 * Does add and/or remove FriendLocationItem items if there are new friends
181 * or old ones deleted in the given list. Remaining FriensLocationItems are updated.
183 * @param friendsList QList item of friend information
185 void friendListUpdated(QList<User *> &friendsList);
188 * @brief Re-factors all FriendLocationItem and FriendGroupItem items.
190 * Calls mergeCollidingGroups(), dropOutOfGroupFriends(), checkAllGroupsForCollidingFriends()
191 * and checkAllFriendsForCollidingFriends().
193 * @param zoomLevel Current view zoom level
195 void refactorFriendItems(int zoomLevel);
197 /*******************************************************************************
199 ******************************************************************************/
202 * @brief Signal is emitted when location item is clicked.
204 * @param userIDs list of friends user IDs in the group
206 void locationItemClicked(const QList<QString> &userIDs);
208 /*******************************************************************************
210 ******************************************************************************/
212 QLinkedList<FriendGroupItem *> m_friendGroupItems; ///< All FriendGroupItem items
213 QLinkedList<FriendLocationItem *> m_friendItems; ///< List of friendLocationItems
214 MapScene *m_mapScene; ///< Pointer to MapScene
215 int m_zoomLevel; ///< Current view zoom level used for calculation of items bounding rect
218 #endif // FRIENDITEMSHANDLER_H