-
Notifications
You must be signed in to change notification settings - Fork 0
/
usermodel.cpp
63 lines (56 loc) · 1.48 KB
/
usermodel.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
#include "usermodel.h"
UserModel::UserModel(QObject *parent)
{
}
QVariant UserModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid()) {
return QVariant();
}
if(role == IdRole) {
return QVariant(users[index.row()].id);
}
if(role == NameRole) {
return QVariant(users[index.row()].name);
}
if(role == EmailRole) {
return QVariant(users[index.row()].email);
}
if(role == BalanceRole) {
return QVariant(users[index.row()].balance);
}
if(role == ActiveRole) {
return QVariant(users[index.row()].active);
}
if(role == AuditRole) {
return QVariant(users[index.row()].audit);
}
if(role == CreatedAtRole) {
return QVariant(users[index.row()].createdAt);
}
if(role == UpdatedAtRole) {
return QVariant(users[index.row()].updatedAt);
}
if(role == AvatarRole) {
return QVariant(users[index.row()].avatar);
}
return QVariant();
}
QHash<int, QByteArray> UserModel::roleNames() const {
QHash<int, QByteArray> roles;
roles[IdRole] = "id";
roles[NameRole] = "name";
roles[EmailRole] = "email";
roles[BalanceRole] = "balance";
roles[ActiveRole] = "active";
roles[AuditRole] = "audit";
roles[CreatedAtRole] = "createdAt";
roles[UpdatedAtRole] = "updatedAt";
roles[AvatarRole] = "avatar";
return roles;
}
void UserModel::activate(const int i) {
if(i < 0 || i >= users.size()) {
return;
}
}