Updated tests cases matching the new tabs
[situare] / src / map / frienditemshandler.h
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Sami Rämö - sami.ramo@ixonos.com
6         Henri Lampela - henri.lampela@ixonos.com
7
8     Situare is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License
10     version 2 as published by the Free Software Foundation.
11
12     Situare is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with Situare; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20     USA.
21 */
22
23
24 #ifndef FRIENDITEMSHANDLER_H
25 #define FRIENDITEMSHANDLER_H
26
27 #include <QLinkedList>
28 #include <QObject>
29
30 class BaseLocationItem;
31 class FriendGroupItem;
32 class FriendLocationItem;
33 class MapScene;
34 class User;
35
36 /**
37  * @brief Handler for friend and friend group items
38  *
39  * Handles all friend map items. Colliding items and groups are grouped. All items are owned
40  * by MapScene.
41  *
42  * @author Sami Rämö - sami.ramo@ixonos.com
43  * @author Ville Tiensuu - ville.tiensuu@ixonos.com
44  */
45 class FriendItemsHandler : public QObject
46 {
47     Q_OBJECT
48
49 public:
50     /**
51       * @brief Constructor
52       *
53       * @param mapScene MapScene object
54       * @param parent Parent QObject
55       */
56     FriendItemsHandler(MapScene *mapScene, QObject *parent = 0);
57
58 /*******************************************************************************
59  * MEMBER FUNCTIONS AND SLOTS
60  ******************************************************************************/
61 private:
62     /**
63       * @brief Add new FriendLocationItem
64       *
65       * New FriendLocationItem is created, values are set and item is added to map.
66       * Item is also added to m_friendItems list.
67       *
68       * @param friendData Data for new friend
69       */
70     void addFriendItem(User *friendData);
71
72     /**
73       * @brief Group colliding friends
74       *
75       * Call checkFriendForCollidingFriends() for all visible FriendLocationItem items.
76       */
77     void checkAllFriendsForCollidingFriends();
78
79     /**
80       * @brief Check single FriendLocationItem for colliding FriendLocationItem items
81       *
82       * Check FriendLocationItem against another visible FriendLocationItem items. If collision is
83       * found, then new FriendGroupItem is made and colliding FriendLocationItem items are joined
84       * to this new FriendGroupItem.
85       *
86       * @param item FriendLocationItem to be checked
87       */
88     void checkFriendForCollidingFriends(FriendLocationItem *item);
89
90     /**
91     * @brief clean old friend data from m_mapScene and m_friendItems
92     *
93     * @param friendsList QList item of friend information
94     */
95     void cleanOldFriendData(const QList<User *> &friendsList);
96
97     /**
98     * @brief Check if items collide
99     *
100     * Does check if items sceneTransformedBoundingRect() does intersect. If item1's rect is max
101     * half of the rect width from the vertical limits of the map (from inside), then rect is
102     * translated to opposite side of the map and intersections are tested there too.
103     *
104     * @param item1 First item
105     * @param item2 Secont item
106     * @return True if collision was found, otherwise false
107     */
108     bool collides(BaseLocationItem *item1, BaseLocationItem *item2);
109
110     /**
111       * @brief Delete FriendLocationItem
112       *
113       * Drops item from all groups, removes it from scene and deletes the item.
114       *
115       * @param item Item to be deleted
116       */
117     void deleteFriendItem(FriendLocationItem *item);
118
119     /**
120     * @brief Destructs all current group items
121     */
122     void destructGroups();
123
124     /**
125       * @brief Update FriendLocationItem data
126       *
127       * Position and image are updated.
128       *
129       * @param friendItem Item to be updated
130       * @param friendData New data for the item
131       */
132     void updateFriendItem(FriendLocationItem *friendItem, User *friendData);
133
134     /**
135     * @brief updates data member m_friendItems from given parameter
136     *
137     * @param friendsList QList item of friend information
138     */
139     void updateFriendItemList(const QList<User *> &friendsList);
140
141     /**
142     * @brief updates data member m_friendItems values that differs from given parameter
143     *
144     * @param friendsList QList item of friend information
145     */
146     void updateFriendLocationsAndImages(const QList<User *> &friendsList);
147
148 private slots:
149
150     /**
151     * @brief Slot updating friend item's profile image
152     *
153     * @param user Friend
154     */
155     void friendImageReady(User *user);
156
157     /**
158     * @brief Slot for upgrading friend items and groups
159     *
160     * Does add and/or remove FriendLocationItem items if there are new friends
161     * or old ones deleted in the given list. Remaining FriensLocationItems are updated.
162     *
163     * @param friendsList QList item of friend information
164     */
165     void friendListUpdated(QList<User *> &friendsList);
166
167     /**
168       * @brief Destroys all current groups and runs grouping again
169       *
170       * Calls destructGroups() and checkAllFriendsForCollidingFriends().
171       *
172       * @param zoomLevel Current view zoom level, used for friend item rect scaling
173       */
174     void refactorFriendItems(int zoomLevel);
175
176 /*******************************************************************************
177  * SIGNALS
178  ******************************************************************************/
179 signals:
180     /**
181     * @brief Signal is emitted when location item is clicked.
182     *
183     * @param userIDs list of friends user IDs in the group
184     */
185     void locationItemClicked(const QList<QString> &userIDs);
186
187 /*******************************************************************************
188  * DATA MEMBERS
189  ******************************************************************************/
190 private:
191     QLinkedList<FriendGroupItem *> m_friendGroupItems; ///< All FriendGroupItem items
192     QLinkedList<FriendLocationItem *> m_friendItems; ///< List of friendLocationItems
193     MapScene *m_mapScene; ///< Pointer to MapScene
194     int m_zoomLevel; ///< Current view zoom level used for calculation of items bounding rect
195 };
196
197 #endif // FRIENDITEMSHANDLER_H