-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_tablemodel.cpp
91 lines (77 loc) · 2.93 KB
/
utils_tablemodel.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "utils_tablemodel.h"
utils_tablemodel::utils_tablemodel()
{
}
void utils_tablemodel::setTableByFilterUser(QSqlTableModel *model, QString name, QString filter)
{
model->setTable(name);
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
userTableStyle(model);
if(!filter.isNull())
{
;
}
model->select();
}
void utils_tablemodel::setTableByFilteClassroomState(QSqlTableModel *model, QString name, QString filter)
{
model->setTable(name);
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
classroomTableStyle(model);
if(!filter.isNull())
{
model->setFilter(QObject::tr("state = '%1'").arg(filter));
}
model->select();
}
void utils_tablemodel::setTableByFilterTeacherId(QSqlTableModel *model, QString name, QString filter)
{
model->setTable(name);
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
reserveTableStyle(model);
if(!filter.isNull())
{
model->setFilter(QObject::tr("teacherId = '%1'").arg(filter));
}
model->select();
}
void utils_tablemodel::setTableByFilteReservationState(QSqlTableModel *model, QString name, QString filter)
{
model->setTable(name);
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
reserveTableStyle(model);
if(!filter.isNull())
{
model->setFilter(QObject::tr("state = '%1'").arg(filter));
}
model->select();
}
QString utils_tablemodel::getVal(QSqlTableModel *model, int row, int col)
{
return model->data(model->index(row,col)).toString();
}
void utils_tablemodel::reserveTableStyle(QSqlTableModel *model)
{
model->setHeaderData(0, Qt::Horizontal, model->tr("教室号"));
model->setHeaderData(1, Qt::Horizontal, model->tr("教师工号"));
model->setHeaderData(2, Qt::Horizontal, model->tr("教师姓名"));
model->setHeaderData(3, Qt::Horizontal, model->tr("提交时间"));
model->setHeaderData(4, Qt::Horizontal, model->tr("预约时间"));
model->setHeaderData(5, Qt::Horizontal, model->tr("当前状态"));
}
void utils_tablemodel::classroomTableStyle(QSqlTableModel *model)
{
model->setHeaderData(0, Qt::Horizontal, model->tr("教室号"));
model->setHeaderData(1, Qt::Horizontal, model->tr("教室名称"));
model->setHeaderData(2, Qt::Horizontal, model->tr("教室类型"));
model->setHeaderData(3, Qt::Horizontal, model->tr("最大容纳量"));
model->setHeaderData(4, Qt::Horizontal, model->tr("空调数量"));
model->setHeaderData(5, Qt::Horizontal, model->tr("监控数量"));
model->setHeaderData(6, Qt::Horizontal, model->tr("预约时间"));
model->setHeaderData(7, Qt::Horizontal, model->tr("当前状态"));
}
void utils_tablemodel::userTableStyle(QSqlTableModel *model)
{
model->setHeaderData(0, Qt::Horizontal, model->tr("用户名"));
model->setHeaderData(1, Qt::Horizontal, model->tr("密码"));
}