EvalSchemeWidget.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #include "EvalSchemeWidget.h"
  2. #include <CCanvas/CSchemeView.h>
  3. #include <CCanvas/CSchemeItem.h>
  4. #include <Widgets/Button.h>
  5. #include <Widgets/Menu.h>
  6. #include <Widgets/CheckBox.h>
  7. #include <QLabel>
  8. #include <QLayout>
  9. #include <QMetaEnum>
  10. #include <QDebug>
  11. QString EvalSchemeWidget::nameOfScheme(Scheme s)
  12. {
  13. switch (s) {
  14. case Index:
  15. return "构建指标体系";
  16. case Collect:
  17. return "收集数据";
  18. case Process:
  19. return "处理数据";
  20. case Output:
  21. return "生成报告";
  22. }
  23. }
  24. QString EvalSchemeWidget::descriptionOfScheme(EvalSchemeWidget::Scheme s)
  25. {
  26. switch (s) {
  27. case Index:
  28. return "构建指标体系";
  29. case Collect:
  30. return "收集专家数据";
  31. case Process:
  32. return "处理数据";
  33. case Output:
  34. return "生成报告";
  35. }
  36. }
  37. QString EvalSchemeWidget::nameOfAlgorithm(EvalSchemeWidget::Algorithm a)
  38. {
  39. switch (a) {
  40. case Alg1:
  41. return "层次分析法";
  42. case Alg2:
  43. return "集对分析法";
  44. case Alg3:
  45. return "熵值法";
  46. case Alg4:
  47. return "物元分析法";
  48. case Alg5:
  49. return "灰色聚类评估法";
  50. }
  51. }
  52. EvalSchemeWidget::EvalSchemeWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent)
  53. {
  54. setTitle("评估方案规划");
  55. // 预设方案模板
  56. m_schemes["指标体系"] = { Index | Process | Output, Alg1 };
  57. m_schemes["收集数据"] = { Collect | Process | Output, Alg1 };
  58. m_schemes["指标体系和收集数据"] = { Index | Collect | Process | Output, Alg1 };
  59. initWidgets();
  60. initLayout();
  61. connectSignalsAndSlots();
  62. loadScheme(m_schemes.keys().first());
  63. }
  64. void EvalSchemeWidget::initWidgets()
  65. {
  66. m_schemeBtn = new PushButton("加载方案模板", this);
  67. m_index = new CheckBox("指标体系", this);
  68. m_data = new CheckBox("收集数据", this);
  69. m_algBtn = new PushButton("数据处理", this);
  70. m_clear = new PushButton("清空");
  71. m_schemeView = new CSchemeView(this);
  72. m_schemeSep = new QWidget(this);
  73. m_schemeSep->setFixedWidth(1);
  74. m_description = new QLabel("description", this);
  75. m_description->setFixedWidth(150);
  76. m_description->setAlignment(Qt::AlignTop);
  77. m_description->setWordWrap(true);
  78. m_schemeMenu = new RoundMenu("scheme", this);
  79. for (QString key : m_schemes.keys()) {
  80. QAction *act = new QAction(key);
  81. m_schemeMenu->addAction(act);
  82. connect(act, &QAction::triggered, [this, act]() { loadScheme(act->text()); });
  83. }
  84. // 按照算法枚举值添加算法选项
  85. m_algMenu = new RoundMenu("alg", this);
  86. QMetaEnum alg = QMetaEnum::fromType<Algorithm>();
  87. for (int i = 0; i < alg.keyCount(); i++) {
  88. Algorithm t = Algorithm(alg.value(i));
  89. QAction *act = new QAction(nameOfAlgorithm(t));
  90. m_algMenu->addAction(act);
  91. connect(act, &QAction::triggered, [this, t]() { slotSelectAlgorithm(t); });
  92. }
  93. }
  94. void EvalSchemeWidget::initLayout()
  95. {
  96. // 总体布局
  97. m_buttonLayout = new QHBoxLayout();
  98. m_contentLayout->addLayout(m_buttonLayout);
  99. m_schemeLayout = new QHBoxLayout();
  100. m_contentLayout->addLayout(m_schemeLayout);
  101. m_buttonLayout->addWidget(m_schemeBtn);
  102. m_buttonLayout->addSpacing(20);
  103. m_buttonLayout->addWidget(m_index);
  104. m_buttonLayout->addSpacing(20);
  105. m_buttonLayout->addWidget(m_data);
  106. m_buttonLayout->addSpacing(20);
  107. m_buttonLayout->addWidget(m_algBtn);
  108. m_buttonLayout->addSpacing(20);
  109. m_buttonLayout->addWidget(m_clear);
  110. m_buttonLayout->addStretch();
  111. m_schemeLayout->addWidget(m_schemeView);
  112. m_schemeLayout->addWidget(m_seperator);
  113. m_schemeLayout->addWidget(m_description);
  114. }
  115. void EvalSchemeWidget::connectSignalsAndSlots()
  116. {
  117. connect(m_schemeBtn, &PushButton::clicked, this, &EvalSchemeWidget::slotShowSchemeMenu);
  118. connect(m_index, &CheckBox::clicked, this, &EvalSchemeWidget::slotIndexClicked);
  119. connect(m_data, &CheckBox::clicked, this, &EvalSchemeWidget::slotDataClicked);
  120. connect(m_algBtn, &PushButton::clicked, this, &EvalSchemeWidget::slotAlgBtnClicked);
  121. connect(m_clear, &PushButton::clicked, this, &EvalSchemeWidget::slotClearClicked);
  122. }
  123. void EvalSchemeWidget::refreshSchemeView()
  124. {
  125. updateButtonState();
  126. m_schemeView->clear();
  127. m_description->clear();
  128. if (m_scheme <= 0) {
  129. return;
  130. }
  131. m_scheme |= Output;
  132. QString desc = QString("方案说明\n\n");
  133. int step = 0;
  134. QMetaEnum sch = QMetaEnum::fromType<Scheme>();
  135. for (int i = 0; i < sch.keyCount(); i++) {
  136. Scheme s = Scheme(sch.value(i));
  137. if (s == Process) {
  138. for (Algorithm a : m_algs) {
  139. CSchemeItem *item = new CSchemeItem(nameOfAlgorithm(a));
  140. m_schemeView->addItem(item);
  141. desc += QString("第 %1 步: 使用%2对数据进行处理\n\n").arg(++step).arg(nameOfAlgorithm(a));
  142. }
  143. } else {
  144. if ((m_scheme & s) == s) {
  145. CSchemeItem *item = new CSchemeItem(nameOfScheme(s));
  146. m_schemeView->addItem(item);
  147. desc += QString("第 %1 步: %2\n\n").arg(++step).arg(descriptionOfScheme(s));
  148. }
  149. }
  150. }
  151. m_description->setText(desc);
  152. }
  153. void EvalSchemeWidget::loadScheme(const QString &scheme)
  154. {
  155. if (m_schemes.contains(scheme) == false) {
  156. return;
  157. }
  158. SchemeAndAlg s = m_schemes[scheme];
  159. m_scheme = s.scheme;
  160. m_algs.clear();
  161. m_algs.append(s.alg);
  162. refreshSchemeView();
  163. }
  164. void EvalSchemeWidget::updateButtonState()
  165. {
  166. bool e = m_scheme > 0 && m_algs.count() > 0;
  167. m_index->setEnabled(e);
  168. m_data->setEnabled(e);
  169. m_algBtn->setEnabled(e);
  170. m_clear->setEnabled(e);
  171. m_index->setChecked((m_scheme & Index) == Index);
  172. m_data->setChecked((m_scheme & Collect) == Collect);
  173. }
  174. void EvalSchemeWidget::slotShowSchemeMenu()
  175. {
  176. QPoint pos = m_schemeBtn->mapToGlobal(QPoint()) + QPoint(m_schemeBtn->width(), -10);
  177. m_schemeMenu->exec(pos, true);
  178. }
  179. void EvalSchemeWidget::slotIndexClicked()
  180. {
  181. m_scheme ^= Index;
  182. refreshSchemeView();
  183. }
  184. void EvalSchemeWidget::slotDataClicked()
  185. {
  186. m_scheme ^= Collect;
  187. refreshSchemeView();
  188. }
  189. void EvalSchemeWidget::slotAlgBtnClicked()
  190. {
  191. QPoint pos = m_algBtn->mapToGlobal(QPoint()) + QPoint(m_algBtn->width(), -10);
  192. m_algMenu->exec(pos, true);
  193. }
  194. void EvalSchemeWidget::slotClearClicked()
  195. {
  196. m_scheme = 0;
  197. m_algs.clear();
  198. refreshSchemeView();
  199. }
  200. void EvalSchemeWidget::slotSelectAlgorithm(EvalSchemeWidget::Algorithm alg)
  201. {
  202. if (m_algs.contains(alg)) {
  203. return;
  204. }
  205. m_algs.clear();
  206. m_algs.append(alg);
  207. refreshSchemeView();
  208. }