-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontactmanager.cpp
52 lines (44 loc) · 1.19 KB
/
contactmanager.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
52
#include "contactmanager.h"
ContactModel::ContactModel(QObject *parent) :
QAbstractListModel(parent)
{
contactList = new QList<QContact>();
}
int ContactModel::rowCount ( const QModelIndex & parent ) const
{
return contactList->count();
}
QVariant ContactModel::data ( const QModelIndex & index, int role ) const
{
switch(role)
{
case Qt::DisplayRole:
QString name;
name+=contactList->at(index.row()).detail<QContactName>().firstName();
if(name.length()>0)
name+=" ";
name+=contactList->at(index.row()).detail<QContactName>().lastName();
return name;
}
return QVariant();
}
void ContactModel::readContacts(QContactManager* cm)
{
QList<QContact> allContacts = cm->contacts();
emit beginInsertRows(QModelIndex(),0,allContacts.count());
foreach(QContact contact,allContacts)
{
contactList->append(contact);
}
emit endInsertRows();
}
QContact ContactModel::getContactAt(int index)
{
if(index >= contactList->count() || index < 0)
return QContact();
return contactList->at(index);
}
QList<QContact> ContactModel::getContacts()
{
return *contactList;
}