EvalReportWidget.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. #include "EvalReportWidget.h"
  2. #include "DataTableWidget.h"
  3. #include "ProjectManager.h"
  4. #include "view/PlotView.h"
  5. #include "CustomPieChart.h"
  6. #include "common/ExportReportManager.h"
  7. #include <dbService/CNodeDataService.h>
  8. #include <dbService/ClassSet.h>
  9. #include <dbService/SchemeInfoService.h>
  10. #include <dbService/SchemeProcessService.h>
  11. #include <dbService/MindWeightService.h>
  12. #include <dbService/MindScoreService.h>
  13. #include <dbService/EffectResultService.h>
  14. #include <dbService/GradeInfoService.h>
  15. #include <dbService/UserConfigService.h>
  16. #include <dbService/NodeMatrixService.h>
  17. #include <QLabel>
  18. #include <QBoxLayout>
  19. #include <QGridLayout>
  20. #include <QComboBox>
  21. #include <QPushButton>
  22. static QSize kFigureSize = QSize(600, 600);
  23. EvalReportWidget::EvalReportWidget(ProjectInfo *proj, int indexType, QWidget *parent)
  24. : QWidget(parent), m_proj(proj), m_indexType(indexType)
  25. {
  26. initWidgets();
  27. initLayouts();
  28. loadAlgs();
  29. loadData();
  30. m_exportMngr = new ExportReportManager(this);
  31. m_exportMngr->setProj(m_proj);
  32. m_exportMngr->setEvalType(ProjectManager::evalTypeOfIndexType(indexType));
  33. }
  34. EvalReportWidget::~EvalReportWidget()
  35. {
  36. delete m_exportMngr;
  37. }
  38. void EvalReportWidget::exportReport()
  39. {
  40. m_exportMngr->exportReport();
  41. return;
  42. if (m_indexType == ProjectManager::OptimalIndex) { // 方案优选
  43. QString path = "D:/FireFly/QFD2/bin/dataset/方案优选评估报告.docx";
  44. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  45. } else if (m_indexType == ProjectManager::EfficiencyIndex) {
  46. QString path = "D:/FireFly/QFD2/bin/dataset/综合效能评估报告.docx";
  47. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  48. }
  49. }
  50. void EvalReportWidget::initWidgets()
  51. {
  52. m_view = new QWidget;
  53. QSize s = kFigureSize;
  54. m_indexTitle = new QLabel(this);
  55. m_indexTab = new QTabWidget(this);
  56. m_indexTab->setFixedSize(s);
  57. connect(m_indexTab, SIGNAL(currentChanged(int)), this, SLOT(slotIndexTabIndexChanged(int)));
  58. QVector<PlotView::Data> data;
  59. m_indexPlot = new PlotView(PlotView::HistogramVertical, data, "", this);
  60. m_indexPlot->setFixedSize(s);
  61. m_techTitle = new QLabel(this);
  62. m_techTable = new QTableView(this);
  63. m_techTable->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  64. m_techTable->verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  65. m_techTable->setAlternatingRowColors(true);
  66. m_techTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  67. DataTableItemModel *techModel = new DataTableItemModel();
  68. m_techTable->setModel(techModel);
  69. m_techTable->setFixedSize(s);
  70. m_techPlot = new PlotView(PlotView::HistogramHorizontal, data, "", this);
  71. m_techPlot->setFixedSize(s);
  72. m_schemeTitle = new QLabel(this);
  73. m_schemeTable = new QTableView(this);
  74. m_schemeTable->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  75. m_schemeTable->verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  76. m_schemeTable->setAlternatingRowColors(true);
  77. m_schemeTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  78. DataTableItemModel *schemeModel = new DataTableItemModel();
  79. m_schemeTable->setModel(schemeModel);
  80. m_schemeTable->setFixedSize(s);
  81. m_schemePlot = new PlotView(PlotView::HistogramVertical, data, "", this);
  82. m_schemePlot->setFixedSize(s);
  83. m_EffiTab = new QTabWidget(this);
  84. m_EffiTab->setFixedSize(s);
  85. connect(m_EffiTab, SIGNAL(currentChanged(int)), this, SLOT(slotEffiTabIndexChanged(int)));
  86. QStringList plots = { "折线图", "横向柱状图", "竖向柱状图", "曲线图", "面积图", "饼图" };
  87. m_indexCombo = new QComboBox(this);
  88. m_indexCombo->setFixedSize(QSize(150, 35));
  89. m_indexCombo->addItems(plots);
  90. m_indexCombo->setCurrentIndex(1);
  91. connect(m_indexCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSelectIndexPlotType(int)));
  92. // plots = QStringList { "竖向柱状图" };
  93. m_techCombo = new QComboBox(this);
  94. m_techCombo->setFixedSize(QSize(150, 35));
  95. m_techCombo->addItems(plots);
  96. m_techCombo->setCurrentIndex(1);
  97. connect(m_techCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSelectTechPlotType(int)));
  98. m_schemeCombo = new QComboBox(this);
  99. m_schemeCombo->setFixedSize(QSize(150, 35));
  100. m_schemeCombo->addItems(plots);
  101. m_schemeCombo->setCurrentIndex(2);
  102. connect(m_schemeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSelectSchemePlotType(int)));
  103. m_lastSchemeLev = new QPushButton("上一级指标");
  104. m_nextSchemeLev = new QPushButton("下一级指标");
  105. connect(m_lastSchemeLev, &QPushButton::clicked, this, &EvalReportWidget::slotLastSchemeLev);
  106. connect(m_nextSchemeLev, &QPushButton::clicked, this, &EvalReportWidget::slotNextSchemeLev);
  107. }
  108. void EvalReportWidget::initLayouts()
  109. {
  110. m_layout = new QVBoxLayout(m_view);
  111. m_gridLayout = new QGridLayout();
  112. m_layout->addLayout(m_gridLayout);
  113. QFont ft("Microsoft YaHei", 12);
  114. QStringList plots = { "折线图", "横向柱状图", "竖向柱状图", "曲线图", "面积图" };
  115. if (m_indexType != ProjectManager::TechIndex) {
  116. m_indexTitle = new QLabel(this);
  117. m_indexTitle->setText("指标权重");
  118. m_indexTitle->setFont(ft);
  119. m_indexTitle->setContentsMargins(0, 10, 0, 10);
  120. m_gridLayout->addWidget(m_indexTitle, 0, 0);
  121. m_gridLayout->addWidget(m_indexCombo, 0, 1);
  122. m_gridLayout->addWidget(m_indexTab, 1, 0);
  123. m_gridLayout->addWidget(m_indexPlot, 1, 1);
  124. } else {
  125. m_techTitle = new QLabel(this);
  126. m_techTitle->setText("技术措施重要度");
  127. m_techTitle->setFont(ft);
  128. m_techTitle->setContentsMargins(0, 10, 0, 10);
  129. m_gridLayout->addWidget(m_techTitle, 0, 0);
  130. m_gridLayout->addWidget(m_techCombo, 0, 1);
  131. m_gridLayout->addWidget(m_techTable, 1, 0);
  132. m_gridLayout->addWidget(m_techPlot, 1, 1);
  133. }
  134. if (m_indexType == ProjectManager::OptimalIndex || m_indexType == ProjectManager::EfficiencyIndex) {
  135. m_schemeTitle = new QLabel(this);
  136. m_schemeTitle->setFont(ft);
  137. m_schemeTitle->setFixedHeight(100);
  138. m_schemeTitle->setContentsMargins(0, 50, 0, 10);
  139. if (m_indexType == ProjectManager::OptimalIndex) {
  140. m_schemeTitle->setText("方案得分");
  141. m_gridLayout->addWidget(m_schemeTitle, 2, 0);
  142. m_gridLayout->addWidget(m_schemeTable, 3, 0);
  143. } else {
  144. m_schemeTitle->setText("效能分析");
  145. m_gridLayout->addWidget(m_schemeTitle, 2, 0);
  146. m_gridLayout->addWidget(m_EffiTab, 3, 0);
  147. QHBoxLayout *lay = new QHBoxLayout();
  148. lay->addWidget(m_lastSchemeLev);
  149. lay->addSpacing(20);
  150. lay->addWidget(m_nextSchemeLev);
  151. m_gridLayout->addLayout(lay, 4, 0);
  152. }
  153. m_gridLayout->addWidget(m_schemeCombo, 2, 1, Qt::AlignBottom);
  154. m_gridLayout->addWidget(m_schemePlot, 3, 1);
  155. }
  156. QScrollArea *scroll = new QScrollArea;
  157. scroll->setAlignment(Qt::AlignLeft);
  158. scroll->setWidget(m_view);
  159. QVBoxLayout *layout = new QVBoxLayout(this);
  160. layout->setMargin(0);
  161. layout->addWidget(scroll);
  162. }
  163. void EvalReportWidget::loadAlgs()
  164. {
  165. QList<SchemePlanManager::SchemeProcessInfo> processList;
  166. SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_proj->id, m_indexType);
  167. for (SchemePlanManager::SchemeProcessInfo process : processList) {
  168. QString algName = SchemePlanManager::nameOfAlgorithm(process.algorithm);
  169. if (process.type == SchemePlanManager::CalculateWeight) {
  170. m_weightAlg = process.algorithm;
  171. m_indexTitle->setText(m_indexTitle->text() + " (" + algName + ") ");
  172. } else if (process.type == SchemePlanManager::RunEvaluate) {
  173. m_evalAlg = process.algorithm;
  174. // m_techTitle->setText(m_techTitle->text() + " (" + algName + ") ");
  175. m_schemeTitle->setText(m_schemeTitle->text() + " (" + algName + ") ");
  176. }
  177. }
  178. }
  179. void EvalReportWidget::loadData()
  180. {
  181. QList<CNodeData> nodeList;
  182. CNodeDataService().QueryAllValid(nodeList, m_proj->id, m_indexType);
  183. m_mind = new CMind(this);
  184. m_mind->setNodeList(nodeList);
  185. if (checkDataComplete() == false) {
  186. return;
  187. }
  188. if (m_indexType != ProjectManager::TechIndex) {
  189. showIndexWeight();
  190. } else {
  191. showTechScore();
  192. }
  193. if (m_indexType == ProjectManager::OptimalIndex) {
  194. showSchemeScore();
  195. }
  196. if (m_indexType == ProjectManager::EfficiencyIndex) {
  197. showEffiResult();
  198. }
  199. }
  200. bool EvalReportWidget::checkDataComplete()
  201. {
  202. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_indexType);
  203. bool ret = NodeMatrixService().hasMeasureData(m_proj->id, indexName);
  204. if (ret == true) {
  205. return true;
  206. }
  207. QList<UserConfig *> cfgList;
  208. ret = UserConfigService().QueryUserConfigListInfoByEngineerId(&cfgList, m_proj->id);
  209. if (ret == false || cfgList.size() <= 0) {
  210. return false;
  211. }
  212. bool expertDataComplete = true;
  213. for (UserConfig *cfg : cfgList) {
  214. ret = NodeMatrixService().hasExpertData(m_proj->id, indexName, cfg->userId);
  215. if (ret == false) {
  216. expertDataComplete = false;
  217. break;
  218. }
  219. }
  220. return expertDataComplete;
  221. }
  222. void EvalReportWidget::showIndexWeight()
  223. {
  224. int levels = m_mind->levels();
  225. if (levels < 2) {
  226. return;
  227. }
  228. MindWeightInfo info;
  229. int indexType = m_indexType;
  230. if (indexType == ProjectManager::TechIndex) {
  231. indexType = ProjectManager::AbilityIndex;
  232. }
  233. bool ret = MindWeightService().queryWeightData(&info, m_proj->id, indexType);
  234. if (ret == false) {
  235. return;
  236. }
  237. if (info.id < 0) {
  238. qDebug() << __FUNCTION__ << __LINE__ << "未找到指标权重数据" << endl;
  239. return;
  240. }
  241. QMap<QString, double> weightData;
  242. QStringList weightList = info.weight.split(";");
  243. for (QString keyValueStr : weightList) {
  244. QStringList keyValue = keyValueStr.split(":");
  245. if (keyValue.size() == 2) {
  246. weightData[keyValue.first()] = keyValue.last().toDouble();
  247. }
  248. }
  249. for (int i = 2; i <= levels; i++) {
  250. QTableView *t = new QTableView();
  251. t->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  252. t->verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  253. t->setAlternatingRowColors(true);
  254. t->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  255. // t->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
  256. // t->setSelectionMode(QAbstractItemView::SingleSelection);
  257. DataTableItemModel *model = new DataTableItemModel();
  258. t->setModel(model);
  259. QStandardItem *hHeader = new QStandardItem("权重");
  260. model->setHorizontalHeaderItem(0, hHeader);
  261. QList<CNodeData> nodeList = m_mind->nodesInLevel(i);
  262. for (int j = 0; j < nodeList.size(); j++) {
  263. CNodeData node = nodeList[j];
  264. QStandardItem *vHeader = new QStandardItem(node.name);
  265. model->setVerticalHeaderItem(j, vHeader);
  266. QStandardItem *item = new QStandardItem();
  267. item->setText(QString("%1").arg(weightData[node.name]));
  268. item->setEditable(false);
  269. model->setItem(j, 0, item);
  270. }
  271. m_indexTab->addTab(t, QString("第%1级指标").arg(i));
  272. }
  273. }
  274. void EvalReportWidget::showIndexWeightPlot()
  275. {
  276. QTableView *table = (QTableView *)m_indexTab->currentWidget();
  277. if (table == nullptr) {
  278. return;
  279. }
  280. DataTableItemModel *model = (DataTableItemModel *)table->model();
  281. if (model == nullptr) {
  282. return;
  283. }
  284. QVector<PlotView::Data> values;
  285. for (int i = 0; i < model->rowCount(); i++) {
  286. QStandardItem *header = model->verticalHeaderItem(i);
  287. QStandardItem *item = model->item(i, 0);
  288. PlotView::Data data { header->text(), item->text().toDouble() };
  289. values.append(data);
  290. }
  291. if (m_indexPlot != nullptr) {
  292. m_gridLayout->removeWidget(m_indexPlot);
  293. m_indexPlot->deleteLater();
  294. m_indexPlot = nullptr;
  295. }
  296. if (m_indexPie != nullptr) {
  297. m_gridLayout->removeWidget(m_indexPie);
  298. m_indexPie->deleteLater();
  299. m_indexPie = nullptr;
  300. }
  301. if (m_indexCombo->currentIndex() < 5) {
  302. PlotView::PlotType type = (PlotView::PlotType)m_indexCombo->currentIndex();
  303. m_indexPlot = new PlotView(type, values, "", this);
  304. m_indexPlot->setFixedSize(kFigureSize);
  305. m_indexPlot->plot();
  306. m_gridLayout->addWidget(m_indexPlot, 1, 1);
  307. } else {
  308. QStringList tagList;
  309. QList<double> dataList;
  310. QList<QColor> colorList;
  311. for (int i = 0; i < values.size(); i++) {
  312. tagList.append("");
  313. double t = values[i].value;
  314. dataList.append(t);
  315. QColor color(20 + 200 / values.size() * i, 70 * (1.6 - i / values.size()), 150, 255);
  316. colorList.append(color);
  317. }
  318. m_indexPie = new CustomPieChart("", tagList, dataList, colorList);
  319. m_indexPie->setFixedSize(kFigureSize);
  320. m_gridLayout->addWidget(m_indexPie, 1, 1);
  321. }
  322. }
  323. void EvalReportWidget::showTechScore()
  324. {
  325. int levels = m_mind->levels();
  326. if (levels < 2) {
  327. return;
  328. }
  329. DataTableItemModel *model = (DataTableItemModel *)m_techTable->model();
  330. if (model == nullptr) {
  331. return;
  332. }
  333. MindScoreInfo info;
  334. bool ret = MindScoreService().queryScoreData(&info, m_proj->id);
  335. if (ret == false || info.id < 0) {
  336. return;
  337. }
  338. QMap<QString, QString> scoreData;
  339. QStringList keyValueStringList = info.score.split(";");
  340. for (QString keyValueString : keyValueStringList) {
  341. QStringList keyValue = keyValueString.split(":");
  342. if (keyValue.size() == 2) {
  343. scoreData[keyValue.first()] = keyValue.last();
  344. }
  345. }
  346. QStandardItem *hHeader = new QStandardItem("重要度");
  347. model->setHorizontalHeaderItem(0, hHeader);
  348. QList<CNodeData> nodeList = m_mind->leaves();
  349. QVector<PlotView::Data> values;
  350. for (int j = 0; j < nodeList.size(); j++) {
  351. CNodeData node = nodeList[j];
  352. QStandardItem *vHeader = new QStandardItem(node.name);
  353. model->setVerticalHeaderItem(j, vHeader);
  354. QStandardItem *item = new QStandardItem();
  355. item->setText(scoreData[node.name]);
  356. item->setEditable(false);
  357. model->setItem(j, 0, item);
  358. PlotView::Data data { vHeader->text(), item->text().toDouble() };
  359. values.append(data);
  360. }
  361. makePlotClear(m_techPlot);
  362. m_techPlot->updateData(values);
  363. }
  364. void EvalReportWidget::showTechScorePlot()
  365. {
  366. DataTableItemModel *model = (DataTableItemModel *)m_techTable->model();
  367. if (model == nullptr) {
  368. return;
  369. }
  370. QVector<PlotView::Data> values;
  371. for (int i = 0; i < model->rowCount(); i++) {
  372. QStandardItem *header = model->verticalHeaderItem(i);
  373. QStandardItem *item = model->item(i, 0);
  374. PlotView::Data data { header->text(), item->text().toDouble() };
  375. values.append(data);
  376. }
  377. if (m_techPlot != nullptr) {
  378. m_gridLayout->removeWidget(m_techPlot);
  379. m_techPlot->deleteLater();
  380. m_techPlot = nullptr;
  381. }
  382. if (m_techPie != nullptr) {
  383. m_gridLayout->removeWidget(m_techPie);
  384. m_techPie->deleteLater();
  385. m_techPie = nullptr;
  386. }
  387. if (m_techCombo->currentIndex() < 5) {
  388. PlotView::PlotType type = (PlotView::PlotType)m_techCombo->currentIndex();
  389. m_techPlot = new PlotView(type, values, "", this);
  390. m_techPlot->setFixedSize(kFigureSize);
  391. m_techPlot->plot();
  392. m_gridLayout->addWidget(m_techPlot, 1, 1);
  393. } else {
  394. QStringList tagList;
  395. QList<double> dataList;
  396. QList<QColor> colorList;
  397. for (int i = 0; i < values.size(); i++) {
  398. tagList.append("");
  399. double t = values[i].value;
  400. dataList.append(t);
  401. QColor color(20 + 200 / values.size() * i, 70 * (1.6 - i / values.size()), 150, 255);
  402. colorList.append(color);
  403. }
  404. m_techPie = new CustomPieChart("", tagList, dataList, colorList);
  405. m_techPie->setFixedSize(kFigureSize);
  406. m_gridLayout->addWidget(m_techPie, 1, 1);
  407. }
  408. }
  409. void EvalReportWidget::showSchemeScore()
  410. {
  411. int levels = m_mind->levels();
  412. if (levels < 2) {
  413. return;
  414. }
  415. DataTableItemModel *model = (DataTableItemModel *)m_schemeTable->model();
  416. if (model == nullptr) {
  417. return;
  418. }
  419. QList<SchemaEval *> schemeList;
  420. QVector<PlotView::Data> values;
  421. if (m_indexType == ProjectManager::EfficiencyIndex) {
  422. SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_proj->id, 1);
  423. }
  424. if (m_indexType == ProjectManager::OptimalIndex) {
  425. SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_proj->id, 0);
  426. QStandardItem *hHeader = new QStandardItem("得分");
  427. model->setHorizontalHeaderItem(0, hHeader);
  428. for (int i = 0; i < schemeList.size(); i++) {
  429. SchemaEval *scheme = schemeList[i];
  430. QStandardItem *vHeader = new QStandardItem(scheme->name);
  431. model->setVerticalHeaderItem(i, vHeader);
  432. QStandardItem *item = new QStandardItem(QString::number(scheme->score, 'f', 2));
  433. item->setEditable(false);
  434. PlotView::Data data { vHeader->text(), scheme->score };
  435. model->setItem(i, 0, item);
  436. values.append(data);
  437. }
  438. }
  439. makePlotClear(m_schemePlot);
  440. m_schemePlot->updateData(values);
  441. }
  442. void EvalReportWidget::showSchemeScorePlot()
  443. {
  444. DataTableItemModel *model = (DataTableItemModel *)m_schemeTable->model();
  445. if (model == nullptr) {
  446. return;
  447. }
  448. QVector<PlotView::Data> values;
  449. for (int i = 0; i < model->rowCount(); i++) {
  450. QStandardItem *header = model->verticalHeaderItem(i);
  451. QStandardItem *item = model->item(i, 0);
  452. PlotView::Data data { header->text(), item->text().toDouble() };
  453. values.append(data);
  454. }
  455. if (m_schemePlot != nullptr) {
  456. m_gridLayout->removeWidget(m_schemePlot);
  457. m_schemePlot->deleteLater();
  458. m_schemePlot = nullptr;
  459. }
  460. if (m_schemePie != nullptr) {
  461. m_gridLayout->removeWidget(m_schemePie);
  462. m_schemePie->deleteLater();
  463. m_schemePie = nullptr;
  464. }
  465. if (m_schemeCombo->currentIndex() < 5) {
  466. PlotView::PlotType type = (PlotView::PlotType)m_schemeCombo->currentIndex();
  467. m_schemePlot = new PlotView(type, values, "", this);
  468. m_schemePlot->setFixedSize(kFigureSize);
  469. m_schemePlot->plot();
  470. m_gridLayout->addWidget(m_schemePlot, 3, 1);
  471. } else {
  472. QStringList tagList;
  473. QList<double> dataList;
  474. QList<QColor> colorList;
  475. for (int i = 0; i < values.size(); i++) {
  476. tagList.append("");
  477. double t = values[i].value;
  478. dataList.append(t);
  479. QColor color(20 + 200 / values.size() * i, 70 * (1.6 - i / values.size()), 150, 255);
  480. colorList.append(color);
  481. }
  482. m_schemePie = new CustomPieChart("", tagList, dataList, colorList);
  483. m_schemePie->setFixedSize(kFigureSize);
  484. m_gridLayout->addWidget(m_schemePie, 3, 1);
  485. }
  486. }
  487. void EvalReportWidget::showEffiResult()
  488. {
  489. showEffiResultLev();
  490. return;
  491. m_EffiTab->clear();
  492. QList<GradeInfo *> gradeInfoList;
  493. int type = m_evalAlg == SchemePlanManager::MEA ? 0 : 1;
  494. bool gradeRet = GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, m_proj->id, type);
  495. if (gradeRet == false) {
  496. return;
  497. }
  498. QStringList gradeNames;
  499. for (int i = 0; i < gradeInfoList.size(); ++i) {
  500. gradeNames.append(gradeInfoList[i]->gradeValue);
  501. }
  502. QList<EffectResult> effList;
  503. bool effRet = EffectResultService().queryDataList(effList, m_proj->id);
  504. if (effRet == false) {
  505. return;
  506. }
  507. QMap<int, QMap<QString, QList<double>>> effData;
  508. QMap<int, QString> schemeNames;
  509. int levels = 0;
  510. for (EffectResult effect : effList) {
  511. if (effData.keys().contains(effect.schemeId) == false) {
  512. effData[effect.schemeId] = QMap<QString, QList<double>>();
  513. schemeNames[effect.schemeId] = effect.schemeName;
  514. }
  515. QStringList values = effect.value.split(",");
  516. levels = values.size();
  517. QList<double> valueList;
  518. for (int v = 0; v < values.size(); ++v) {
  519. valueList.append(values[v].toDouble());
  520. }
  521. effData[effect.schemeId][effect.indexName] = valueList;
  522. }
  523. for (int i = 0; i < effData.keys().size(); i++) {
  524. QTableView *t = new QTableView();
  525. t->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  526. t->verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  527. t->setAlternatingRowColors(true);
  528. t->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  529. DataTableItemModel *model = new DataTableItemModel();
  530. t->setModel(model);
  531. for (int lev = 0; lev < levels; lev++) {
  532. QStandardItem *hHeader = new QStandardItem(gradeNames[lev]);
  533. model->setHorizontalHeaderItem(lev, hHeader);
  534. }
  535. QStandardItem *vHeader = new QStandardItem("综合");
  536. model->setVerticalHeaderItem(0, vHeader);
  537. QList<CNodeData> nodeList = m_mind->nodesInLevel(m_mind->levels());
  538. for (int j = 0; j < nodeList.size(); j++) {
  539. CNodeData node = nodeList[j];
  540. QStandardItem *vHeader = new QStandardItem(node.name);
  541. model->setVerticalHeaderItem(j + 1, vHeader);
  542. }
  543. for (int r = 0; r < model->rowCount(); ++r) {
  544. QStandardItem *vHeader = model->verticalHeaderItem(r);
  545. QList<double> rowValues = effData[effData.keys()[i]][vHeader->text()];
  546. for (int c = 0; c < model->columnCount(); ++c) {
  547. QStandardItem *item = new QStandardItem();
  548. if (effData.keys().size() > i && rowValues.size() > c) {
  549. QString text = QString("%1").arg(rowValues[c]);
  550. if (std::isnan(rowValues[c])) {
  551. text = "0";
  552. }
  553. item->setText(text);
  554. }
  555. item->setEditable(false);
  556. model->setItem(r, c, item);
  557. }
  558. }
  559. m_EffiTab->addTab(t, schemeNames[effData.keys()[i]]);
  560. }
  561. }
  562. void EvalReportWidget::makePlotClear(PlotView *plotView)
  563. {
  564. plotView->clearGraphs();
  565. plotView->clearItems();
  566. plotView->clearMask();
  567. plotView->clearPlottables();
  568. }
  569. void EvalReportWidget::showEffiResultLev()
  570. {
  571. if (m_mind->levels() < 2) {
  572. return;
  573. }
  574. // 获取指标权重
  575. MindWeightInfo info;
  576. int indexType = m_indexType;
  577. if (indexType == ProjectManager::TechIndex) {
  578. indexType = ProjectManager::AbilityIndex;
  579. }
  580. bool ret = MindWeightService().queryWeightData(&info, m_proj->id, indexType);
  581. if (ret == false) {
  582. return;
  583. }
  584. if (info.id < 0) {
  585. qDebug() << __FUNCTION__ << __LINE__ << "未找到指标权重数据" << endl;
  586. return;
  587. }
  588. QMap<QString, double> weightData;
  589. QStringList weightList = info.weight.split(";");
  590. for (QString keyValueStr : weightList) {
  591. QStringList keyValue = keyValueStr.split(":");
  592. if (keyValue.size() == 2) {
  593. weightData[keyValue.first()] = keyValue.last().toDouble();
  594. }
  595. }
  596. int curTabIndex = m_EffiTab->currentIndex();
  597. m_EffiTab->clear();
  598. QList<GradeInfo *> gradeInfoList;
  599. int type = m_evalAlg == SchemePlanManager::MEA ? 0 : 1;
  600. bool gradeRet = GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, m_proj->id, type);
  601. if (gradeRet == false) {
  602. return;
  603. }
  604. QStringList gradeNames;
  605. for (int i = 0; i < gradeInfoList.size(); ++i) {
  606. gradeNames.append(gradeInfoList[i]->gradeValue);
  607. }
  608. QList<EffectResult> effList;
  609. bool effRet = EffectResultService().queryDataList(effList, m_proj->id);
  610. if (effRet == false) {
  611. return;
  612. }
  613. QMap<int, QMap<QString, QList<double>>> effData;
  614. QMap<int, QString> schemeNames;
  615. int levels = 0; // 效能分级
  616. for (EffectResult effect : effList) {
  617. if (effData.keys().contains(effect.schemeId) == false) {
  618. effData[effect.schemeId] = QMap<QString, QList<double>>();
  619. schemeNames[effect.schemeId] = effect.schemeName;
  620. }
  621. QStringList values = effect.value.split(",");
  622. levels = values.size();
  623. QList<double> valueList;
  624. for (int v = 0; v < values.size(); ++v) {
  625. valueList.append(values[v].toDouble());
  626. }
  627. effData[effect.schemeId][effect.indexName] = valueList;
  628. }
  629. for (int i = 0; i < effData.keys().size(); i++) {
  630. QTableView *t = new QTableView();
  631. t->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  632. t->verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  633. t->setAlternatingRowColors(true);
  634. t->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  635. DataTableItemModel *model = new DataTableItemModel();
  636. t->setModel(model);
  637. for (int lev = 0; lev < levels; lev++) {
  638. QStandardItem *hHeader = new QStandardItem(gradeNames[lev]);
  639. model->setHorizontalHeaderItem(lev, hHeader);
  640. }
  641. QStandardItem *vHeader = new QStandardItem("综合");
  642. model->setVerticalHeaderItem(0, vHeader);
  643. QList<CNodeData> nodeList = m_mind->nodesInLevel(m_curSchemeLev);
  644. for (int j = 0; j < nodeList.size(); j++) {
  645. CNodeData node = nodeList[j];
  646. QStandardItem *vHeader = new QStandardItem(node.name);
  647. model->setVerticalHeaderItem(j + 1, vHeader);
  648. }
  649. for (int r = 0; r < model->rowCount(); ++r) {
  650. QStandardItem *vHeader = model->verticalHeaderItem(r);
  651. QList<double> rowValues;
  652. if (m_curSchemeLev == m_mind->levels() || r == 0) {
  653. rowValues = effData[effData.keys()[i]][vHeader->text()];
  654. } else {
  655. QList<CNodeData> subNodes = m_mind->leavesOfNode(nodeList[r - 1]);
  656. for (int l = 0; l < levels; l++) {
  657. double sumValue = 0;
  658. double sumWeight = 0;
  659. for (int n = 0; n < subNodes.count(); n++) {
  660. QList<double> subNodeValues = effData[effData.keys()[i]][subNodes[n].name];
  661. double weight = weightData[subNodes[n].name];
  662. sumValue += subNodeValues[l] * weight;
  663. sumWeight += weight;
  664. }
  665. double finalValue = 0;
  666. if (sumWeight > 0) {
  667. finalValue = sumValue / sumWeight;
  668. }
  669. rowValues.append(finalValue);
  670. }
  671. }
  672. for (int c = 0; c < model->columnCount(); ++c) {
  673. QStandardItem *item = new QStandardItem();
  674. if (effData.keys().size() > i && rowValues.size() > c) {
  675. QString text = QString("%1").arg(rowValues[c]);
  676. if (std::isnan(rowValues[c])) {
  677. text = "0";
  678. }
  679. item->setText(text);
  680. }
  681. item->setEditable(false);
  682. model->setItem(r, c, item);
  683. }
  684. }
  685. m_EffiTab->addTab(t, schemeNames[effData.keys()[i]]);
  686. }
  687. if (curTabIndex >= 0) {
  688. m_EffiTab->setCurrentIndex(curTabIndex);
  689. }
  690. }
  691. void EvalReportWidget::slotSelectIndexPlotType(int)
  692. {
  693. showIndexWeightPlot();
  694. }
  695. void EvalReportWidget::slotSelectTechPlotType(int)
  696. {
  697. showTechScorePlot();
  698. }
  699. void EvalReportWidget::slotSelectSchemePlotType(int)
  700. {
  701. if (m_indexType == ProjectManager::OptimalIndex) {
  702. showSchemeScorePlot();
  703. }
  704. if (m_indexType == ProjectManager::EfficiencyIndex) {
  705. slotEffiTabIndexChanged(m_EffiTab->currentIndex());
  706. }
  707. }
  708. void EvalReportWidget::slotIndexTabIndexChanged(int)
  709. {
  710. showIndexWeightPlot();
  711. }
  712. void EvalReportWidget::slotEffiTabIndexChanged(int index)
  713. {
  714. QTableView *table = (QTableView *)m_EffiTab->currentWidget();
  715. if (table == nullptr) {
  716. return;
  717. }
  718. DataTableItemModel *model = (DataTableItemModel *)table->model();
  719. if (model == nullptr) {
  720. return;
  721. }
  722. QVector<PlotView::Data> values;
  723. for (int i = 0; i < model->columnCount(); i++) {
  724. QStandardItem *header = model->horizontalHeaderItem(i);
  725. QStandardItem *item = model->item(0, i);
  726. if (item != nullptr) {
  727. PlotView::Data data { header->text(), item->text().toDouble() };
  728. values.append(data);
  729. }
  730. }
  731. if (m_schemePlot != nullptr) {
  732. m_gridLayout->removeWidget(m_schemePlot);
  733. m_schemePlot->deleteLater();
  734. m_schemePlot = nullptr;
  735. }
  736. if (m_schemePie != nullptr) {
  737. m_gridLayout->removeWidget(m_schemePie);
  738. m_schemePie->deleteLater();
  739. m_schemePie = nullptr;
  740. }
  741. if (m_schemeCombo->currentIndex() < 5) {
  742. PlotView::PlotType type = (PlotView::PlotType)m_schemeCombo->currentIndex();
  743. m_schemePlot = new PlotView(type, values, "", this);
  744. m_schemePlot->setFixedSize(kFigureSize);
  745. m_schemePlot->plot();
  746. m_gridLayout->addWidget(m_schemePlot, 3, 1);
  747. } else {
  748. QStringList tagList;
  749. QList<double> dataList;
  750. QList<QColor> colorList;
  751. for (int i = 0; i < values.size(); i++) {
  752. tagList.append("");
  753. double t = values[i].value;
  754. dataList.append(t);
  755. QColor color(20 + 200 / values.size() * i, 70 * (1.6 - i / values.size()), 150, 255);
  756. colorList.append(color);
  757. }
  758. m_schemePie = new CustomPieChart("", tagList, dataList, colorList);
  759. m_schemePie->setFixedSize(kFigureSize);
  760. m_gridLayout->addWidget(m_schemePie, 3, 1);
  761. }
  762. }
  763. void EvalReportWidget::slotLastSchemeLev()
  764. {
  765. if (m_curSchemeLev > 2) {
  766. m_curSchemeLev--;
  767. }
  768. showEffiResultLev();
  769. }
  770. void EvalReportWidget::slotNextSchemeLev()
  771. {
  772. if (m_curSchemeLev < m_mind->levels()) {
  773. m_curSchemeLev++;
  774. }
  775. showEffiResultLev();
  776. }