Skip to content

Commit

Permalink
Finish sort algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
laddie132 committed Jun 13, 2016
1 parent 8c4ed99 commit f175f1f
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 53 deletions.
9 changes: 8 additions & 1 deletion source/fun.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/**
* Name: fun.h
* User: L.Laddie
* Function: 常用自定义函数
*/

#ifndef FUN_H
#define FUN_H

#include <QDebug>
#include "include.h"

//泛型排序算法
Expand Down Expand Up @@ -54,7 +61,7 @@ namespace Sort {
}
}
if(flag){
break;
// return;
}
}
}
Expand Down
68 changes: 40 additions & 28 deletions source/mainwindow_admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); //初始化状态栏
}

Expand All @@ -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);
Expand All @@ -70,6 +91,7 @@ void MainWindow_admin::initStatusBar()
ui->statusbar->setStyleSheet(QString("QStatusBar::item{border: 0px}, *{font-size : 8px}"));
}

//定时更新状态栏
void MainWindow_admin::updateStatusBar()
{
//设置实时人数信息
Expand All @@ -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()));
Expand All @@ -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();
Expand Down Expand Up @@ -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()));
Expand All @@ -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()));
}

Expand Down Expand Up @@ -330,7 +340,7 @@ void MainWindow_admin::action_start_course_triggered()
void MainWindow_admin::action_about_triggered()
{
QMessageBox::about(this, QString::fromLocal8Bit("关于"),
QString::fromLocal8Bit(" <font color='red'>Students` Grade Manage System 2.7.0 (opensource)</font>"
QString::fromLocal8Bit(" <font color='red'>Students` Grade Manage System 2.9.0 (opensource)</font>"
"<br>项目主页:https://github.com/laddie132/StudentsGradeManageSystem"
" <br>作者:L.Laddie"
" <br><br>Copyright 2016-2016 The Qt Company Ltd. All rights reserved." ));
Expand All @@ -346,6 +356,7 @@ void MainWindow_admin::updateTable_slots()
updateTable();
}

//修改某一门课程
void MainWindow_admin::update_course_slots()
{
QString id;
Expand Down Expand Up @@ -377,6 +388,7 @@ void MainWindow_admin::update_course_slots()
m_info_course_widget->show();
}

//修改某一个用户
void MainWindow_admin::update_user_slots()
{
QString id;
Expand Down
2 changes: 1 addition & 1 deletion source/mainwindow_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MainWindow_admin : public QMainWindow
void creatAction();

void showInfo(); //显示用户信息
void initTable(); //表格信息初始化
void initActivex(); //控件信息初始化
void updateTable(); //表格信息更新

void initStatusBar();
Expand Down
42 changes: 33 additions & 9 deletions source/mainwindow_student.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -44,6 +48,7 @@ void MainWindow_student::setUser(Student* user)
this->m_user = user;
}

//初始化状态栏信息
void MainWindow_student::initStatusBar()
{
ui_label_time->setAlignment(Qt::AlignRight);
Expand All @@ -53,6 +58,7 @@ void MainWindow_student::initStatusBar()
ui->statusbar->setStyleSheet(QString("QStatusBar::item{border: 0px}, *{font-size : 8px}"));
}

//定时更新状态栏
void MainWindow_student::updateStatusBar()
{
//设置实时人数信息
Expand All @@ -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();
Expand All @@ -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()));
Expand Down Expand Up @@ -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()));
Expand All @@ -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<struct course_module> course_o;
for(auto i : m_user->getGrade())
{
Expand All @@ -220,6 +239,7 @@ void MainWindow_student::sort_course_o(int column)
course_o.push_back(temp);
}

//判断需要对哪一项排序
switch(column)
{
case 0:
Expand Down Expand Up @@ -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)));
Expand All @@ -259,6 +280,7 @@ void MainWindow_student::sort_course_o(int column)
}
}

//对选修课程排序
void MainWindow_student::sort_course_e(int column)
{
static bool reverse = false;
Expand Down Expand Up @@ -302,7 +324,7 @@ void MainWindow_student::sort_course_e(int column)
}

default:
break;
return;
}

for(int i = 0; i < course_e.size(); i++)
Expand Down Expand Up @@ -357,7 +379,7 @@ void MainWindow_student::action_change_pass_triggered()
void MainWindow_student::action_about_triggered()
{
QMessageBox::about(this, QString::fromLocal8Bit("关于"),
QString::fromLocal8Bit(" <font color='red'>Students` Grade Manage System 2.7.0 (opensource)</font>"
QString::fromLocal8Bit(" <font color='red'>Students` Grade Manage System 2.9.0 (opensource)</font>"
"<br>项目主页:https://github.com/laddie132/StudentsGradeManageSystem"
" <br>作者:L.Laddie"
" <br><br>Copyright 2016-2016 The Qt Company Ltd. All rights reserved." ));
Expand All @@ -368,6 +390,7 @@ void MainWindow_student::action_help_triggered()

}

//选择选修课
void MainWindow_student::add_course_slots()
{
int row = ui->tableView_course_s->currentIndex().row();
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit f175f1f

Please sign in to comment.