diff --git a/source/fun.h b/source/fun.h index 30103f0..a2f5b7e 100644 --- a/source/fun.h +++ b/source/fun.h @@ -1,6 +1,13 @@ +/** + * Name: fun.h + * User: L.Laddie + * Function: 常用自定义函数 + */ + #ifndef FUN_H #define FUN_H +#include #include "include.h" //泛型排序算法 @@ -54,7 +61,7 @@ namespace Sort { } } if(flag){ - break; +// return; } } } diff --git a/source/mainwindow_admin.cpp b/source/mainwindow_admin.cpp index 8bf5dc1..04583f1 100644 --- a/source/mainwindow_admin.cpp +++ b/source/mainwindow_admin.cpp @@ -27,16 +27,11 @@ MainWindow_admin::MainWindow_admin(Envir_widget* envir_widget, QWidget *parent) m_envir_widget(envir_widget), ui(new Ui::MainWindow_admin) { - ui_label_status = new QLabel(); - ui_label_time = new QLabel(); - m_timer_status = new QTimer(this); - m_info_course_widget = new Information_course(this); - m_info_user_widget = new Information_user(this); ui->setupUi(this); setFixedSize(800, 500); //禁止更改大小 - creatAction(); //链接信号与槽 - initTable(); //初始化表格信息 + initActivex(); //初始化控件信息 + creatAction(); //链接信号与槽 initStatusBar(); //初始化状态栏 } @@ -61,6 +56,32 @@ void MainWindow_admin::setUser(Admin* user) this->m_user = user; } +//初始化控件信息 +void MainWindow_admin::initActivex() +{ + ui_label_status = new QLabel(); + ui_label_time = new QLabel(); + m_timer_status = new QTimer(this); + m_info_course_widget = new Information_course(this); + m_info_user_widget = new Information_user(this); + + ui_course_model_o = new QStandardItemModel(); + ui->tableView_course_o->setModel(ui_course_model_o); + + ui_course_model_e = new QStandardItemModel(); + ui->tableView_course_e->setModel(ui_course_model_e); + + ui_student_model = new QStandardItemModel(); + ui->tableView_student->setModel(ui_student_model); + + ui_teacher_model = new QStandardItemModel(); + ui->tableView_teacher->setModel(ui_teacher_model); + + ui_admin_model = new QStandardItemModel(); + ui->tableView_admin->setModel(ui_admin_model); +} + +//初始化状态栏信息 void MainWindow_admin::initStatusBar() { ui_label_time->setAlignment(Qt::AlignRight); @@ -70,6 +91,7 @@ void MainWindow_admin::initStatusBar() ui->statusbar->setStyleSheet(QString("QStatusBar::item{border: 0px}, *{font-size : 8px}")); } +//定时更新状态栏 void MainWindow_admin::updateStatusBar() { //设置实时人数信息 @@ -86,6 +108,7 @@ void MainWindow_admin::updateStatusBar() ui_label_time->setText("系统时间:" + cur_time_str); } +//初次进入界面更新信息 void MainWindow_admin::showInfo() { ui->label_id->setText(QString::fromStdString(m_user->getID())); @@ -97,24 +120,7 @@ void MainWindow_admin::showInfo() m_timer_status->start(1000); //每一秒刷新一次状态栏 } -void MainWindow_admin::initTable() -{ - ui_course_model_o = new QStandardItemModel(); - ui->tableView_course_o->setModel(ui_course_model_o); - - ui_course_model_e = new QStandardItemModel(); - ui->tableView_course_e->setModel(ui_course_model_e); - - ui_student_model = new QStandardItemModel(); - ui->tableView_student->setModel(ui_student_model); - - ui_teacher_model = new QStandardItemModel(); - ui->tableView_teacher->setModel(ui_teacher_model); - - ui_admin_model = new QStandardItemModel(); - ui->tableView_admin->setModel(ui_admin_model); -} - +//更新表格信息 void MainWindow_admin::updateTable() { ui_course_model_o->clear(); @@ -230,9 +236,10 @@ void MainWindow_admin::updateTable() ui_admin_model->sort(0); } -//链接菜单栏按钮的槽函数 +//链接各项槽函数 void MainWindow_admin::creatAction() { + //菜单栏 connect(ui->action_login, SIGNAL(triggered()), this, SLOT(action_login_triggered())); connect(ui->action_quit, SIGNAL(triggered()), this, SLOT(action_quit_triggered())); connect(ui->action_course_o, SIGNAL(triggered()), this, SLOT(action_course_o_triggered())); @@ -246,21 +253,24 @@ void MainWindow_admin::creatAction() connect(ui->action_about, SIGNAL(triggered()), this, SLOT(action_about_triggered())); connect(ui->action_help, SIGNAL(triggered()), this, SLOT(action_help_triggered())); + //子界面信号 connect(m_info_user_widget, SIGNAL(updateUser()), this, SLOT(updateTable_slots())); connect(m_info_course_widget, SIGNAL(updateCourse()), this, SLOT(updateTable_slots())); - connect(m_info_user_widget, SIGNAL(updateConfig()), this->m_envir_widget, SLOT(updateConfig())); connect(m_info_course_widget, SIGNAL(updateConfig()), this->m_envir_widget, SLOT(updateConfig())); + //表格项目双击事件 connect(ui->tableView_course_o, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(update_course_slots())); connect(ui->tableView_course_e, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(update_course_slots())); connect(ui->tableView_student, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(update_user_slots())); connect(ui->tableView_teacher, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(update_user_slots())); connect(ui->tableView_admin, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(update_user_slots())); + //界面按钮 connect(ui->add_course_btn, SIGNAL(clicked()), this, SLOT(action_course_add_triggered())); connect(ui->add_user_btn, SIGNAL(clicked()), this, SLOT(action_user_add_triggered())); + //状态栏计时器 connect(m_timer_status, SIGNAL(timeout()), this, SLOT(updateStatusBar())); } @@ -330,7 +340,7 @@ void MainWindow_admin::action_start_course_triggered() void MainWindow_admin::action_about_triggered() { QMessageBox::about(this, QString::fromLocal8Bit("关于"), - QString::fromLocal8Bit(" Students` Grade Manage System 2.7.0 (opensource)" + QString::fromLocal8Bit(" Students` Grade Manage System 2.9.0 (opensource)" "
项目主页:https://github.com/laddie132/StudentsGradeManageSystem" "
作者:L.Laddie" "

Copyright 2016-2016 The Qt Company Ltd. All rights reserved." )); @@ -346,6 +356,7 @@ void MainWindow_admin::updateTable_slots() updateTable(); } +//修改某一门课程 void MainWindow_admin::update_course_slots() { QString id; @@ -377,6 +388,7 @@ void MainWindow_admin::update_course_slots() m_info_course_widget->show(); } +//修改某一个用户 void MainWindow_admin::update_user_slots() { QString id; diff --git a/source/mainwindow_admin.h b/source/mainwindow_admin.h index dd20639..3a8e566 100644 --- a/source/mainwindow_admin.h +++ b/source/mainwindow_admin.h @@ -29,7 +29,7 @@ class MainWindow_admin : public QMainWindow void creatAction(); void showInfo(); //显示用户信息 - void initTable(); //表格信息初始化 + void initActivex(); //控件信息初始化 void updateTable(); //表格信息更新 void initStatusBar(); diff --git a/source/mainwindow_student.cpp b/source/mainwindow_student.cpp index d53d403..f563270 100644 --- a/source/mainwindow_student.cpp +++ b/source/mainwindow_student.cpp @@ -18,20 +18,24 @@ MainWindow_student::MainWindow_student(Envir_widget* envir_widget, QWidget *pare m_envir_widget(envir_widget), ui(new Ui::MainWindow_student) { - ui_label_status = new QLabel(); - ui_label_time = new QLabel(); - m_timer_status = new QTimer(this); ui->setupUi(this); setFixedSize(800, 500); //禁止更改大小 - initActivex(); - creatAction(); - initStatusBar(); + initActivex(); //初始化控件 + creatAction(); //链接槽函数 + initStatusBar(); //初始化状态栏 } MainWindow_student::~MainWindow_student() { + delete ui_label_status; + delete ui_label_time; + delete m_timer_status; delete ui; + + delete ui_course_model_e; + delete ui_course_model_o; + delete ui_course_model_s; } void MainWindow_student::setEnvirWidget(Envir_widget* envir_widget) @@ -44,6 +48,7 @@ void MainWindow_student::setUser(Student* user) this->m_user = user; } +//初始化状态栏信息 void MainWindow_student::initStatusBar() { ui_label_time->setAlignment(Qt::AlignRight); @@ -53,6 +58,7 @@ void MainWindow_student::initStatusBar() ui->statusbar->setStyleSheet(QString("QStatusBar::item{border: 0px}, *{font-size : 8px}")); } +//定时更新状态栏 void MainWindow_student::updateStatusBar() { //设置实时人数信息 @@ -78,6 +84,7 @@ void MainWindow_student::updateStatusBar() ui_label_time->setText("系统时间:" + cur_time_str); } +//初始化相关控件 void MainWindow_student::initActivex() { ui_course_model_o = new QStandardItemModel(); @@ -87,8 +94,13 @@ void MainWindow_student::initActivex() ui->tableView_course_o->setModel(ui_course_model_o); ui->tableView_course_e->setModel(ui_course_model_e); ui->tableView_course_s->setModel(ui_course_model_s); + + ui_label_status = new QLabel(); + ui_label_time = new QLabel(); + m_timer_status = new QTimer(this); } +//初始进入界面时更新界面 void MainWindow_student::showInfo() { ui->label_id->setText(QString::fromStdString(m_user->getID())); @@ -178,9 +190,10 @@ void MainWindow_student::updateTable() ui_course_model_s->sort(0); } -//链接菜单栏按钮的槽函数 +//链接各项槽函数 void MainWindow_student::creatAction() { + //菜单栏 connect(ui->action_login, SIGNAL(triggered()), this, SLOT(action_login_triggered())); connect(ui->action_quit, SIGNAL(triggered()), this, SLOT(action_quit_triggered())); connect(ui->action_course_o, SIGNAL(triggered()), this, SLOT(action_course_o_triggered())); @@ -190,21 +203,27 @@ void MainWindow_student::creatAction() connect(ui->action_help, SIGNAL(triggered()), this, SLOT(action_help_triggered())); connect(ui->action_password, SIGNAL(triggered()), this, SLOT(action_change_pass_triggered())); + //更新配置文件 connect(this, SIGNAL(updateConfig()), this->m_envir_widget, SLOT(updateConfig())); + //学生选课和删除课程事件 connect(ui->tableView_course_s, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(add_course_slots())); connect(ui->tableView_course_e, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(delete_course_slots())); + //状态栏计时器 connect(m_timer_status, SIGNAL(timeout()), this, SLOT(updateStatusBar())); + //表头点击排序事件 connect(ui->tableView_course_o->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(sort_course_o(int))); connect(ui->tableView_course_e->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(sort_course_e(int))); } +//对必修课程排序 void MainWindow_student::sort_course_o(int column) { static bool reverse = false; + //重新构建表格项目的vector向量 std::vector course_o; for(auto i : m_user->getGrade()) { @@ -220,6 +239,7 @@ void MainWindow_student::sort_course_o(int column) course_o.push_back(temp); } + //判断需要对哪一项排序 switch(column) { case 0: @@ -247,6 +267,7 @@ void MainWindow_student::sort_course_o(int column) return; } + //更新表格信息 for(int i = 0; i < course_o.size(); i++) { ui_course_model_o->setItem(i, 0, new QStandardItem(QString::fromStdString(course_o[i].id))); @@ -259,6 +280,7 @@ void MainWindow_student::sort_course_o(int column) } } +//对选修课程排序 void MainWindow_student::sort_course_e(int column) { static bool reverse = false; @@ -302,7 +324,7 @@ void MainWindow_student::sort_course_e(int column) } default: - break; + return; } for(int i = 0; i < course_e.size(); i++) @@ -357,7 +379,7 @@ void MainWindow_student::action_change_pass_triggered() void MainWindow_student::action_about_triggered() { QMessageBox::about(this, QString::fromLocal8Bit("关于"), - QString::fromLocal8Bit(" Students` Grade Manage System 2.7.0 (opensource)" + QString::fromLocal8Bit(" Students` Grade Manage System 2.9.0 (opensource)" "
项目主页:https://github.com/laddie132/StudentsGradeManageSystem" "
作者:L.Laddie" "

Copyright 2016-2016 The Qt Company Ltd. All rights reserved." )); @@ -368,6 +390,7 @@ void MainWindow_student::action_help_triggered() } +//选择选修课 void MainWindow_student::add_course_slots() { int row = ui->tableView_course_s->currentIndex().row(); @@ -396,6 +419,7 @@ void MainWindow_student::add_course_slots() emit updateConfig(); } +//删除选修课 void MainWindow_student::delete_course_slots() { int row = ui->tableView_course_e->currentIndex().row(); diff --git a/source/mainwindow_teacher.cpp b/source/mainwindow_teacher.cpp index dcb1844..0dc51ee 100644 --- a/source/mainwindow_teacher.cpp +++ b/source/mainwindow_teacher.cpp @@ -8,6 +8,7 @@ #include #include +#include "fun.h" #include "mainwindow_teacher.h" #include "ui_mainwindow_teacher.h" @@ -16,20 +17,23 @@ MainWindow_teacher::MainWindow_teacher(Envir_widget* envir_widget, QWidget *pare m_envir_widget(envir_widget), ui(new Ui::MainWindow_teacher) { - ui_label_status = new QLabel(); - ui_label_time = new QLabel(); - m_timer_status = new QTimer(this); ui->setupUi(this); setFixedSize(800, 500); //禁止更改大小 - initActivex(); - creatAction(); - initStatusBar(); + initActivex(); //初始化控件 + creatAction(); //链接槽函数 + initStatusBar(); //初始化状态栏 } MainWindow_teacher::~MainWindow_teacher() { + delete ui_label_status; + delete ui_label_time; + delete m_timer_status; delete ui; + + delete ui_course_model; + delete ui_student_model; } void MainWindow_teacher::setEnvirWidget(Envir_widget* envir_widget) @@ -42,6 +46,7 @@ void MainWindow_teacher::setUser(Teacher* user) this->m_user = user; } +//初始化状态栏信息 void MainWindow_teacher::initStatusBar() { ui_label_time->setAlignment(Qt::AlignRight); @@ -51,6 +56,7 @@ void MainWindow_teacher::initStatusBar() ui->statusbar->setStyleSheet(QString("QStatusBar::item{border: 0px}, *{font-size : 8px}")); } +//定时更新状态栏 void MainWindow_teacher::updateStatusBar() { //设置实时人数信息 @@ -75,6 +81,7 @@ void MainWindow_teacher::updateStatusBar() ui_label_time->setText("系统时间:" + cur_time_str); } +//初始化控件 void MainWindow_teacher::initActivex() { ui_course_model = new QStandardItemModel(); @@ -82,8 +89,13 @@ void MainWindow_teacher::initActivex() ui->tableView_course->setModel(ui_course_model); ui->tableView_student->setModel(ui_student_model); + + ui_label_status = new QLabel(); + ui_label_time = new QLabel(); + m_timer_status = new QTimer(this); } +//更新课程表格 void MainWindow_teacher::updateTable() { ui_course_model->clear(); @@ -109,9 +121,9 @@ void MainWindow_teacher::updateTable() } ui_course_model->sort(0); - ui_student_model->sort(0); } +//初始化进入界面 void MainWindow_teacher::showInfo() { ui->label_id->setText(QString::fromStdString(m_user->getID())); @@ -131,17 +143,18 @@ void MainWindow_teacher::showInfo() m_timer_status->start(1000); //每一秒刷新一次状态栏 } +//更新学生表格 void MainWindow_teacher::updateStudent() { if(ui->comboBox_course->currentIndex() != -1){ QString id = ui->comboBox_course->currentText(); Course_teacher* temp = m_user->findCourse(id.toStdString()); - if(temp){ - ui->label_course_id->setText(QString::fromStdString(temp->getID())); - ui->label_course_name->setText(QString::fromStdString(temp->getName())); - ui->label_course_credit->setText(QString::number(temp->getCredit())); - ui->label_course_type->setText(temp->getCourseType() ? QString::fromLocal8Bit("必修") : QString::fromLocal8Bit("选修")); - } + if(!temp) + return; + ui->label_course_id->setText(QString::fromStdString(temp->getID())); + ui->label_course_name->setText(QString::fromStdString(temp->getName())); + ui->label_course_credit->setText(QString::number(temp->getCredit())); + ui->label_course_type->setText(temp->getCourseType() ? QString::fromLocal8Bit("必修") : QString::fromLocal8Bit("选修")); //更新学生表格信息 ui_student_model->clear(); @@ -162,12 +175,71 @@ void MainWindow_teacher::updateStudent() ui_student_model->setItem(row, 4, new QStandardItem(QString("%1").arg(i.second))); row++; } + ui_student_model->sort(0); + } +} + +//对学生排序 +void MainWindow_teacher::sort_student(int column) +{ + static bool reverse = false; + + std::vector student_m; + if(ui->comboBox_course->currentIndex() != -1){ + //查找当前选择课程 + QString id = ui->comboBox_course->currentText(); + Course_teacher* temp = m_user->findCourse(id.toStdString()); + if(!temp) + return; + + for(auto i : temp->getStudentGrade()) + { + struct student_model temp; + temp.id = i.first->getID(); + temp.name = i.first->getName(); + temp.class_name = i.first->getClass(); + temp.institude = i.first->getInsititude(); + temp.grade = i.second; + student_m.push_back(temp); + } + + //判断当前需要对哪一项排序 + switch(column) + { + case 0: + { + Sort::sortVectorCourse(student_m, "id", reverse); + reverse = !reverse; + break; + } + + case 4: + { + Sort::sortVectorCourse(student_m, "grade", reverse); + reverse = !reverse; + break; + } + + default: + return; + } + + //重新更新表格 + for(int i = 0; i < student_m.size(); i++) + { + ui_student_model->setItem(i, 0, new QStandardItem(QString::fromStdString(student_m[i].id))); + ui_student_model->setItem(i, 1, new QStandardItem(QString::fromStdString(student_m[i].name))); + ui_student_model->setItem(i, 2, new QStandardItem(QString::fromStdString(student_m[i].class_name))); + ui_student_model->setItem(i, 3, new QStandardItem(QString::fromStdString(student_m[i].institude))); + ui_student_model->setItem(i, 4, new QStandardItem(QString("%1").arg(student_m[i].grade))); + } } } //链接菜单栏按钮的槽函数 void MainWindow_teacher::creatAction() { + //菜单栏 connect(ui->action_login, SIGNAL(triggered()), this, SLOT(action_login_triggered())); connect(ui->action_quit, SIGNAL(triggered()), this, SLOT(action_quit_triggered())); connect(ui->action_course, SIGNAL(triggered()), this, SLOT(action_course_triggered())); @@ -176,11 +248,17 @@ void MainWindow_teacher::creatAction() connect(ui->action_help, SIGNAL(triggered()), this, SLOT(action_help_triggered())); connect(ui->action_password, SIGNAL(triggered()), this, SLOT(action_change_pass_triggered())); + //界面按钮 connect(ui->set_grade_btn, SIGNAL(clicked()), this, SLOT(action_set_grade_triggered())); + //更新配置文件 connect(this, SIGNAL(updateConfig()), this->m_envir_widget, SLOT(updateConfig())); + //状态栏计时器 connect(m_timer_status, SIGNAL(timeout()), this, SLOT(updateStatusBar())); + + //表头点击排序 + connect(ui->tableView_student->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(sort_student(int))); } void MainWindow_teacher::action_login_triggered() @@ -218,7 +296,7 @@ void MainWindow_teacher::action_change_pass_triggered() void MainWindow_teacher::action_about_triggered() { QMessageBox::about(this, QString::fromLocal8Bit("关于"), - QString::fromLocal8Bit(" Students` Grade Manage System 2.7.0 (opensource)" + QString::fromLocal8Bit(" Students` Grade Manage System 2.9.0 (opensource)" "
项目主页:https://github.com/laddie132/StudentsGradeManageSystem" "
作者:L.Laddie" "

Copyright 2016-2016 The Qt Company Ltd. All rights reserved." )); @@ -234,11 +312,13 @@ void MainWindow_teacher::on_comboBox_course_currentIndexChanged(int index) updateStudent(); } +//取消修改按钮 void MainWindow_teacher::on_cancel_btn_clicked() { updateStudent(); } +//确认修改按钮 void MainWindow_teacher::on_confirm_btn_clicked() { if(ui->comboBox_course->currentIndex() != -1){ diff --git a/source/mainwindow_teacher.h b/source/mainwindow_teacher.h index 895ca4d..d2587e7 100644 --- a/source/mainwindow_teacher.h +++ b/source/mainwindow_teacher.h @@ -54,6 +54,8 @@ private slots: void updateStatusBar(); + void sort_student(int); + private: Ui::MainWindow_teacher *ui; Envir_widget* m_envir_widget; @@ -69,4 +71,15 @@ private slots: QTimer* m_timer_status; }; +//表格上的学生结构体 +struct student_model +{ + std::string id; + std::string name; + std::string class_name; + std::string institude; + float grade; + float gpa = 0; +}; + #endif // MAINWINDOW_TEACHER_H