Merge branch 'master' into locationlistview
[situare] / src / ui / listview.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jussi Laitinen - jussi.laitinen@ixonos.com
6
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.
10
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.
15
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,
19    USA.
20 */
21
22 #ifndef LISTVIEW_H
23 #define LISTVIEW_H
24
25 #include <QListWidget>
26
27 class GeoCoordinate;
28 class ListItem;
29
30 /**
31 * @brief View for ListItems.
32 *
33 * ListView is used to show ListItems in list view. Items can be added, removed or
34 * filtered.
35 */
36 class ListView : public QListWidget
37 {
38     Q_OBJECT
39
40 public:
41     /**
42     * @brief Constructor.
43     *
44     * @param parent QWidget
45     */
46     ListView(QWidget *parent = 0);
47
48 /******************************************************************************
49 * MEMBER FUNCTIONS AND SLOTS
50 ******************************************************************************/
51 public:
52     /**
53     * @brief Add item to view and item list.
54     *
55     * @param key user ID
56     * @param item item to add to view and list
57     */
58     void addListItem(const QString &key, ListItem *item);
59
60     /**
61     * @brief Adds item to view.
62     *
63     * @param item FriendListItem
64     */
65     void addListItemToView(ListItem *item);
66
67     /**
68     * @brief Clear unused items from view.
69     *
70     * Clears items which are not in user ID's list from the view and items list.
71     *
72     * @param userIDs list of new user ID's.
73     */
74     void clearUnused(const QStringList &userIDs);
75
76     /**
77     * @brief Clears filtering from list.
78     *
79     * Shows all items.
80     */
81     void clearFilter();
82
83     /**
84     * @brief Clears list.
85     *
86     * Items are removed from view and item list.
87     */
88     void clearList();
89
90     /**
91     * @brief Checks if view contains item with userID.
92     *
93     * @param userID user's ID
94     * @return true if view contains item, false otherwise
95     */
96     bool contains(const QString &userID);
97
98     /**
99     * @brief Sets filter to list.
100     *
101     * Hide all items that are not in the userIDs list.
102     *
103     * @param userIDs user ID's to items that are shown
104     */
105     void filter(const QList<QString> &userIDs);
106
107     /**
108     * @brief Takes item from view.
109     *
110     * Item is not deleted.
111     *
112     * @param userID user's ID
113     * @return ListItem
114     */
115     ListItem *takeListItemFromView(const QString &userID);
116
117     /**
118     * @brief Returns ListItem with userID.
119     *
120     * @param userID user's ID
121     * @return ListItem
122     */
123     ListItem *listItem(const QString &userID);
124
125 protected slots:
126     /**
127     * @brief Slot for list item clicked.
128     *
129     * Toggles items selection state and emits listItemClicked signal.
130     */
131     virtual void listItemClicked(QListWidgetItem *item);
132
133 /******************************************************************************
134 * SIGNALS
135 ******************************************************************************/
136 signals:
137     /**
138     * @brief Signal is emitted when list item is clicked.
139     *
140     * @param coordinates item's coordinates
141     */
142     void listItemClicked(const GeoCoordinate &coordinates);
143
144 /*******************************************************************************
145  * DATA MEMBERS
146  ******************************************************************************/
147 private:
148     ListItem *m_previousItem;               ///< Previously selected item
149     QHash<QString, ListItem *> m_listItems; ///< List of items in this view. Key = user ID
150 };
151
152 #endif // LISTVIEW_H