clOnlineHomework.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #include "clOnlineHomework.h"
  2. #include "ui_clOnlineHomework.h"
  3. #include "CAppInfo.h"
  4. #include "clOperation.h"
  5. #include <QScrollBar>
  6. #include "awMsgBox.h"
  7. clOnlineHomework::clOnlineHomework(QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::clOnlineHomework)
  10. {
  11. ui->setupUi(this);
  12. setStyleSheet(g_appInfoPtr->m_sQssStr);
  13. qRegisterMetaType<CQueryHomeworkList>("CQueryHomeworkList");
  14. connect(g_httpBllPtr.get(), &CHttpBll::sgnQueryHomeworkList, this, &clOnlineHomework::onQueryHomeworkList);
  15. m_pObjectiveScoreTimer = std::make_shared<QTimer>();
  16. m_pObjectiveScoreTimer->setInterval(200);
  17. connect(m_pObjectiveScoreTimer.get(), &QTimer::timeout, this, [&]() {
  18. m_pObjectiveScoreTimer->stop();
  19. if (m_pObjectiveScore != nullptr)
  20. {
  21. m_pObjectiveScore.reset();
  22. }
  23. });
  24. }
  25. clOnlineHomework::~clOnlineHomework()
  26. {
  27. delete ui;
  28. }
  29. void clOnlineHomework::setUI(const int nWidth, const int nHeight)
  30. {
  31. setGeometry(0, 0, nWidth, nHeight);
  32. ui->tabw_onlineExam->setGeometry(0, 0, nWidth, nHeight);
  33. ui->tabw_onlineExam->setTabEnabled(1, false);
  34. ui->tabw_onlineExam->setTabText(0, QString::fromLocal8Bit("待考列表"));
  35. ui->tabw_onlineExam->setTabText(1, QString::fromLocal8Bit("已完成考试"));
  36. ui->vlayout_el->setContentsMargins(g_appInfoPtr->m_fRate*30, 0, g_appInfoPtr->m_fRate*30, 0);
  37. ui->vlayout_fel->setContentsMargins(g_appInfoPtr->m_fRate*30, 0, g_appInfoPtr->m_fRate*30, 0);
  38. ui->tablewt_examList->setEditTriggers(QAbstractItemView::NoEditTriggers);
  39. //整行选中的方式
  40. ui->tablewt_examList->setSelectionBehavior(QAbstractItemView::SelectRows);
  41. //设置为只能选中一行
  42. ui->tablewt_examList->setSelectionMode(QAbstractItemView::SingleSelection);
  43. //隐藏列表头
  44. ui->tablewt_examList->verticalHeader()->setVisible(false);
  45. //隐藏边框
  46. ui->tablewt_examList->setShowGrid(false);
  47. //表头不高亮显示
  48. ui->tablewt_examList->horizontalHeader()->setHighlightSections(false);
  49. //设置行数
  50. ui->tablewt_examList->setRowCount(10);
  51. //设置列数
  52. ui->tablewt_examList->setColumnCount(7);
  53. ui->tablewt_examList->setHorizontalScrollMode(QTableWidget::ScrollPerPixel);
  54. ui->tablewt_examList->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5);
  55. QStringList sHeadStr;
  56. sHeadStr << QString::fromLocal8Bit("课程") <<
  57. QString::fromLocal8Bit("层次") <<
  58. QString::fromLocal8Bit("专业") <<
  59. QString::fromLocal8Bit("考试进入时间") <<
  60. QString::fromLocal8Bit("考试时间周期") <<
  61. QString::fromLocal8Bit("剩余考试次数") <<
  62. QString::fromLocal8Bit("操作");
  63. ui->tablewt_examList->setHorizontalHeaderLabels(sHeadStr);
  64. ui->tablewt_examList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  65. ui->tablewt_examList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
  66. ui->tablewt_examList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48);
  67. ui->tablewt_examList->setColumnWidth(0, g_appInfoPtr->m_fRate*116);
  68. ui->tablewt_examList->setColumnWidth(1, g_appInfoPtr->m_fRate*56);
  69. ui->tablewt_examList->setColumnWidth(2, g_appInfoPtr->m_fRate*104);
  70. ui->tablewt_examList->setColumnWidth(3, g_appInfoPtr->m_fRate*277);
  71. ui->tablewt_examList->setColumnWidth(4, g_appInfoPtr->m_fRate*305);
  72. ui->tablewt_examList->setColumnWidth(5, g_appInfoPtr->m_fRate*102);
  73. ui->tablewt_examList->setColumnWidth(6, g_appInfoPtr->m_fRate*146);
  74. ui->tablewt_examList->horizontalHeader()->setStretchLastSection(true);
  75. ui->tablew_finishExamList->setEditTriggers(QAbstractItemView::NoEditTriggers);
  76. //整行选中的方式
  77. ui->tablew_finishExamList->setSelectionBehavior(QAbstractItemView::SelectRows);
  78. //设置为只能选中一行
  79. ui->tablew_finishExamList->setSelectionMode(QAbstractItemView::SingleSelection);
  80. //隐藏列表头
  81. ui->tablew_finishExamList->verticalHeader()->setVisible(false);
  82. //隐藏边框
  83. ui->tablew_finishExamList->setShowGrid(false);
  84. //表头不高亮显示
  85. ui->tablew_finishExamList->horizontalHeader()->setHighlightSections(false);
  86. //设置行数
  87. ui->tablew_finishExamList->setRowCount(10);
  88. //设置列数
  89. ui->tablew_finishExamList->setColumnCount(7);
  90. ui->tablew_finishExamList->setHorizontalScrollMode(QTableWidget::ScrollPerPixel);
  91. ui->tablew_finishExamList->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5);
  92. ui->tablew_finishExamList->setHorizontalHeaderLabels(sHeadStr);
  93. ui->tablew_finishExamList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  94. ui->tablew_finishExamList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
  95. ui->tablew_finishExamList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48);
  96. ui->tablew_finishExamList->setColumnWidth(0, g_appInfoPtr->m_fRate*116);
  97. ui->tablew_finishExamList->setColumnWidth(1, g_appInfoPtr->m_fRate*56);
  98. ui->tablew_finishExamList->setColumnWidth(2, g_appInfoPtr->m_fRate*104);
  99. ui->tablew_finishExamList->setColumnWidth(3, g_appInfoPtr->m_fRate*277);
  100. ui->tablew_finishExamList->setColumnWidth(4, g_appInfoPtr->m_fRate*305);
  101. ui->tablew_finishExamList->setColumnWidth(5, g_appInfoPtr->m_fRate*102);
  102. ui->tablew_finishExamList->setColumnWidth(6, g_appInfoPtr->m_fRate*146);
  103. ui->tablew_finishExamList->horizontalHeader()->setStretchLastSection(true);
  104. }
  105. void clOnlineHomework::showEvent(QShowEvent *)
  106. {
  107. CHttpRequestPackage hrp;
  108. hrp.sUri = "/api/ecs_oe_admin/client/exam/process/queryHomeworkList";
  109. hrp.nRequestType = RequestType::rtQueryHomeworkList;
  110. g_httpBllPtr->post(hrp);
  111. }
  112. void clOnlineHomework::onQueryHomeworkList(CQueryHomeworkList queryHomeworkList)
  113. {
  114. if (queryHomeworkList.nCode == 200)
  115. {
  116. int nSize = queryHomeworkList.vHomeworkExamList.size();
  117. for (int i = 0; i < nSize; ++i)
  118. {
  119. CExamCourseInfo eci = queryHomeworkList.vHomeworkExamList[i];
  120. ui->tablewt_examList->setItem(i, 0, new QTableWidgetItem(eci.sCourseName));
  121. ui->tablewt_examList->setItem(i, 1, new QTableWidgetItem(eci.sCourseLevel));
  122. ui->tablewt_examList->setItem(i, 2, new QTableWidgetItem(eci.sSpecialtyName));
  123. ui->tablewt_examList->setItem(i, 3, new QTableWidgetItem(QString::fromLocal8Bit("%1 ~ %2").arg(eci.sStartTime).arg(eci.sEndTime)));
  124. ui->tablewt_examList->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("")));
  125. ui->tablewt_examList->setItem(i, 5, new QTableWidgetItem(QString::number(eci.nAllowExamCount)));
  126. clOperation *clo = new clOperation(i, ui->tablewt_examList);
  127. connect(clo, &clOperation::enterExam, this, [&](CL_OPERATION_TYPE cot, int nRow){
  128. if (cot == CL_OPERATION_TYPE::cot_online_homework )
  129. {
  130. emit enterExam(cot, m_vHomeworkExamList[nRow].nExamId, m_vHomeworkExamList[nRow].nExamStudentId);
  131. }
  132. });
  133. connect(clo, &clOperation::showObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  134. if (cot == CL_OPERATION_TYPE::cot_online_homework )
  135. {
  136. m_pObjectiveScoreTimer->stop();
  137. if (m_pObjectiveScore != nullptr &&
  138. m_pObjectiveScore->getRow() != nRow)
  139. {
  140. m_pObjectiveScore.reset();
  141. }
  142. if (m_pObjectiveScore == nullptr)
  143. {
  144. m_pObjectiveScore = std::make_shared<clObjectiveScore>(nRow, QString::number(m_vHomeworkExamList[nRow].nExamStudentId), this);
  145. connect(m_pObjectiveScore.get(), &clObjectiveScore::objectiveScoreHeight, this, [&](int nRow, int nHeight) {
  146. int ntableTop = ui->tabw_onlineExam->y() + g_appInfoPtr->m_fRate*70;
  147. int nTop = ntableTop + (nRow + 2)* ui->tablewt_examList->verticalHeader()->defaultSectionSize() - nHeight / 2;
  148. if (nTop < ui->tabw_onlineExam->y())
  149. {
  150. nTop = ui->tabw_onlineExam->y();
  151. }
  152. else if ((nTop + nHeight) > (ntableTop + ui->tablewt_examList->height()))
  153. {
  154. nTop = ntableTop + ui->tablewt_examList->height() - nHeight;
  155. }
  156. m_pObjectiveScore->setUI(ui->tablewt_examList->x() + ui->tablewt_examList->width() - ui->tablewt_examList->columnWidth(6) - g_appInfoPtr->m_fRate * 530,
  157. nTop, g_appInfoPtr->m_fRate * 530, nHeight);
  158. m_pObjectiveScore->show();
  159. });
  160. }
  161. }
  162. });
  163. connect(clo, &clOperation::hideObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  164. if (cot == CL_OPERATION_TYPE::cot_online_homework)
  165. {
  166. m_pObjectiveScoreTimer->start();
  167. }
  168. });
  169. clo->setUI(ui->tablewt_examList->columnWidth(6), ui->tablewt_examList->rowHeight(i), CL_OPERATION_TYPE::cot_online_homework);
  170. ui->tablewt_examList->setCellWidget(i, 6, clo);
  171. }
  172. m_vHomeworkExamList.swap(queryHomeworkList.vHomeworkExamList);
  173. }
  174. else
  175. {
  176. if(queryHomeworkList.sMessage.isEmpty())
  177. {
  178. ShowMsg(QString::fromLocal8Bit("获取在线作业列表失败"), (QWidget*)(this->parent()));
  179. }
  180. else
  181. {
  182. ShowMsg(queryHomeworkList.sMessage, (QWidget*)(this->parent()));
  183. }
  184. }
  185. }