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 #include "friendmodel.h"
25 FriendModel::FriendModel(QObject *parent) :
26 QAbstractListModel(parent)
28 QHash<int, QByteArray> roles;
29 roles[AddressRole] = "address";
30 roles[CoordinateRole] = "coordinate";
31 roles[NameRole] = "name";
32 roles[MessageRole] = "message";
33 roles[ImageUrlRole] = "imageUrl";
34 roles[ImageRole] = "image";
35 roles[TimeStampRole] = "time";
36 roles[DistanceRole] = "distance";
37 roles[DistanceUnitRole] = "distanceUnit";
38 roles[UserIdRole] = "userId";
42 //void RouteModel::addSegment(const RouteSegment &segment)
43 void FriendModel::addFriend(const User &singleFriend)
45 beginInsertRows(QModelIndex(), rowCount(), rowCount());
46 /// @todo implement adding a friend
47 // m_friends << singleFriend;
51 void FriendModel::setFriends(const QList<User *>& friends)
58 void FriendModel::resetFriends()
64 int FriendModel::rowCount(const QModelIndex & parent) const {
66 return m_friends.count();
69 QVariant FriendModel::data(const QModelIndex & index, int role) const {
70 if (index.row() < 0 || index.row() > m_friends.count())
73 const User *user = m_friends[index.row()];
76 return QVariant::fromValue(user->coordinates());
78 return user->address();
84 return user->profileImageUrl();
86 return user->profileImage();
88 return user->timestamp();
93 user->distance(distance, unit);
96 case DistanceUnitRole:
100 user->distance(distance, unit);
104 return user->userId();
106 return QVariant::fromValue((void*)user);
112 FilteredFriendModel::FilteredFriendModel(QObject *parent)
113 : QSortFilterProxyModel(parent)
116 void FilteredFriendModel::setFilter(const QList<User*>& filter)
122 void FilteredFriendModel::resetFilter()
124 setFilter(QList<User*>());
127 bool FilteredFriendModel::filterAcceptsRow(int source_row, const QModelIndex & source_parent) const
129 Q_UNUSED(source_parent);
130 const QModelIndex index = sourceModel()->index(source_row, 0);
131 User* user = static_cast<User*>(sourceModel()->data(index, FriendModel::UserRole).value<void*>());
132 if (!m_filter.isEmpty())
133 return m_filter.contains(user);