SchemePlanWidget.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #include "SchemePlanWidget.h"
  2. #include "SchemeFlowWidget.h"
  3. #include "ProjectManager.h"
  4. #include <dbService/ClassSet.h>
  5. #include <dbService/SchemeProcessService.h>
  6. #include <dbService/NodeMatrixService.h>
  7. #include <dbService/UserConfigService.h>
  8. #include <CSchemeView.h>
  9. #include <Widgets/Button.h>
  10. #include <QTabWidget>
  11. #include <QLayout>
  12. //#include <QTextEdit>
  13. #include <QDebug>
  14. SchemePlanWidget::SchemePlanWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent)
  15. {
  16. setTitle("评估方案规划");
  17. setupUI();
  18. }
  19. void SchemePlanWidget::setType(int type)
  20. {
  21. EvalWidget::setType(type);
  22. setupTabWidget();
  23. }
  24. void SchemePlanWidget::setupUI()
  25. {
  26. m_topLayout->addStretch();
  27. m_export = new PushButton("保存", this);
  28. m_export->setEnabled(false);
  29. m_topLayout->addWidget(m_export);
  30. m_topLayout->addSpacing(10);
  31. m_export->setHidden(true);
  32. m_description = new QTextEdit(this);
  33. m_description->setReadOnly(true);
  34. m_description->setFixedWidth(240);
  35. m_contentLayout->addWidget(m_description);
  36. connect(m_export, &PushButton::clicked, this, &SchemePlanWidget::slotExportClicked);
  37. connect(m_tab, &QTabWidget::currentChanged, this, &SchemePlanWidget::slotTabCurrentChanged);
  38. }
  39. QList<SchemePlanManager::SchemeProcessInfo> SchemePlanWidget::templateSchemes(int projId, int indexType)
  40. {
  41. QList<SchemePlanManager::SchemeProcessType> types;
  42. switch (indexType) {
  43. case ProjectManager::AbilityIndex: {
  44. types = { SchemePlanManager::IndexSystem, SchemePlanManager::ImportWeightData,
  45. SchemePlanManager::OptimizeIndex, SchemePlanManager::CalculateWeight,
  46. SchemePlanManager::ShowEvalResult, SchemePlanManager::GenerateReport };
  47. break;
  48. }
  49. case ProjectManager::TechIndex: {
  50. types = { SchemePlanManager::IndexSystem, SchemePlanManager::ImportEvalData, SchemePlanManager::RunEvaluate,
  51. SchemePlanManager::ShowEvalResult, SchemePlanManager::GenerateReport };
  52. break;
  53. }
  54. case ProjectManager::OptimalIndex: {
  55. types = { SchemePlanManager::IndexSystem, SchemePlanManager::ImportWeightData,
  56. SchemePlanManager::OptimizeIndex, SchemePlanManager::CalculateWeight,
  57. SchemePlanManager::ImportEvalData, SchemePlanManager::RunEvaluate,
  58. SchemePlanManager::ShowEvalResult, SchemePlanManager::GenerateReport };
  59. break;
  60. }
  61. case ProjectManager::EfficiencyIndex: {
  62. types = { SchemePlanManager::IndexSystem, SchemePlanManager::ImportWeightData,
  63. SchemePlanManager::OptimizeIndex, SchemePlanManager::CalculateWeight,
  64. SchemePlanManager::ImportEvalData, SchemePlanManager::RunEvaluate,
  65. SchemePlanManager::ShowEvalResult, SchemePlanManager::GenerateReport };
  66. break;
  67. }
  68. }
  69. QList<SchemePlanManager::SchemeProcessInfo> schemes;
  70. for (int i = 0; i < types.count(); i++) {
  71. SchemePlanManager::SchemeProcessInfo process;
  72. process.projectId = projId;
  73. process.indexType = indexType;
  74. process.type = types[i];
  75. process.step = i;
  76. QList<SchemePlanManager::SchemeDataSource> data = SchemePlanManager::processOptionalDataSource(process);
  77. process.dSource = data.size() > 0 ? data.first() : SchemePlanManager::NoData;
  78. QList<SchemePlanManager::Algorithm> algs = SchemePlanManager::processOptionalAlgorithms(process);
  79. process.algorithm = algs.size() > 0 ? algs.first() : SchemePlanManager::NoAlg;
  80. schemes.append(process);
  81. }
  82. return schemes;
  83. }
  84. void SchemePlanWidget::setupTabWidget()
  85. {
  86. m_tab->clear();
  87. for (int i : indexList()) {
  88. SchemeFlowWidget *m = new SchemeFlowWidget(this);
  89. connect(m, &SchemeFlowWidget::sigSchemeProcessEdited, this, &SchemePlanWidget::slotSchemeProcessEdited);
  90. QList<SchemePlanManager::SchemeProcessInfo> schemes;
  91. bool ret = SchemeProcessService().QueryAllByProjectIdAndIndexType(schemes, m_proj->id, i);
  92. if (ret && schemes.count() <= 0) {
  93. schemes = templateSchemes(m_proj->id, i);
  94. ret = SchemeProcessService().AddAllSchemeProcess(schemes);
  95. }
  96. if (ret) {
  97. m->loadSchemes(schemes);
  98. }
  99. ProjectManager::IndexType t = (ProjectManager::IndexType)i;
  100. QString s = ProjectManager::nameOfIndexType(t);
  101. m_tab->addTab(m, s);
  102. }
  103. }
  104. bool SchemePlanWidget::hasData(QString indexName) const
  105. {
  106. bool ret = NodeMatrixService().hasMeasureData(m_proj->id, indexName);
  107. if (ret == true) {
  108. return true;
  109. }
  110. QList<UserConfig *> cfgList;
  111. ret = UserConfigService().QueryUserConfigListInfoByEngineerId(&cfgList, m_proj->id);
  112. if (ret == false) {
  113. return false;
  114. }
  115. for (UserConfig *cfg : cfgList) {
  116. ret = NodeMatrixService().hasExpertData(m_proj->id, indexName, cfg->userId);
  117. if (ret) {
  118. return true;
  119. }
  120. }
  121. return false;
  122. }
  123. void SchemePlanWidget::updateDescription()
  124. {
  125. SchemeFlowWidget *m = (SchemeFlowWidget *)m_tab->currentWidget();
  126. if (m == nullptr) {
  127. return;
  128. }
  129. QList<SchemePlanManager::SchemeProcessInfo> schemes = m->schemes();
  130. QString text = "方案说明\n";
  131. for (int i = 0; i < schemes.size(); ++i) {
  132. text.append("\n");
  133. text.append(QString("第 %1 步:\n").arg(i + 1));
  134. text.append(SchemePlanManager::processName(schemes[i]));
  135. text.append("\n");
  136. text.append(SchemePlanManager::processDescription(schemes[i]));
  137. text.append("\n");
  138. }
  139. m_description->setText(text);
  140. }
  141. void SchemePlanWidget::slotExportClicked()
  142. {
  143. for (int i = 0; i < m_tab->count(); i++) {
  144. SchemeFlowWidget *w = (SchemeFlowWidget *)m_tab->widget(i);
  145. QList<SchemePlanManager::SchemeProcessInfo> schemes = w->schemes();
  146. }
  147. }
  148. void SchemePlanWidget::slotSchemeProcessEdited(const SchemePlanManager::SchemeProcessInfo &process)
  149. {
  150. qDebug() << __FUNCTION__ << __LINE__ << process.algorithm << endl;
  151. SchemeProcessService().UpdateSchemeProcess(process);
  152. updateDescription();
  153. }
  154. void SchemePlanWidget::slotTabCurrentChanged(int c)
  155. {
  156. SchemeFlowWidget *m = (SchemeFlowWidget *)m_tab->currentWidget();
  157. if (m == nullptr) {
  158. return;
  159. }
  160. /// 有数据时禁止编辑
  161. bool ret = hasData(m_tab->tabText(c));
  162. m->setAllowEdit(!ret);
  163. updateDescription();
  164. }