clOnlinePractice.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include "clOnlinePractice.h"
  2. #include "ui_clOnlinePractice.h"
  3. #include "CAppInfo.h"
  4. #include "clOperation.h"
  5. #include <QScrollBar>
  6. #include <QListView>
  7. #include "awMsgBox.h"
  8. clOnlinePractice::clOnlinePractice(QWidget *parent) :
  9. QWidget(parent),
  10. ui(new Ui::clOnlinePractice)
  11. {
  12. ui->setupUi(this);
  13. setStyleSheet(g_appInfoPtr->m_sQssStr);
  14. qRegisterMetaType<CQueryBatchList>("CQueryBatchList");
  15. connect(g_httpBllPtr.get(), &CHttpBll::sgnQueryBatchList, this, &clOnlinePractice::onQueryBatchList);
  16. qRegisterMetaType<CQueryPracticeCourseList>("CQueryPracticeCourseList");
  17. connect(g_httpBllPtr.get(), &CHttpBll::sgnQueryPracticeCourseList, this, &clOnlinePractice::onQueyPracticeCourseList);
  18. }
  19. clOnlinePractice::~clOnlinePractice()
  20. {
  21. delete ui;
  22. }
  23. void clOnlinePractice::setUI(const int nWidth, const int nHeight)
  24. {
  25. setGeometry(0, 0, nWidth, nHeight);
  26. ui->widget_onlinePractice->setGeometry(0, 0, width(), height());
  27. ui->widget_op_top->setGeometry(0, 0, width(), g_appInfoPtr->m_fRate*72);
  28. ui->label_batch->adjustSize();
  29. ui->label_batch->setGeometry(g_appInfoPtr->m_fRate*30, (ui->widget_op_top->height() - ui->label_batch->height())/2,
  30. ui->label_batch->width(), ui->label_batch->height());
  31. ui->cbo_batch->setGeometry(ui->label_batch->x() + ui->label_batch->width() + g_appInfoPtr->m_fRate*10,
  32. (ui->widget_op_top->height() - g_appInfoPtr->m_fRate*32)/2,
  33. g_appInfoPtr->m_fRate*240, g_appInfoPtr->m_fRate*32);
  34. ui->cbo_batch->setView(new QListView);
  35. ui->tablewt_examList->setGeometry(g_appInfoPtr->m_fRate*30, ui->widget_op_top->height() + g_appInfoPtr->m_fRate*10,
  36. ui->widget_onlinePractice->width() - g_appInfoPtr->m_fRate*30*2,
  37. ui->widget_onlinePractice->height() - ui->widget_op_top->height() - g_appInfoPtr->m_fRate*(10 + 62));
  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(8);
  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. QString::fromLocal8Bit("操作");
  64. ui->tablewt_examList->setHorizontalHeaderLabels(sHeadStr);
  65. ui->tablewt_examList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  66. ui->tablewt_examList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
  67. ui->tablewt_examList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48);
  68. ui->tablewt_examList->setColumnWidth(0, g_appInfoPtr->m_fRate*116);
  69. ui->tablewt_examList->setColumnWidth(1, g_appInfoPtr->m_fRate*275);
  70. ui->tablewt_examList->setColumnWidth(2, g_appInfoPtr->m_fRate*280);
  71. ui->tablewt_examList->setColumnWidth(3, g_appInfoPtr->m_fRate*66);
  72. ui->tablewt_examList->setColumnWidth(4, g_appInfoPtr->m_fRate*80);
  73. ui->tablewt_examList->setColumnWidth(5, g_appInfoPtr->m_fRate*80);
  74. ui->tablewt_examList->setColumnWidth(6, g_appInfoPtr->m_fRate*80);
  75. ui->tablewt_examList->setColumnWidth(7, g_appInfoPtr->m_fRate*146);
  76. ui->tablewt_examList->horizontalHeader()->setStretchLastSection(true);
  77. }
  78. void clOnlinePractice::onQueryBatchList(CQueryBatchList queryBatchList)
  79. {
  80. if (queryBatchList.nCode == 200)
  81. {
  82. ui->cbo_batch->clear();
  83. for (CBatchInfo bi : queryBatchList.vBatchList)
  84. {
  85. ui->cbo_batch->addItem(bi.sName, bi.nId);
  86. }
  87. ui->cbo_batch->setCurrentIndex(0);
  88. }
  89. else
  90. {
  91. if(queryBatchList.sMessage.isEmpty())
  92. {
  93. ShowMsg(QString::fromLocal8Bit("获取批次信息失败"), (QWidget*)(this->parent()));
  94. }
  95. else
  96. {
  97. ShowMsg(queryBatchList.sMessage, (QWidget*)(this->parent()));
  98. }
  99. }
  100. }
  101. void clOnlinePractice::showEvent(QShowEvent *)
  102. {
  103. CHttpRequestPackage hrp;
  104. hrp.sUri = "/api/ecs_exam_work/exam/queryByNameLike";
  105. hrp.sParamList.push_back("examTypes,PRACTICE");
  106. hrp.sParamList.push_back(QString("studentId,%1").arg(g_appInfoPtr->m_nStudentId));
  107. hrp.sParamList.push_back(QString("name,%1").arg(""));
  108. hrp.nRequestType = RequestType::rtQueryBatchList;
  109. g_httpBllPtr->get(hrp);
  110. }
  111. void clOnlinePractice::onQueyPracticeCourseList(CQueryPracticeCourseList queryPracticeCourseList)
  112. {
  113. if (queryPracticeCourseList.nCode == 200)
  114. {
  115. int nSize = queryPracticeCourseList.vPracticeCourseInfo.size();
  116. for (int i = 0; i < nSize; ++i)
  117. {
  118. CPracticeCourseInfo pci = queryPracticeCourseList.vPracticeCourseInfo[i];
  119. ui->tablewt_examList->setItem(i, 0, new QTableWidgetItem(pci.sCourseName));
  120. ui->tablewt_examList->setItem(i, 1, new QTableWidgetItem(QString::fromLocal8Bit("%1 ~ %2").arg(pci.sStartTime).arg(pci.sEndTime)));
  121. ui->tablewt_examList->setItem(i, 2, new QTableWidgetItem(QString::fromLocal8Bit("")));
  122. ui->tablewt_examList->setItem(i, 3, new QTableWidgetItem(QString::number(pci.nPracticeCount)));
  123. ui->tablewt_examList->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("%1%").arg(pci.fRecentObjectiveAccuracy)));
  124. ui->tablewt_examList->setItem(i, 5, new QTableWidgetItem(QString::fromLocal8Bit("%1%").arg(pci.fAveObjectiveAccuracy)));
  125. ui->tablewt_examList->setItem(i, 6, new QTableWidgetItem(QString::fromLocal8Bit("%1%").arg(pci.fMaxObjectiveAccuracy)));
  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_practice )
  129. {
  130. emit enterExam(cot, m_vPracticeCourseInfo[nRow].nExamId, m_vPracticeCourseInfo[nRow].nExamStudentId);
  131. }
  132. });
  133. connect(clo, &clOperation::viewPracticeDetail, this, [&](int nRow){
  134. if(m_pResultList == nullptr)
  135. {
  136. m_pResultList = std::make_shared<clopResultList>(m_vPracticeCourseInfo[nRow], ui->cbo_batch->currentText(), this);
  137. connect(m_pResultList.get(), &clopResultList::goback, this, [&](){
  138. m_pResultList.reset();
  139. });
  140. m_pResultList->setUI(0, 0, width(), height());
  141. }
  142. m_pResultList->show();
  143. });
  144. clo->setUI(ui->tablewt_examList->columnWidth(7), ui->tablewt_examList->rowHeight(i), CL_OPERATION_TYPE::cot_online_practice);
  145. ui->tablewt_examList->setCellWidget(i, 7, clo);
  146. }
  147. m_vPracticeCourseInfo.swap(queryPracticeCourseList.vPracticeCourseInfo);
  148. }
  149. else
  150. {
  151. if(queryPracticeCourseList.sMessage.isEmpty())
  152. {
  153. ShowMsg(QString::fromLocal8Bit("获取练习列表失败"), (QWidget*)(this->parent()));
  154. }
  155. else
  156. {
  157. ShowMsg(queryPracticeCourseList.sMessage, (QWidget*)(this->parent()));
  158. }
  159. }
  160. }
  161. void clOnlinePractice::on_cbo_batch_currentIndexChanged(int index)
  162. {
  163. QString sExamId = ui->cbo_batch->currentData().toString();
  164. CHttpRequestPackage hrp;
  165. hrp.sUri = "/api/ecs_oe_admin/client/exam/process/queryPracticeCourseList";
  166. hrp.sParamList.push_back(QString("examId,%1").arg(sExamId));
  167. hrp.nRequestType = RequestType::rtQueryPracticeCourseList;
  168. hrp.eParamType = HttpParamType::hptUrl;
  169. g_httpBllPtr->post(hrp);
  170. }