9ec88fb8d0a0618287b89cd141fd6ecbf06d8499
[situare] / src / user / friendmodel.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
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
23 #ifndef FRIENDMODEL_H
24 #define FRIENDMODEL_H
25
26 #include <QAbstractListModel>
27 #include <QSortFilterProxyModel>
28
29 #include "user.h"
30
31 class FriendModel : public QAbstractListModel
32 {
33     Q_OBJECT
34
35 public:
36     enum FriendRoles {
37         AddressRole = Qt::UserRole + 1,
38         CoordinateRole,
39         NameRole,
40         MessageRole,
41         ImageUrlRole,
42         ImageRole,
43         TimeStampRole,
44         DistanceRole,
45         DistanceUnitRole,
46         UserIdRole,
47         UserRole
48     };
49
50     explicit FriendModel(QObject *parent = 0);
51     void addFriend(const User &singleFriend);
52     void setFriends(const QList<User *>& friends);
53     void resetFriends();
54
55     int rowCount(const QModelIndex & parent = QModelIndex()) const;
56     QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
57
58 private:
59     QList<User *> m_friends;
60 };
61
62 class FilteredFriendModel : public QSortFilterProxyModel
63 {
64     Q_OBJECT
65
66 public:
67     explicit FilteredFriendModel(QObject *parent = 0);
68
69     void setFilter(const QList<User*>& filter);
70
71     Q_INVOKABLE void resetFilter();
72
73 protected:
74     virtual bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const;
75
76 private:
77     QList<User *> m_filter;
78 };
79
80 #endif // FRIENDMODEL_H