-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasstable.cpp
More file actions
165 lines (148 loc) · 5.64 KB
/
Copy pathclasstable.cpp
File metadata and controls
165 lines (148 loc) · 5.64 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "classtable.h"
#include "classedit.h"
#include "managerboundary.h"
#include "ui_classtable.h"
classtable::classtable(ComputerClassroom* classroom,QString number,QWidget *parent)
: QWidget(parent)
, ui(new Ui::classtable)
,classroom(classroom)
,number(number)
{
ui->setupUi(this);
initTable();
auto csiList = classroom->getCSI();
for (auto it = csiList.begin(); it != csiList.end(); ++it) {
QString classname=QString::fromStdString(it->getclassname());
QString teacher=QString::fromStdString(it->getteacher());
setCourseData(it->gettime()-1,it->getweek()-1,classname,teacher);
}
}
classtable::~classtable()
{
delete ui;
}
void classtable::initTable()
{
// 设置表格为4行5列
ui->tableWidget->setRowCount(4);
ui->tableWidget->setColumnCount(5);
// 设置表头
QStringList headers;
headers << "周一" << "周二" << "周三" << "周四" << "周五";
ui->tableWidget->setHorizontalHeaderLabels(headers);
// 设置行标题(时间段)
QStringList rowHeaders;
rowHeaders << "上午第一节" << "上午第二节" << "下午第一节" << "下午第二节";
ui->tableWidget->setVerticalHeaderLabels(rowHeaders);
// 设置表格属性
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); // 禁止编辑
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
// 设置表格样式
ui->tableWidget->setStyleSheet(
"QTableWidget {"
" gridline-color: #cccccc;"
" background-color: #f5f5f5;"
"}"
"QTableWidget::item {"
" border: 1px solid #cccccc;"
" padding: 5px;"
" color: black;"
"}"
"QHeaderView::section {"
" background-color: #e0e0e0;"
" border: 1px solid #cccccc;"
" padding: 5px;"
" font-weight: bold;"
" color: black;"
"}"
);
}
void classtable::setCourseData(int row, int col, const QString &courseName,const QString &teacher)
{
if (row < 0 || row >= ui->tableWidget->rowCount() ||
col < 0 || col >= ui->tableWidget->columnCount()) {
return; // 检查索引是否有效
}
// 构建课程信息
QString courseInfo = courseName;
if (!teacher.isEmpty()) {
courseInfo += "\n教师: " + teacher;
}
// 创建单元格项并设置数据
QTableWidgetItem *item = new QTableWidgetItem(courseInfo);
// 设置文本对齐方式
item->setTextAlignment(Qt::AlignCenter);
// 设置单元格字体
QFont font = item->font();
font.setPointSize(10);
item->setFont(font);
// 设置单元格到表格
ui->tableWidget->setItem(row, col, item);
}
void classtable::clearTable()
{
// 清空表格内容
for (int row = 0; row < ui->tableWidget->rowCount(); ++row) {
for (int col = 0; col < ui->tableWidget->columnCount(); ++col) {
QTableWidgetItem *item = ui->tableWidget->item(row, col);
if (item) {
delete item;
ui->tableWidget->setItem(row, col, nullptr);
}
}
}
}
void classtable::on_pushButton_2_clicked()
{
classedit *a=new classedit(classroom,number);
this->close();
a->show();
}
void classtable::on_pushButton_3_clicked()
{
if(number=="一"){
QString title = QString::fromUtf8("<html><head/><body><p align=\"center\"><span style=\" font-size:30pt;\">第一机房管理系统</span></p></body></html>");
managerboundary *boundary = new managerboundary(classroom,number);
boundary->setlabletitle(title);
this->close();
boundary->show();
}
if(number=="二"){
QString title = QString::fromUtf8("<html><head/><body><p align=\"center\"><span style=\" font-size:30pt;\">第二机房管理系统</span></p></body></html>");
managerboundary *boundary = new managerboundary(classroom,number);
boundary->setlabletitle(title);
this->close();
boundary->show();
}
if(number=="三"){
QString title = QString::fromUtf8("<html><head/><body><p align=\"center\"><span style=\" font-size:30pt;\">第三机房管理系统</span></p></body></html>");
managerboundary *boundary = new managerboundary(classroom,number);
boundary->setlabletitle(title);
this->close();
boundary->show();
}
if(number=="四"){
QString title = QString::fromUtf8("<html><head/><body><p align=\"center\"><span style=\" font-size:30pt;\">第四机房管理系统</span></p></body></html>");
managerboundary *boundary = new managerboundary(classroom,number);
boundary->setlabletitle(title);
this->close();
boundary->show();
}
if(number=="五"){
QString title = QString::fromUtf8("<html><head/><body><p align=\"center\"><span style=\" font-size:30pt;\">第五机房管理系统</span></p></body></html>");
managerboundary *boundary = new managerboundary(classroom,number);
boundary->setlabletitle(title);
this->close();
boundary->show();
}
if(number=="六"){
QString title = QString::fromUtf8("<html><head/><body><p align=\"center\"><span style=\" font-size:30pt;\">第六机房管理系统</span></p></body></html>");
managerboundary *boundary = new managerboundary(classroom,number);
boundary->setlabletitle(title);
this->close();
boundary->show();
}
}