AnalysisTableWidget.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. #include "AnalysisTableWidget.h"
  2. #include "RequirementImportance.h"
  3. #include "algorithm/ConsistencyCheck.h"
  4. #include <QDebug>
  5. #include <QHeaderView>
  6. #include <QTime>
  7. #include <QtMath>
  8. #include "dbService/ClassSet.h"
  9. #include <dbService/DBServiceSet.h>
  10. #include <dbService/NodeMatrixService.h>
  11. #include <dbService/DemandWeightService.h>
  12. #include <QList>
  13. AnalysisTableWidget::AnalysisTableWidget(QWidget *parent) : QTableView(parent)
  14. {
  15. qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
  16. // qDebug() << "AnalysisTableWidget---init";
  17. model = new QStandardItemModel();
  18. this->setModel(model);
  19. paintDone = false;
  20. connect(model, &QStandardItemModel::itemChanged, this, &AnalysisTableWidget::nodeValueChanged);
  21. }
  22. AnalysisTableWidget::~AnalysisTableWidget() { }
  23. void AnalysisTableWidget::addRowNode(QString node, QString name, QString remark)
  24. {
  25. matrixRows << AnalysisTableWidget::MatrixNode(node, name, remark);
  26. }
  27. void AnalysisTableWidget::addColNode(QString node, QString name, QString remark)
  28. {
  29. matrixCols << AnalysisTableWidget::MatrixNode(node, name, remark);
  30. }
  31. QList<AnalysisDataSource> AnalysisTableWidget::getSource() const
  32. {
  33. return dataSource;
  34. }
  35. void AnalysisTableWidget::setTableWeight(QList<DemandWeight *> firstWeight, QList<DemandWeight *> secondWeight)
  36. {
  37. m_firstTableWeight = firstWeight;
  38. m_secondTableWeight = secondWeight;
  39. }
  40. void AnalysisTableWidget::setTableIndexAndTableMsg(int index, int engineerId, QString expertId, QString tableMsg)
  41. {
  42. m_tableIndex = index;
  43. m_engineerId = engineerId;
  44. m_expertId = expertId;
  45. m_table_msg = tableMsg;
  46. }
  47. void AnalysisTableWidget::setTableMethod(QString method)
  48. {
  49. m_resultMethod = method;
  50. }
  51. void AnalysisTableWidget::paintMatrixTable(QList<NodeMatrixInfo *> nodeValueInfoList, int type)
  52. {
  53. int row = matrixRows.count();
  54. int col = matrixCols.count();
  55. this->horizontalHeader()->setStretchLastSection(true);
  56. this->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  57. this->setSelectionMode(QAbstractItemView::SingleSelection);
  58. this->setSelectionBehavior(QAbstractItemView::SelectItems);
  59. model->setHorizontalHeaderItem(0, new QStandardItem(""));
  60. if (type == IndexType::IndexTech || type == IndexType::SchemaEval) {
  61. for (int c = 0; c < col; ++c) {
  62. model->setHorizontalHeaderItem(c + 1, new QStandardItem(matrixCols[c].name));
  63. model->horizontalHeaderItem(c + 1)->setToolTip(matrixCols[c].remark);
  64. model->horizontalHeaderItem(c + 1)->setTextAlignment(Qt::AlignCenter);
  65. }
  66. model->setHorizontalHeaderItem(col + 1, new QStandardItem("权重"));
  67. model->horizontalHeaderItem(col + 1)->setToolTip("权重");
  68. QStringList nodes;
  69. QVector<qreal> nxn((int)qPow(row, 2), 0);
  70. for (int r = 0; r < row; ++r) {
  71. model->setItem(r, 0, new QStandardItem(matrixRows[r].name));
  72. nodes << model->item(r, 0)->text().trimmed();
  73. model->item(r, 0)->setToolTip(matrixRows[r].remark);
  74. model->item(r, 0)->setTextAlignment(Qt::AlignCenter);
  75. model->item(r, 0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  76. for (int c = 1; c < col + 1; ++c) {
  77. AnalysisDataSource data;
  78. data.row = r;
  79. data.col = c;
  80. data.changed = true;
  81. if (nodeValueInfoList.size() > 0) {
  82. for (NodeMatrixInfo *nodeMatrixInfo : nodeValueInfoList) {
  83. if (nodeMatrixInfo->abscissa == matrixRows[r].name
  84. && nodeMatrixInfo->ordinate == matrixCols[c - 1].name) {
  85. data.nodeValue = nodeMatrixInfo->nodeValue;
  86. }
  87. }
  88. } else {
  89. // data.nodeValue = "0";
  90. data.nodeValue = "";
  91. }
  92. model->setItem(r, c, new QStandardItem(data.nodeValue));
  93. QStringList content = model->item(r, c)->text().trimmed().split("/");
  94. if (content.size() == 1) {
  95. nxn[r * col + c - 1] = content[0].toDouble();
  96. } else {
  97. nxn[r * col + c - 1] = content[0].toDouble() / content[1].toDouble();
  98. }
  99. model->item(r, c)->setTextAlignment(Qt::AlignCenter);
  100. model->item(r, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  101. data.node = matrixRows[r].node;
  102. data.abscissa = matrixRows[r].name;
  103. data.ordinate = matrixCols[c - 1].name;
  104. dataSource << data;
  105. }
  106. }
  107. ConsistencyCheck cc(nodes, nxn);
  108. for (int r = 0; r < row; ++r) {
  109. model->setItem(r, col + 1,
  110. new QStandardItem(QString::number(cc.getWeights().at(r)) == "nan"
  111. ? ""
  112. : QString::number(cc.getWeights().at(r))));
  113. model->item(r, col + 1)->setTextAlignment(Qt::AlignCenter);
  114. model->item(r, col + 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  115. }
  116. QStringList nodeList = cc.getNodes();
  117. QVector<qreal> weights = cc.getWeights();
  118. // qDebug() << weights;
  119. QList<DemandWeight *> list;
  120. for (int i = 0; i < weights.length(); i++) {
  121. DemandWeight *demandWeight = new DemandWeight();
  122. demandWeight->nodeName = nodeList.at(i);
  123. demandWeight->nodeWeight = weights.at(i);
  124. demandWeight->nodeValue = weights.at(i);
  125. demandWeight->engineerId = m_engineerId;
  126. demandWeight->expertId = m_expertId;
  127. demandWeight->isValid = 1;
  128. demandWeight->tableIndex = m_tableIndex;
  129. demandWeight->tableMsg = m_table_msg;
  130. demandWeight->pageIndex = 0;
  131. list.append(demandWeight);
  132. }
  133. if (DemandWeightService().QueryByTableIndexAndTableMsg(m_expertId, m_engineerId, m_tableIndex, m_table_msg)) {
  134. DemandWeightService().UpdateNodeValueList(list);
  135. } else {
  136. DemandWeightService().AddNodeWeightInfoList(list);
  137. }
  138. } else {
  139. // 获取到指标体系需求重要度
  140. model->setHorizontalHeaderItem(1, new QStandardItem("权重"));
  141. model->horizontalHeaderItem(1)->setToolTip("权重");
  142. for (int c = 0; c < col; ++c) {
  143. model->setHorizontalHeaderItem(c + 2, new QStandardItem(matrixCols[c].name));
  144. model->horizontalHeaderItem(c + 2)->setToolTip(matrixCols[c].remark);
  145. }
  146. for (int r = 0; r < row; ++r) {
  147. model->setItem(r, 0, new QStandardItem(matrixRows[r].name));
  148. model->item(r, 0)->setToolTip(matrixRows[r].remark);
  149. model->item(r, 0)->setTextAlignment(Qt::AlignCenter);
  150. model->item(r, 0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  151. if (r >= m_secondTableWeight.count()) {
  152. model->setItem(r, 1, new QStandardItem(""));
  153. } else {
  154. model->setItem(r, 1,
  155. new QStandardItem(QString::number(m_secondTableWeight.at(r)->nodeValue) == "nan"
  156. ? ""
  157. : QString::number(m_secondTableWeight.at(r)->nodeValue)));
  158. }
  159. model->item(r, 1)->setTextAlignment(Qt::AlignCenter);
  160. model->item(r, 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  161. for (int c = 2; c < col + 2; ++c) {
  162. AnalysisDataSource data;
  163. data.row = r;
  164. data.col = c;
  165. data.changed = true;
  166. if (nodeValueInfoList.size() > 0) {
  167. for (NodeMatrixInfo *nodeMatrixInfo : nodeValueInfoList) {
  168. if (nodeMatrixInfo->abscissa == matrixRows[r].name
  169. && nodeMatrixInfo->ordinate == matrixCols[c - 2].name) {
  170. data.nodeValue = nodeMatrixInfo->nodeValue;
  171. }
  172. }
  173. } else {
  174. data.nodeValue = "";
  175. }
  176. model->setItem(r, c, new QStandardItem(data.nodeValue));
  177. model->item(r, c)->setTextAlignment(Qt::AlignCenter);
  178. model->item(r, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  179. data.node = matrixRows[r].node;
  180. data.abscissa = matrixRows[r].name;
  181. data.ordinate = matrixCols[c - 2].name;
  182. dataSource << data;
  183. }
  184. }
  185. for (int c = 0; c < col + 2; ++c) {
  186. if (c == 0) {
  187. model->setItem(row, c, new QStandardItem("技术重要度"));
  188. } else if (c > 1 && c < col + 2) {
  189. qreal value = 0;
  190. for (int r = 0; r < row; r++) {
  191. if (r < m_secondTableWeight.count()) {
  192. QStandardItem *item = model->item(r, c);
  193. QStringList content = item->text().trimmed().split("/");
  194. double itemValue = 0;
  195. if (content.size() == 1) {
  196. itemValue = content[0].toDouble();
  197. } else {
  198. itemValue = content[0].toDouble() / content[1].toDouble();
  199. }
  200. double tempValue = 0;
  201. if (QString::number(m_secondTableWeight.at(r)->nodeValue) != "nan") {
  202. tempValue = m_secondTableWeight.at(r)->nodeValue;
  203. }
  204. value += itemValue * tempValue;
  205. }
  206. }
  207. model->setItem(row, c, new QStandardItem(QString::number(value)));
  208. } else {
  209. model->setItem(row, c, new QStandardItem(""));
  210. }
  211. model->item(row, c)->setTextAlignment(Qt::AlignCenter);
  212. model->item(row, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  213. }
  214. // 保存技术重要度
  215. QList<TechnicalImport *> importList;
  216. for (int c = 0; c < col; c++) {
  217. QStandardItem *item = model->item(row, c + 2);
  218. TechnicalImport *import = new TechnicalImport();
  219. import->engineerId = m_engineerId;
  220. import->expertId = m_expertId.toInt();
  221. import->nodeName = matrixCols[c].name;
  222. import->nodeValue = item->text().toDouble();
  223. importList.append(import);
  224. }
  225. if (DBServiceSet().QueryTechnicalImportInfoByEngineerId(m_expertId.toInt(), m_engineerId)) {
  226. DBServiceSet().UpdateTechnicalImportInfoList(importList);
  227. } else {
  228. DBServiceSet().AddTechnicalImportInfoList(importList);
  229. }
  230. }
  231. emit returnModel(model);
  232. paintDone = true;
  233. }
  234. void AnalysisTableWidget::paintCompositeMatrixTable(QList<NodeMatrixInfo *> nodeValueInfoList, int type)
  235. {
  236. int row = matrixRows.count();
  237. int col = matrixCols.count();
  238. this->horizontalHeader()->setStretchLastSection(true);
  239. this->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  240. this->setSelectionMode(QAbstractItemView::SingleSelection);
  241. this->setSelectionBehavior(QAbstractItemView::SelectItems);
  242. model->setHorizontalHeaderItem(0, new QStandardItem(""));
  243. if (type == IndexType::IndexTech || type == IndexType::SchemaEval) {
  244. for (int c = 0; c < col; ++c) {
  245. model->setHorizontalHeaderItem(c + 1, new QStandardItem(matrixCols[c].name));
  246. model->horizontalHeaderItem(c + 1)->setToolTip(matrixCols[c].remark);
  247. }
  248. model->setHorizontalHeaderItem(col + 1, new QStandardItem("权重"));
  249. model->horizontalHeaderItem(col + 1)->setToolTip("权重");
  250. QStringList nodes;
  251. QVector<qreal> nxn((int)qPow(row, 2), 0);
  252. for (int r = 0; r < row; ++r) {
  253. model->setItem(r, 0, new QStandardItem(matrixRows[r].name));
  254. nodes << model->item(r, 0)->text().trimmed();
  255. model->item(r, 0)->setToolTip(matrixRows[r].remark);
  256. model->item(r, 0)->setTextAlignment(Qt::AlignCenter);
  257. model->item(r, 0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  258. for (int c = 1; c < col + 1; ++c) {
  259. AnalysisDataSource data;
  260. data.row = r;
  261. data.col = c;
  262. data.changed = true;
  263. for (NodeMatrixInfo *nodeMatrixInfo : nodeValueInfoList) {
  264. if (nodeMatrixInfo->abscissa == matrixRows[r].name
  265. && nodeMatrixInfo->ordinate == matrixCols[c - 1].name) {
  266. data.nodeValue = nodeMatrixInfo->nodeValue;
  267. }
  268. }
  269. model->setItem(r, c, new QStandardItem(data.nodeValue));
  270. QStringList content = model->item(r, c)->text().trimmed().split("/");
  271. if (content.size() == 1) {
  272. nxn[r * col + c - 1] = content[0].toDouble();
  273. } else {
  274. nxn[r * col + c - 1] = content[0].toDouble() / content[1].toDouble();
  275. }
  276. model->item(r, c)->setTextAlignment(Qt::AlignCenter);
  277. model->item(r, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  278. data.node = matrixRows[r].node;
  279. data.abscissa = matrixRows[r].name;
  280. data.ordinate = matrixCols[c - 1].name;
  281. dataSource << data;
  282. }
  283. }
  284. ConsistencyCheck cc(nodes, nxn);
  285. for (int r = 0; r < row; ++r) {
  286. model->setItem(r, col + 1, new QStandardItem(QString::number(cc.getWeights().at(r))));
  287. model->item(r, col + 1)->setTextAlignment(Qt::AlignCenter);
  288. model->item(r, col + 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  289. }
  290. QStringList nodeList = cc.getNodes();
  291. QVector<qreal> weights = cc.getWeights();
  292. QList<DemandWeight *> list;
  293. for (int i = 0; i < weights.length(); i++) {
  294. DemandWeight *demandWeight = new DemandWeight();
  295. demandWeight->nodeName = nodeList.at(i);
  296. demandWeight->nodeWeight = weights.at(i);
  297. demandWeight->nodeValue = weights.at(i);
  298. demandWeight->engineerId = m_engineerId;
  299. demandWeight->expertId = m_expertId;
  300. demandWeight->isValid = 1;
  301. demandWeight->tableIndex = m_tableIndex;
  302. demandWeight->tableMsg = m_table_msg;
  303. list.append(demandWeight);
  304. }
  305. if (DemandWeightService().QueryByTableIndexAndTableMsg(m_expertId, m_engineerId, m_tableIndex, m_table_msg)) {
  306. DemandWeightService().UpdateNodeValueList(list);
  307. } else {
  308. DemandWeightService().AddNodeWeightInfoList(list);
  309. }
  310. } else {
  311. // 获取到指标体系需求重要度
  312. model->setHorizontalHeaderItem(1, new QStandardItem("权重"));
  313. model->horizontalHeaderItem(1)->setToolTip("权重");
  314. for (int c = 0; c < col; ++c) {
  315. model->setHorizontalHeaderItem(c + 2, new QStandardItem(matrixCols[c].name));
  316. model->horizontalHeaderItem(c + 2)->setToolTip(matrixCols[c].remark);
  317. }
  318. for (int r = 0; r < row; ++r) {
  319. model->setItem(r, 0, new QStandardItem(matrixRows[r].name));
  320. model->item(r, 0)->setToolTip(matrixRows[r].remark);
  321. model->item(r, 0)->setTextAlignment(Qt::AlignCenter);
  322. model->item(r, 0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  323. if (r >= m_secondTableWeight.count()) {
  324. model->setItem(r, 1, new QStandardItem(""));
  325. } else {
  326. model->setItem(r, 1, new QStandardItem(QString::number(m_secondTableWeight.at(r)->nodeValue)));
  327. }
  328. model->item(r, 1)->setTextAlignment(Qt::AlignCenter);
  329. model->item(r, 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  330. for (int c = 2; c < col + 2; ++c) {
  331. AnalysisDataSource data;
  332. data.row = r;
  333. data.col = c;
  334. data.changed = true;
  335. for (NodeMatrixInfo *nodeMatrixInfo : nodeValueInfoList) {
  336. if (nodeMatrixInfo->abscissa == matrixRows[r].name
  337. && nodeMatrixInfo->ordinate == matrixCols[c - 2].name) {
  338. data.nodeValue = nodeMatrixInfo->nodeValue;
  339. }
  340. }
  341. model->setItem(r, c, new QStandardItem(data.nodeValue));
  342. model->item(r, c)->setTextAlignment(Qt::AlignCenter);
  343. model->item(r, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  344. data.node = matrixRows[r].node;
  345. data.abscissa = matrixRows[r].name;
  346. data.ordinate = matrixCols[c - 2].name;
  347. dataSource << data;
  348. }
  349. }
  350. for (int c = 0; c < col + 2; ++c) {
  351. if (c == 0) {
  352. model->setItem(row, c, new QStandardItem("技术重要度"));
  353. } else if (c > 1 && c < col + 2) {
  354. qreal value = 0;
  355. for (int r = 0; r < row; r++) {
  356. if (r < m_secondTableWeight.count()) {
  357. QStandardItem *item = model->item(r, c);
  358. QStringList content = item->text().trimmed().split("/");
  359. double itemValue = 0;
  360. if (content.size() == 1) {
  361. itemValue = content[0].toDouble();
  362. } else {
  363. itemValue = content[0].toDouble() / content[1].toDouble();
  364. }
  365. value += itemValue * m_secondTableWeight.at(r)->nodeValue;
  366. }
  367. }
  368. model->setItem(row, c, new QStandardItem(QString::number(value)));
  369. } else {
  370. model->setItem(row, c, new QStandardItem(""));
  371. }
  372. model->item(row, c)->setTextAlignment(Qt::AlignCenter);
  373. model->item(row, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  374. }
  375. }
  376. emit returnModel(model);
  377. paintDone = true;
  378. }
  379. void AnalysisTableWidget::paintSecondMatrixTable(QList<NodeMatrixInfo *> nodeValueInfoList, int page, int type,
  380. int index)
  381. {
  382. // qDebug() << "----------o---" << index;
  383. int row = matrixRows.count();
  384. int col = matrixCols.count();
  385. this->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  386. this->setSelectionMode(QAbstractItemView::SingleSelection);
  387. this->setSelectionBehavior(QAbstractItemView::SelectItems);
  388. model->setHorizontalHeaderItem(0, new QStandardItem(""));
  389. if (type == IndexType::IndexTech || type == IndexType::SchemaEval) {
  390. for (int c = 0; c < col; ++c) {
  391. model->setHorizontalHeaderItem(c + 1, new QStandardItem(matrixCols[c].name));
  392. model->horizontalHeaderItem(c + 1)->setToolTip(matrixCols[c].remark);
  393. }
  394. model->setHorizontalHeaderItem(col + 1, new QStandardItem("权重"));
  395. model->horizontalHeaderItem(col + 1)->setToolTip("权重");
  396. model->setHorizontalHeaderItem(col + 2, new QStandardItem("需求重要度"));
  397. model->horizontalHeaderItem(col + 2)->setToolTip("需求重要度");
  398. QStringList nodes;
  399. QVector<qreal> nxn((int)qPow(row, 2), 0);
  400. for (int r = 0; r < row; ++r) {
  401. model->setItem(r, 0, new QStandardItem(matrixRows[r].name));
  402. nodes << model->item(r, 0)->text().trimmed();
  403. model->item(r, 0)->setToolTip(matrixRows[r].remark);
  404. model->item(r, 0)->setTextAlignment(Qt::AlignCenter);
  405. model->item(r, 0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  406. for (int c = 1; c < col + 1; ++c) {
  407. AnalysisDataSource data;
  408. data.row = r;
  409. data.col = c;
  410. data.changed = true;
  411. if (nodeValueInfoList.size() > 0) {
  412. for (NodeMatrixInfo *nodeMatrixInfo : nodeValueInfoList) {
  413. if (nodeMatrixInfo->abscissa == matrixRows[r].name
  414. && nodeMatrixInfo->ordinate == matrixCols[c - 1].name) {
  415. data.nodeValue = nodeMatrixInfo->nodeValue;
  416. }
  417. }
  418. } else {
  419. // data.nodeValue = "0";
  420. data.nodeValue = "";
  421. }
  422. model->setItem(r, c, new QStandardItem(data.nodeValue));
  423. QStringList content = model->item(r, c)->text().trimmed().split("/");
  424. if (content.size() == 1) {
  425. nxn[r * col + c - 1] = content[0].toDouble();
  426. } else {
  427. nxn[r * col + c - 1] = content[0].toDouble() / content[1].toDouble();
  428. }
  429. model->item(r, c)->setTextAlignment(Qt::AlignCenter);
  430. model->item(r, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  431. data.node = matrixRows[r].node;
  432. data.abscissa = matrixRows[r].name;
  433. data.ordinate = matrixCols[c - 1].name;
  434. dataSource << data;
  435. }
  436. }
  437. ConsistencyCheck cc(nodes, nxn);
  438. for (int r = 0; r < row; ++r) {
  439. model->setItem(r, col + 1,
  440. new QStandardItem(QString::number(cc.getWeights().at(r)) == "nan"
  441. ? ""
  442. : QString::number(cc.getWeights().at(r))));
  443. model->item(r, col + 1)->setTextAlignment(Qt::AlignCenter);
  444. model->item(r, col + 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  445. qreal firstWeight = 0;
  446. if (m_firstTableWeight.size() > 0) {
  447. firstWeight = m_firstTableWeight.at(index - 1)->nodeWeight;
  448. }
  449. qreal value = cc.getWeights().at(r) * firstWeight;
  450. model->setItem(r, col + 2,
  451. new QStandardItem(QString::number(value) == "nan" ? "" : QString::number(value)));
  452. model->item(r, col + 2)->setTextAlignment(Qt::AlignCenter);
  453. model->item(r, col + 2)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  454. }
  455. // 校验成功持久化数据
  456. QStringList nodeList = cc.getNodes();
  457. QVector<qreal> weights = cc.getWeights();
  458. QList<DemandWeight *> list;
  459. QList<DemandWeight *> firstList;
  460. // DBServiceSet().QueryByTableIndexAndTableMsg(&firstList, m_expertId, m_engineerId, 0, m_table_msg);
  461. DemandWeightService().QueryByTableIndexAndTableMsg(&firstList, m_expertId, m_engineerId, page - 1, m_table_msg);
  462. double weight = 0;
  463. // if (firstList.size() != 0) {
  464. weight = m_firstTableWeight.at(index - 1)->nodeWeight;
  465. //}
  466. for (int i = 0; i < weights.length(); i++) {
  467. DemandWeight *demandWeight = new DemandWeight();
  468. demandWeight->nodeName = nodeList.at(i);
  469. demandWeight->nodeWeight = weights.at(i);
  470. demandWeight->engineerId = m_engineerId;
  471. demandWeight->expertId = m_expertId;
  472. demandWeight->isValid = 1;
  473. demandWeight->tableIndex = m_tableIndex;
  474. demandWeight->tableMsg = m_table_msg;
  475. demandWeight->nodeValue = demandWeight->nodeWeight * weight;
  476. demandWeight->pageIndex = page;
  477. list.append(demandWeight);
  478. }
  479. if (DemandWeightService().QueryByTableIndexAndTableMsgAndPage(m_expertId, m_engineerId, m_tableIndex,
  480. m_table_msg, page)) {
  481. DemandWeightService().UpdateNodeValueList(list);
  482. } else {
  483. DemandWeightService().AddNodeWeightInfoList(list);
  484. }
  485. } else {
  486. model->setHorizontalHeaderItem(1, new QStandardItem("权重"));
  487. model->horizontalHeaderItem(1)->setToolTip("权重");
  488. for (int c = 0; c < col; ++c) {
  489. model->setHorizontalHeaderItem(c + 2, new QStandardItem(matrixCols[c].name));
  490. model->horizontalHeaderItem(c + 2)->setToolTip(matrixCols[c].remark);
  491. }
  492. for (int r = 0; r < row; ++r) {
  493. model->setItem(r, 0, new QStandardItem(matrixRows[r].name));
  494. model->item(r, 0)->setToolTip(matrixRows[r].remark);
  495. model->item(r, 0)->setTextAlignment(Qt::AlignCenter);
  496. model->item(r, 0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  497. if (r >= m_secondTableWeight.count()) {
  498. model->setItem(r, 1, new QStandardItem("1"));
  499. } else {
  500. model->setItem(r, 1,
  501. new QStandardItem(QString::number(m_secondTableWeight.at(r)->nodeValue) == "nan"
  502. ? ""
  503. : QString::number(m_secondTableWeight.at(r)->nodeValue)));
  504. }
  505. model->item(r, 1)->setTextAlignment(Qt::AlignCenter);
  506. model->item(r, 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  507. for (int c = 2; c < col + 2; ++c) {
  508. AnalysisDataSource data;
  509. data.row = r;
  510. data.col = c;
  511. data.changed = true;
  512. if (nodeValueInfoList.size() > 0) {
  513. for (NodeMatrixInfo *nodeMatrixInfo : nodeValueInfoList) {
  514. if (nodeMatrixInfo->abscissa == matrixRows[r].name
  515. && nodeMatrixInfo->ordinate == matrixCols[c - 2].name) {
  516. data.nodeValue = nodeMatrixInfo->nodeValue;
  517. }
  518. }
  519. } else {
  520. data.nodeValue = "";
  521. }
  522. model->setItem(r, c, new QStandardItem(data.nodeValue));
  523. model->item(r, c)->setTextAlignment(Qt::AlignCenter);
  524. model->item(r, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  525. data.node = matrixRows[r].node;
  526. data.abscissa = matrixRows[r].name;
  527. data.ordinate = matrixCols[c - 2].name;
  528. dataSource << data;
  529. }
  530. }
  531. for (int c = 0; c < col + 2; ++c) {
  532. if (c == 0) {
  533. model->setItem(row, c, new QStandardItem("技术重要度"));
  534. } else if (c > 1 && c < col + 2) {
  535. qreal value = 0;
  536. for (int r = 0; r < row; r++) {
  537. if (r < m_secondTableWeight.count()) {
  538. QStandardItem *item = model->item(r, c);
  539. QStringList content = item->text().trimmed().split("/");
  540. double itemValue = 0;
  541. if (content.size() == 1) {
  542. itemValue = content[0].toDouble();
  543. } else {
  544. itemValue = content[0].toDouble() / content[1].toDouble();
  545. }
  546. double tempValue = 0;
  547. if (QString::number(m_secondTableWeight.at(r)->nodeValue) != "nan") {
  548. tempValue = m_secondTableWeight.at(r)->nodeValue;
  549. }
  550. value += itemValue * tempValue;
  551. }
  552. }
  553. model->setItem(row, c, new QStandardItem(QString::number(value)));
  554. } else {
  555. model->setItem(row, c, new QStandardItem(""));
  556. }
  557. model->item(row, c)->setTextAlignment(Qt::AlignCenter);
  558. model->item(row, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
  559. }
  560. }
  561. emit returnModel(model);
  562. paintDone = true;
  563. // qDebug() << "--------ok";
  564. }
  565. void AnalysisTableWidget::nodeValueChanged(QStandardItem *item)
  566. {
  567. if (paintDone) {
  568. // qDebug() << item->column() << item->row() << item->text();
  569. }
  570. }
  571. bool AnalysisTableWidget::isDataReady() const
  572. {
  573. if (dataSource.count() == 0) {
  574. return false;
  575. }
  576. for (AnalysisDataSource data : dataSource) {
  577. if (data.changed == false) {
  578. return false;
  579. }
  580. }
  581. return true;
  582. }