#include "clOnlineHomework.h" #include "ui_clOnlineHomework.h" #include "CAppInfo.h" #include "clOperation.h" #include #include "awMsgBox.h" clOnlineHomework::clOnlineHomework(QWidget *parent) : QWidget(parent), ui(new Ui::clOnlineHomework) { ui->setupUi(this); setStyleSheet(g_appInfoPtr->m_sQssStr); qRegisterMetaType("CQueryHomeworkList"); connect(g_httpBllPtr.get(), &CHttpBll::sgnQueryHomeworkList, this, &clOnlineHomework::onQueryHomeworkList); m_pObjectiveScoreTimer = std::make_shared(); m_pObjectiveScoreTimer->setInterval(200); connect(m_pObjectiveScoreTimer.get(), &QTimer::timeout, this, [&]() { m_pObjectiveScoreTimer->stop(); if (m_pObjectiveScore != nullptr) { m_pObjectiveScore.reset(); } }); } clOnlineHomework::~clOnlineHomework() { delete ui; } void clOnlineHomework::setUI(const int nWidth, const int nHeight) { setGeometry(0, 0, nWidth, nHeight); ui->tabw_onlineExam->setGeometry(0, 0, nWidth, nHeight); ui->tabw_onlineExam->setTabEnabled(1, false); ui->tabw_onlineExam->setTabText(0, QString::fromLocal8Bit("待考列表")); ui->tabw_onlineExam->setTabText(1, QString::fromLocal8Bit("已完成考试")); ui->vlayout_el->setContentsMargins(g_appInfoPtr->m_fRate*30, 0, g_appInfoPtr->m_fRate*30, 0); ui->vlayout_fel->setContentsMargins(g_appInfoPtr->m_fRate*30, 0, g_appInfoPtr->m_fRate*30, 0); ui->tablewt_examList->setEditTriggers(QAbstractItemView::NoEditTriggers); //整行选中的方式 ui->tablewt_examList->setSelectionBehavior(QAbstractItemView::SelectRows); //设置为只能选中一行 ui->tablewt_examList->setSelectionMode(QAbstractItemView::SingleSelection); //隐藏列表头 ui->tablewt_examList->verticalHeader()->setVisible(false); //隐藏边框 ui->tablewt_examList->setShowGrid(false); //表头不高亮显示 ui->tablewt_examList->horizontalHeader()->setHighlightSections(false); //设置行数 ui->tablewt_examList->setRowCount(10); //设置列数 ui->tablewt_examList->setColumnCount(7); ui->tablewt_examList->setHorizontalScrollMode(QTableWidget::ScrollPerPixel); ui->tablewt_examList->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5); QStringList sHeadStr; sHeadStr << QString::fromLocal8Bit("课程") << QString::fromLocal8Bit("层次") << QString::fromLocal8Bit("专业") << QString::fromLocal8Bit("考试进入时间") << QString::fromLocal8Bit("考试时间周期") << QString::fromLocal8Bit("剩余考试次数") << QString::fromLocal8Bit("操作"); ui->tablewt_examList->setHorizontalHeaderLabels(sHeadStr); ui->tablewt_examList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); ui->tablewt_examList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); ui->tablewt_examList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48); ui->tablewt_examList->setColumnWidth(0, g_appInfoPtr->m_fRate*116); ui->tablewt_examList->setColumnWidth(1, g_appInfoPtr->m_fRate*56); ui->tablewt_examList->setColumnWidth(2, g_appInfoPtr->m_fRate*104); ui->tablewt_examList->setColumnWidth(3, g_appInfoPtr->m_fRate*277); ui->tablewt_examList->setColumnWidth(4, g_appInfoPtr->m_fRate*305); ui->tablewt_examList->setColumnWidth(5, g_appInfoPtr->m_fRate*102); ui->tablewt_examList->setColumnWidth(6, g_appInfoPtr->m_fRate*146); ui->tablewt_examList->horizontalHeader()->setStretchLastSection(true); ui->tablew_finishExamList->setEditTriggers(QAbstractItemView::NoEditTriggers); //整行选中的方式 ui->tablew_finishExamList->setSelectionBehavior(QAbstractItemView::SelectRows); //设置为只能选中一行 ui->tablew_finishExamList->setSelectionMode(QAbstractItemView::SingleSelection); //隐藏列表头 ui->tablew_finishExamList->verticalHeader()->setVisible(false); //隐藏边框 ui->tablew_finishExamList->setShowGrid(false); //表头不高亮显示 ui->tablew_finishExamList->horizontalHeader()->setHighlightSections(false); //设置行数 ui->tablew_finishExamList->setRowCount(10); //设置列数 ui->tablew_finishExamList->setColumnCount(7); ui->tablew_finishExamList->setHorizontalScrollMode(QTableWidget::ScrollPerPixel); ui->tablew_finishExamList->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5); ui->tablew_finishExamList->setHorizontalHeaderLabels(sHeadStr); ui->tablew_finishExamList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); ui->tablew_finishExamList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); ui->tablew_finishExamList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48); ui->tablew_finishExamList->setColumnWidth(0, g_appInfoPtr->m_fRate*116); ui->tablew_finishExamList->setColumnWidth(1, g_appInfoPtr->m_fRate*56); ui->tablew_finishExamList->setColumnWidth(2, g_appInfoPtr->m_fRate*104); ui->tablew_finishExamList->setColumnWidth(3, g_appInfoPtr->m_fRate*277); ui->tablew_finishExamList->setColumnWidth(4, g_appInfoPtr->m_fRate*305); ui->tablew_finishExamList->setColumnWidth(5, g_appInfoPtr->m_fRate*102); ui->tablew_finishExamList->setColumnWidth(6, g_appInfoPtr->m_fRate*146); ui->tablew_finishExamList->horizontalHeader()->setStretchLastSection(true); } void clOnlineHomework::showEvent(QShowEvent *) { CHttpRequestPackage hrp; hrp.sUri = "/api/ecs_oe_admin/client/exam/process/queryHomeworkList"; hrp.nRequestType = RequestType::rtQueryHomeworkList; g_httpBllPtr->post(hrp); } void clOnlineHomework::onQueryHomeworkList(CQueryHomeworkList queryHomeworkList) { if (queryHomeworkList.nCode == 200) { int nSize = queryHomeworkList.vHomeworkExamList.size(); for (int i = 0; i < nSize; ++i) { CExamCourseInfo eci = queryHomeworkList.vHomeworkExamList[i]; ui->tablewt_examList->setItem(i, 0, new QTableWidgetItem(eci.sCourseName)); ui->tablewt_examList->setItem(i, 1, new QTableWidgetItem(eci.sCourseLevel)); ui->tablewt_examList->setItem(i, 2, new QTableWidgetItem(eci.sSpecialtyName)); ui->tablewt_examList->setItem(i, 3, new QTableWidgetItem(QString::fromLocal8Bit("%1 ~ %2").arg(eci.sStartTime).arg(eci.sEndTime))); ui->tablewt_examList->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit(""))); ui->tablewt_examList->setItem(i, 5, new QTableWidgetItem(QString::number(eci.nAllowExamCount))); clOperation *clo = new clOperation(i, ui->tablewt_examList); connect(clo, &clOperation::enterExam, this, [&](CL_OPERATION_TYPE cot, int nRow){ if (cot == CL_OPERATION_TYPE::cot_online_homework ) { emit enterExam(cot, m_vHomeworkExamList[nRow].nExamId, m_vHomeworkExamList[nRow].nExamStudentId); } }); connect(clo, &clOperation::showObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) { if (cot == CL_OPERATION_TYPE::cot_online_homework ) { m_pObjectiveScoreTimer->stop(); if (m_pObjectiveScore != nullptr && m_pObjectiveScore->getRow() != nRow) { m_pObjectiveScore.reset(); } if (m_pObjectiveScore == nullptr) { m_pObjectiveScore = std::make_shared(nRow, QString::number(m_vHomeworkExamList[nRow].nExamStudentId), this); connect(m_pObjectiveScore.get(), &clObjectiveScore::objectiveScoreHeight, this, [&](int nRow, int nHeight) { int ntableTop = ui->tabw_onlineExam->y() + g_appInfoPtr->m_fRate*70; int nTop = ntableTop + (nRow + 2)* ui->tablewt_examList->verticalHeader()->defaultSectionSize() - nHeight / 2; if (nTop < ui->tabw_onlineExam->y()) { nTop = ui->tabw_onlineExam->y(); } else if ((nTop + nHeight) > (ntableTop + ui->tablewt_examList->height())) { nTop = ntableTop + ui->tablewt_examList->height() - nHeight; } m_pObjectiveScore->setUI(ui->tablewt_examList->x() + ui->tablewt_examList->width() - ui->tablewt_examList->columnWidth(6) - g_appInfoPtr->m_fRate * 530, nTop, g_appInfoPtr->m_fRate * 530, nHeight); m_pObjectiveScore->show(); }); } } }); connect(clo, &clOperation::hideObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) { if (cot == CL_OPERATION_TYPE::cot_online_homework) { m_pObjectiveScoreTimer->start(); } }); clo->setUI(ui->tablewt_examList->columnWidth(6), ui->tablewt_examList->rowHeight(i), CL_OPERATION_TYPE::cot_online_homework); ui->tablewt_examList->setCellWidget(i, 6, clo); } m_vHomeworkExamList.swap(queryHomeworkList.vHomeworkExamList); } else { if(queryHomeworkList.sMessage.isEmpty()) { ShowMsg(QString::fromLocal8Bit("获取在线作业列表失败"), (QWidget*)(this->parent())); } else { ShowMsg(queryHomeworkList.sMessage, (QWidget*)(this->parent())); } } }