/
fbfriendsmodel.cpp
51 lines (43 loc) · 1.04 KB
/
fbfriendsmodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "fbfriendsmodel.h"
#include <QDebug>
FBFriendsModel::FBFriendsModel(QObject *parent) :
QAbstractListModel(parent)
{
friendList = new QList<Friend*>();
}
int FBFriendsModel::rowCount ( const QModelIndex & parent ) const
{
return friendList->count();
}
QVariant FBFriendsModel::data ( const QModelIndex & index, int role ) const
{
Friend* fr = friendList->at(index.row());
switch(role)
{
case Qt::DisplayRole:
return fr->getFirstName()+ " " + fr->getLastName();
break;
}
return QVariant();
}
void FBFriendsModel::add(QList<Friend*>* list)
{
int i=0;
emit beginInsertRows(QModelIndex(),friendList->count(),
friendList->count()+list->count()-1);
foreach(Friend* f,*list)
{
friendList->append(f);
}
emit endInsertRows();
}
Friend* FBFriendsModel::getFriendAt(int index)
{
if(index > friendList->count())
return NULL;
return friendList->at(index);
}
QList<Friend*> FBFriendsModel::getFriends()
{
return *friendList;
}