-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainscreen.h
More file actions
133 lines (117 loc) · 4 KB
/
mainscreen.h
File metadata and controls
133 lines (117 loc) · 4 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#ifndef MAINSCREEN_H
#define MAINSCREEN_H
#include <qqml.h>
#include <QObject>
#include <QAbstractTableModel>
#include <QJsonArray>
#include <QJsonObject>
class TableModel : public QAbstractTableModel
{
Q_OBJECT
QML_ELEMENT
QML_ADDED_IN_MINOR_VERSION(1)
public:
TableModel() {
listStudents.push_back(QJsonObject {
{"ma", "123"},
{"ten", "Nguyễn Văn A"},
{"khoa", "Điện - điện tử"},
{"nganh", "Công nghệ kỹ thuật máy tính"},
{"gioitinh", "nam"}
});
listStudents.push_back(QJsonObject {
{"ma", "124"},
{"ten", "Nguyễn Văn B"},
{"khoa", "Điện - điện tử"},
{"nganh", "Công nghệ kỹ thuật máy tính"},
{"gioitinh", "nam"}
});
listStudents.push_back(QJsonObject {
{"ma", "125"},
{"ten", "Nguyễn Văn C"},
{"khoa", "Điện - điện tử"},
{"nganh", "Hệ thống nhúng và IoT"},
{"gioitinh", "nam"}
});
listStudents.push_back(QJsonObject {
{"ma", "126"},
{"ten", "Nguyễn Văn D"},
{"khoa", "Điện - điện tử"},
{"nganh", "Hệ thống nhúng và IoT"},
{"gioitinh", "nam"}
});
listStudents.push_back(QJsonObject {
{"ma", "127"},
{"ten", "Nguyễn Văn E"},
{"khoa", "Điện - điện tử"},
{"nganh", "Hệ thống nhúng và IoT"},
{"gioitinh", "nam"}
});
}
int rowCount(const QModelIndex & = QModelIndex()) const override
{
return listStudents.size() + 1;
}
int columnCount(const QModelIndex & = QModelIndex()) const override
{
return 6;
}
QVariant data(const QModelIndex &index, int role) const override
{
// qDebug() << "role: " << role;
switch (role) {
case 0:
if (index.column() == 0 && index.row() == 0) {
return "Index";
} else if (index.column() == 1 && index.row() == 0) {
return "Mã SV";
} else if (index.column() == 2 && index.row() == 0) {
return "Tên SV";
} else if (index.column() == 3 && index.row() == 0) {
return "Khoa";
} else if (index.column() == 4 && index.row() == 0) {
return "Ngành";
} else if (index.column() == 5 && index.row() == 0) {
return "Giới tính";
} else if (index.column() == 0) {
return QString::number(index.row());
} else if (index.column() == 1) {
return listStudents.at(index.row() - 1).toObject()["ma"].toString();
} else if (index.column() == 2) {
return listStudents.at(index.row() - 1).toObject()["ten"].toString();
} else if (index.column() == 3) {
return listStudents.at(index.row() - 1).toObject()["khoa"].toString();
} else if (index.column() == 4) {
return listStudents.at(index.row() - 1).toObject()["nganh"].toString();
} else if (index.column() == 5) {
return listStudents.at(index.row() - 1).toObject()["gioitinh"].toString();
}
return "Empty";
default:
break;
}
return QVariant();
}
QHash<int, QByteArray> roleNames() const override
{
return {
{0, "display"}
};
}
private:
QJsonArray listStudents;
};
class MainScreen : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList listKhoa MEMBER m_listKhoa NOTIFY listKhoaChanged)
public:
MainScreen();
public slots:
QStringList getListNganh(QString khoa);
signals:
void listKhoaChanged(QStringList);
private:
QStringList m_listKhoa;
};
#endif // MAINSCREEN_H