This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserModel.h
55 lines (42 loc) · 1.48 KB
/
UserModel.h
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
#ifndef USERMODEL_H
#define USERMODEL_H
#include <QAbstractTableModel>
class UserModel : public QAbstractTableModel {
Q_OBJECT
public:
UserModel(const QList<QPair<QString, QString>> &users, QObject *parent = nullptr)
: QAbstractTableModel(parent), _users(users) {}
int rowCount(const QModelIndex &parent = QModelIndex()) const override {
return _users.size();
}
int columnCount(const QModelIndex &parent = QModelIndex()) const override {
return 2;
}
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override {
if (!index.isValid() || role != Qt::DisplayRole)
return QVariant();
const auto &item = _users[index.row()];
if (index.column() == 0)
return item.first; // Username
else if (index.column() == 1) {
if(item.second.length() == 64) return tr("Hashed Password");
else return item.second; // Hashed password
}
return QVariant();
}
QVariant headerData(int section, Qt::Orientation orientation, int role) const override {
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal) {
switch (section) {
case 0: return tr("Username");
case 1: return tr("Password");
default: return QVariant();
}
}
return QVariant();
}
private:
QList<QPair<QString, QString>> _users;
};
#endif