-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdelegateslistmodel.cpp
72 lines (59 loc) · 1.39 KB
/
delegateslistmodel.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "delegateslistmodel.h"
DelegatesListModel::DelegatesListModel(QObject *parent)
: QAbstractListModel(parent)
{
}
DelegatesListModel::~DelegatesListModel()
{
clearDelegateAccounts();
}
int DelegatesListModel::rowCount(const QModelIndex &parent) const
{
return delegateAccounts.size();
}
QVariant DelegatesListModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::UserRole)
return QVariant::fromValue(delegateAccounts.at(index.row()));
else if (role == Qt::DisplayPropertyRole)
return QVariant::fromValue(pageNum);
else
return QVariant();
}
void DelegatesListModel::setDelegateAccounts(const QVector<DelegateAccount>& accounts)
{
clearDelegateAccounts();
for (int i = 0; i < accounts.size(); i++)
{
auto pAccount = new DelegateAccount;
*pAccount = accounts.at(i);
delegateAccounts.push_back(pAccount);
}
refresh();
}
void DelegatesListModel::setPageNum(int num)
{
pageNum = num;
}
void DelegatesListModel::clearDelegateAccounts()
{
for (size_t i = 0; i < delegateAccounts.size(); i++)
{
delete delegateAccounts.at(i);
}
delegateAccounts.clear();
}
void DelegatesListModel::refresh()
{
beginResetModel();
endResetModel();
}
DelegateAccount* DelegatesListModel::getDelegateAccount(int accountId)
{
for (int i = 0; i < delegateAccounts.size(); i++)
{
if (delegateAccounts.at(i)->id == accountId)
return delegateAccounts.at(i);
}
return nullptr;
}