DataTableWidget.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. #include "DataTableWidget.h"
  2. #include "DataTableItemDelegate.h"
  3. #include "ProjectManager.h"
  4. #include <dbService/CNodeDataService.h>
  5. #include <dbService/ClassSet.h>
  6. #include <dbService/NodeMatrixService.h>
  7. #include <dbService/SchemeInfoService.h>
  8. #include <Widgets/Button.h>
  9. #include <QBoxLayout>
  10. #include <QTabWidget>
  11. #include <QLabel>
  12. #include <QTableView>
  13. #include <QTableWidget>
  14. #include <QAbstractItemModel>
  15. #include <QStandardItemModel>
  16. #include <QStandardItem>
  17. #include <QHeaderView>
  18. #include <QDebug>
  19. static const char *kDataTabName = "tabName";
  20. static const char *kUUIDName = "uuidName";
  21. DataTableItemModel::DataTableItemModel(QObject *parent) : QStandardItemModel(parent) { }
  22. QVariant DataTableItemModel::data(const QModelIndex &index, int role) const
  23. {
  24. QVariant value = QStandardItemModel::data(index, role);
  25. if (Qt::TextAlignmentRole == role) {
  26. value = Qt::AlignCenter;
  27. }
  28. return value;
  29. }
  30. DataTableWidget::DataTableWidget(SchemePlanManager::SchemeProcessInfo process, QWidget *parent)
  31. : QWidget(parent), m_process(process)
  32. {
  33. m_mind1 = new CMind(this);
  34. m_mind2 = new CMind(this);
  35. initWidget();
  36. initLayout();
  37. connectSignalsAndSlots();
  38. m_comboDelegate = new DataTableComboDelegate(this);
  39. }
  40. SchemePlanManager::SchemeProcessInfo DataTableWidget::process() const
  41. {
  42. return m_process;
  43. }
  44. void DataTableWidget::initWidget()
  45. {
  46. m_dataTab = new QTabWidget(this);
  47. m_dataTab->setTabPosition(QTabWidget::South);
  48. m_pageLab = new QLabel(this);
  49. m_previous = new PushButton("上一级指标", this);
  50. m_next = new PushButton("下一级指标", this);
  51. }
  52. void DataTableWidget::initLayout()
  53. {
  54. m_layout = new QVBoxLayout(this);
  55. m_layout->setMargin(0);
  56. m_layout->addWidget(m_dataTab);
  57. m_pageLayout = new QHBoxLayout();
  58. m_layout->addLayout(m_pageLayout);
  59. m_pageLayout->setSpacing(10);
  60. m_pageLayout->addStretch();
  61. m_pageLayout->addWidget(m_previous);
  62. m_pageLayout->addWidget(m_pageLab);
  63. m_pageLayout->addWidget(m_next);
  64. m_pageLayout->addStretch();
  65. }
  66. void DataTableWidget::connectSignalsAndSlots()
  67. {
  68. connect(m_previous, &PushButton::clicked, this, &DataTableWidget::slotPrevious);
  69. connect(m_next, &PushButton::clicked, this, &DataTableWidget::slotNext);
  70. connect(m_dataTab, &QTabWidget::currentChanged, this, &DataTableWidget::slotTabCurrentChanged);
  71. }
  72. void DataTableWidget::setupModels()
  73. {
  74. // 按照脑图层级创建各个表的 models
  75. m_models.clear();
  76. QList<CNodeData> hHeaders;
  77. QList<CNodeData> vHeaders;
  78. for (int i = 1; i < m_mind1->levels(); i++) {
  79. QList<DataTableItemModel *> modelList;
  80. /// 方案优选和综合效能的评估数据采集
  81. /// 页面只有一级, 不用切换页面
  82. /// 方案优选显示指标量纲和指标类型
  83. /// 综合效能显示指标类型
  84. if (m_process.type == SchemePlanManager::ImportEvalData
  85. && (m_process.indexType == ProjectManager::OptimalIndex
  86. || m_process.indexType == ProjectManager::EfficiencyIndex)) {
  87. DataTableItemModel *model = new DataTableItemModel(this);
  88. int hIndex = -1;
  89. QStandardItem *item = new QStandardItem("指标量纲");
  90. model->setHorizontalHeaderItem(++hIndex, item);
  91. vHeaders = m_mind1->leaves();
  92. for (int j = 0; j < vHeaders.count(); j++) {
  93. CNodeData node = vHeaders[j];
  94. QStandardItem *item = new QStandardItem();
  95. item->setEditable(false);
  96. item->setText(node.dimension);
  97. model->setItem(j, hIndex, item);
  98. }
  99. if (m_process.indexType == ProjectManager::OptimalIndex) {
  100. QStandardItem *item = new QStandardItem("指标类型");
  101. model->setHorizontalHeaderItem(++hIndex, item);
  102. for (int k = 0; k < vHeaders.count(); k++) {
  103. CNodeData node = vHeaders[k];
  104. QStandardItem *item = new QStandardItem();
  105. item->setEditable(false);
  106. SchemePlanManager::IndexCostType cost = (SchemePlanManager::IndexCostType)node.type;
  107. item->setText(SchemePlanManager::stringFromIndexCostType(cost));
  108. model->setItem(k, hIndex, item);
  109. }
  110. }
  111. updateModel(model, hHeaders, vHeaders, hIndex);
  112. hIndex += hHeaders.size();
  113. m_schemeList.clear();
  114. if (m_process.indexType == ProjectManager::EfficiencyIndex) {
  115. SchemeInfoService().QuerySchemeInfoByEngineerId(&m_schemeList, m_process.projectId, 1);
  116. }
  117. if (m_process.indexType == ProjectManager::OptimalIndex) {
  118. SchemeInfoService().QuerySchemeInfoByEngineerId(&m_schemeList, m_process.projectId, 0);
  119. }
  120. m_schemeStartIndex = hIndex + 1;
  121. if (m_schemeList.count() > 0) {
  122. for (SchemaEval *scheme : m_schemeList) {
  123. QStandardItem *item = new QStandardItem(scheme->name);
  124. model->setHorizontalHeaderItem(++hIndex, item);
  125. for (QString indexValue : scheme->valueStr.split(";")) {
  126. QStringList indexAndValue = indexValue.split(":");
  127. if (indexAndValue.size() < 2) {
  128. continue;
  129. }
  130. for (int l = 0; l < model->rowCount(); l++) {
  131. QStandardItem *hHeader = model->verticalHeaderItem(l);
  132. if (hHeader->text() == indexAndValue.first()) {
  133. QStandardItem *item = new QStandardItem(indexAndValue.last());
  134. item->setData(indexAndValue.last());
  135. model->setItem(l, hIndex, item);
  136. }
  137. }
  138. }
  139. }
  140. }
  141. modelList.append(model);
  142. m_models[i] = modelList;
  143. break;
  144. }
  145. /// 权重分析数据: 能力重要度评估,方案优选评估,综合效能评估
  146. /// 评估数据: 技术措施重要度评估
  147. QList<CNodeData> nodes = m_mind1->nodesInLevel(i);
  148. for (int j = 0; j < nodes.count(); j++) {
  149. CNodeData node = nodes[j];
  150. DataTableItemModel *model = new DataTableItemModel(this);
  151. if (m_process.type == SchemePlanManager::ImportWeightData) {
  152. hHeaders = m_mind1->subNodes(node);
  153. if (m_process.dSource == SchemePlanManager::FromExpert) {
  154. vHeaders = hHeaders;
  155. }
  156. }
  157. if (m_process.type == SchemePlanManager::ImportEvalData) {
  158. if (m_process.indexType == ProjectManager::TechIndex) {
  159. hHeaders = m_mind1->subNodes(node);
  160. vHeaders = m_mind2->leaves();
  161. }
  162. }
  163. model->setProperty(kDataTabName, node.name);
  164. updateModel(model, hHeaders, vHeaders);
  165. modelList.append(model);
  166. }
  167. m_models[i] = modelList;
  168. }
  169. for (auto modelList : m_models.values()) {
  170. for (auto model : modelList) {
  171. connect(model, &QStandardItemModel::itemChanged, this, &DataTableWidget::itemChanged);
  172. }
  173. }
  174. setCurrentPage(1);
  175. }
  176. void DataTableWidget::setupTabWidget()
  177. {
  178. m_dataTab->clear();
  179. QList<DataTableItemModel *> list = m_models[m_currentPage];
  180. for (int j = 0; j < list.size(); j++) {
  181. DataTableItemModel *model = list[j];
  182. QTableView *t = new QTableView(m_dataTab);
  183. t->setAlternatingRowColors(m_mind2->nodeList().count() > 0);
  184. t->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  185. t->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  186. t->verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  187. t->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
  188. t->setSelectionMode(QAbstractItemView::SingleSelection);
  189. t->setModel(model);
  190. m_dataTab->addTab(t, model->property(kDataTabName).toString());
  191. if (m_process.type == SchemePlanManager::ImportEvalData
  192. && m_process.indexType == ProjectManager::OptimalIndex) {
  193. t->setItemDelegateForColumn(1, m_comboDelegate);
  194. }
  195. }
  196. }
  197. int DataTableWidget::currentPage() const
  198. {
  199. return m_currentPage;
  200. }
  201. void DataTableWidget::setCurrentPage(int p)
  202. {
  203. if (p < 1 || p > m_models.size()) {
  204. return;
  205. }
  206. m_currentPage = p;
  207. m_previous->setEnabled(p > 1);
  208. m_next->setEnabled(p < m_models.size());
  209. setupTabWidget();
  210. m_pageLab->setText(QString("共 %1 页, 当前第 %2 页").arg(m_models.size()).arg(p));
  211. }
  212. void DataTableWidget::updateCurrentTable()
  213. {
  214. return;
  215. int c = m_dataTab->currentIndex();
  216. QTableView *table = (QTableView *)m_dataTab->widget(c);
  217. if (table == nullptr || table->model() == nullptr || m_isSettingTable) {
  218. return;
  219. }
  220. QStandardItemModel *model = (QStandardItemModel *)table->model();
  221. /// 设置顶部水平方向标题
  222. int hIndex = -1;
  223. int dimensionIndex = -1; // 量纲所在列
  224. int typeIndex = -1; // 指标类型所在列
  225. // 指标
  226. CNodeData n = m_mind1->nodesInLevel(m_currentPage)[c];
  227. QList<CNodeData> hList = m_mind1->subNodes(n);
  228. // 以下情况需要显示指标
  229. // 导入权重分析数据
  230. // 导入需求分析评估的评估数据
  231. if (m_process.type == SchemePlanManager::ImportWeightData || m_process.indexType == ProjectManager::TechIndex) {
  232. for (CNodeData node : hList) {
  233. QStandardItem *item = new QStandardItem(node.name);
  234. item->setToolTip(node.remark);
  235. model->setHorizontalHeaderItem(++hIndex, item);
  236. }
  237. }
  238. // 导入方案优选评估或效能评估的评估数据时, 需要显示量纲
  239. if (m_process.type == SchemePlanManager::ImportEvalData
  240. && (m_process.indexType == ProjectManager::OptimalIndex
  241. || m_process.indexType == ProjectManager::EfficiencyIndex)) {
  242. QStandardItem *item = new QStandardItem("指标量纲");
  243. model->setHorizontalHeaderItem(++hIndex, item);
  244. dimensionIndex = hIndex;
  245. }
  246. // 导入方案优选评估的评估数据时, 需要显示指标类型
  247. if (m_process.type == SchemePlanManager::ImportEvalData && m_process.indexType == ProjectManager::OptimalIndex) {
  248. QStandardItem *item = new QStandardItem("指标类型");
  249. model->setHorizontalHeaderItem(++hIndex, item);
  250. typeIndex = hIndex;
  251. }
  252. /// 设置左侧垂直方向标题
  253. QList<CNodeData> vList;
  254. // 导入权重分析的专家数据时, 显示指标
  255. if (m_process.type == SchemePlanManager::ImportWeightData && m_process.dSource == SchemePlanManager::FromExpert) {
  256. vList = hList;
  257. }
  258. // 导入评估数据时, 显示最后一级指标
  259. if (m_process.type == SchemePlanManager::ImportEvalData) {
  260. if (m_process.indexType == ProjectManager::TechIndex) {
  261. vList = m_mind2->leaves();
  262. } else {
  263. vList = m_mind1->leaves();
  264. }
  265. }
  266. for (int i = 0; i < vList.count(); i++) {
  267. CNodeData node = vList[i];
  268. QStandardItem *item = new QStandardItem(QString(" %1 ").arg(node.name));
  269. item->setToolTip(node.remark);
  270. model->setVerticalHeaderItem(i, item);
  271. table->setRowHeight(i, 35);
  272. }
  273. /// 填充量纲和指标类型
  274. for (int i = 0; i < vList.count(); i++) {
  275. CNodeData vNode = vList[i];
  276. QStandardItem *d = new QStandardItem();
  277. d->setData(Qt::AlignCenter, Qt::TextAlignmentRole); // 单元格文字居中
  278. if (dimensionIndex >= 0) {
  279. d->setText(vNode.dimension);
  280. model->setItem(i, dimensionIndex, d);
  281. }
  282. if (typeIndex >= 0) {
  283. model->setItem(i, typeIndex, d);
  284. table->setItemDelegateForColumn(typeIndex, m_comboDelegate);
  285. }
  286. table->setRowHeight(i, 35);
  287. }
  288. /// 填充单元格
  289. if (m_process.type == SchemePlanManager::ImportWeightData) {
  290. if (m_process.dSource == SchemePlanManager::FromExpert) {
  291. for (int i = 0; i < vList.count(); i++) {
  292. CNodeData vNode = vList[i];
  293. for (int j = 0; j < hList.count(); j++) {
  294. CNodeData hNode = hList[j];
  295. QStandardItem *item = new QStandardItem();
  296. item->setData(Qt::AlignCenter, Qt::TextAlignmentRole); // 单元格文字居中
  297. item->setBackground(QBrush(QColor("white")));
  298. for (NodeMatrixInfo *info : m_data) {
  299. if (info->abscissa.toInt() == hNode.id && info->ordinate.toInt() == vNode.id) {
  300. item->setText(info->nodeValue);
  301. model->setItem(i, j, item);
  302. break;
  303. }
  304. }
  305. }
  306. table->setRowHeight(i, 35);
  307. }
  308. } else if (m_process.dSource == SchemePlanManager::FromMeasurement) {
  309. int row = model->rowCount();
  310. for (int j = 0; j < hList.count(); j++) {
  311. CNodeData hNode = hList[j];
  312. QStandardItem *item = new QStandardItem();
  313. item->setData(Qt::AlignCenter, Qt::TextAlignmentRole); // 单元格文字居中
  314. item->setBackground(QBrush(QColor("white")));
  315. for (NodeMatrixInfo *info : m_data) {
  316. if (info->abscissa.toInt() == hNode.id) {
  317. item->setText(info->nodeValue);
  318. model->setItem(row, j, item);
  319. break;
  320. }
  321. }
  322. }
  323. }
  324. } else if (m_process.type == SchemePlanManager::ImportEvalData) {
  325. if (m_process.indexType == ProjectManager::TechIndex) {
  326. for (int i = 0; i < vList.count(); i++) {
  327. CNodeData vNode = vList[i];
  328. for (int j = 0; j < hList.count(); j++) {
  329. CNodeData hNode = hList[j];
  330. QStandardItem *item = new QStandardItem();
  331. item->setData(Qt::AlignCenter, Qt::TextAlignmentRole); // 单元格文字居中
  332. item->setBackground(QBrush(QColor("white")));
  333. for (NodeMatrixInfo *info : m_data) {
  334. if (info->abscissa.toInt() == hNode.id && info->ordinate.toInt() == vNode.id) {
  335. item->setText(info->nodeValue);
  336. model->setItem(i, j, item);
  337. break;
  338. }
  339. }
  340. }
  341. table->setRowHeight(i, 35);
  342. }
  343. }
  344. }
  345. }
  346. void DataTableWidget::setSchemeList(const QList<SchemaEval *> &list) { }
  347. void DataTableWidget::addScheme(SchemaEval *scheme)
  348. {
  349. if (m_process.type == SchemePlanManager::ImportEvalData && m_process.indexType == ProjectManager::EfficiencyIndex) {
  350. }
  351. if (m_models.count() <= 0 || m_models[1].count() <= 0) {
  352. return;
  353. }
  354. DataTableItemModel *model = m_models[1].first();
  355. QStandardItem *item = new QStandardItem(scheme->name);
  356. model->setHorizontalHeaderItem(model->columnCount(), item);
  357. }
  358. QTabWidget *DataTableWidget::tabWidget() const
  359. {
  360. return m_dataTab;
  361. }
  362. CMind *DataTableWidget::mind1() const
  363. {
  364. return m_mind1;
  365. }
  366. CMind *DataTableWidget::mind2() const
  367. {
  368. return m_mind2;
  369. }
  370. void DataTableWidget::setNodeMatrixData(QList<NodeMatrixInfo *> data, bool isExpertData)
  371. {
  372. m_isFillingData = true;
  373. /// 清空表中数据
  374. for (QList<DataTableItemModel *> modelList : m_models.values()) {
  375. for (DataTableItemModel *model : modelList) {
  376. for (int r = 0; r < model->rowCount(); r++) {
  377. for (int c = 0; c < model->columnCount(); c++) {
  378. QStandardItem *item = model->item(r, c);
  379. if (item != nullptr) {
  380. item->setData("");
  381. item->setText("");
  382. }
  383. }
  384. }
  385. }
  386. }
  387. if (data.size() <= 0) {
  388. m_isFillingData = false;
  389. return;
  390. }
  391. m_data = data;
  392. m_uuidStr = data.first()->strUuid;
  393. // 加载权重分析数据
  394. if (m_process.type == SchemePlanManager::ImportWeightData) {
  395. if (m_process.dSource == SchemePlanManager::FromExpert) { // 专家数据
  396. for (NodeMatrixInfo *info : data) {
  397. for (QList<DataTableItemModel *> modelList : m_models.values()) {
  398. for (DataTableItemModel *model : modelList) {
  399. for (int r = 0; r < model->rowCount(); r++) {
  400. QStandardItem *rHeader = model->verticalHeaderItem(r);
  401. for (int c = 0; c < model->columnCount(); c++) {
  402. QStandardItem *cHeader = model->horizontalHeaderItem(c);
  403. if (cHeader->text() == info->abscissa && rHeader->text() == info->ordinate) {
  404. QStandardItem *item = new QStandardItem();
  405. item->setText(info->nodeValue);
  406. item->setEditable(false);
  407. model->setItem(r, c, item);
  408. }
  409. }
  410. }
  411. }
  412. }
  413. }
  414. } else { // 实测数据
  415. for (NodeMatrixInfo *info : data) {
  416. for (QList<DataTableItemModel *> modelList : m_models.values()) {
  417. for (DataTableItemModel *model : modelList) {
  418. for (int c = 0; c < model->columnCount(); c++) {
  419. QStandardItem *cHeader = model->horizontalHeaderItem(c);
  420. if (cHeader->text() == info->abscissa) {
  421. QStandardItem *item = new QStandardItem();
  422. item->setText(info->nodeValue);
  423. item->setData(info->nodeValue);
  424. model->setItem(0, c, item);
  425. }
  426. }
  427. }
  428. }
  429. }
  430. }
  431. }
  432. // 加载技术重要度的评估数据
  433. // 由于表的结构相似, 所以不用不区分专家数据和实测数据
  434. if (m_process.type == SchemePlanManager::ImportEvalData && m_process.indexType == ProjectManager::TechIndex) {
  435. for (NodeMatrixInfo *info : data) {
  436. for (QList<DataTableItemModel *> modelList : m_models.values()) {
  437. for (DataTableItemModel *model : modelList) {
  438. for (int r = 0; r < model->rowCount(); r++) {
  439. QStandardItem *rHeader = model->verticalHeaderItem(r);
  440. for (int c = 0; c < model->columnCount(); c++) {
  441. QStandardItem *cHeader = model->horizontalHeaderItem(c);
  442. if (cHeader->text() == info->abscissa && rHeader->text() == info->ordinate) {
  443. QStandardItem *item = new QStandardItem();
  444. item->setText(info->nodeValue);
  445. item->setData(info->nodeValue);
  446. model->setItem(r, c, item);
  447. }
  448. }
  449. }
  450. }
  451. }
  452. }
  453. }
  454. m_isFillingData = false;
  455. }
  456. void DataTableWidget::updateModel(DataTableItemModel *model, QList<CNodeData> &hHeaders, QList<CNodeData> &vHeaders,
  457. int hStart, int vStart)
  458. {
  459. for (int i = 0; i < hHeaders.size(); i++) {
  460. CNodeData node = hHeaders[i];
  461. QStandardItem *item = new QStandardItem(node.name);
  462. item->setToolTip(node.remark);
  463. model->setHorizontalHeaderItem(i + hStart, item);
  464. }
  465. for (int i = 0; i < vHeaders.size(); i++) {
  466. CNodeData node = vHeaders[i];
  467. QStandardItem *item = new QStandardItem(node.name);
  468. item->setToolTip(node.remark);
  469. model->setVerticalHeaderItem(i + vStart, item);
  470. }
  471. if (m_process.dSource == SchemePlanManager::FromExpert) {
  472. for (int i = 0; i < hHeaders.size(); i++) {
  473. for (int j = 0; j < vHeaders.size(); j++) {
  474. QStandardItem *item = new QStandardItem();
  475. item->setEditable(false);
  476. model->setItem(j, i, item);
  477. }
  478. }
  479. }
  480. }
  481. void DataTableWidget::slotPrevious()
  482. {
  483. setCurrentPage(m_currentPage - 1);
  484. }
  485. void DataTableWidget::slotNext()
  486. {
  487. setCurrentPage(m_currentPage + 1);
  488. }
  489. void DataTableWidget::slotTabCurrentChanged(int c)
  490. {
  491. Q_UNUSED(c)
  492. updateCurrentTable();
  493. }
  494. /// 用户编辑了表格数据后, 将数据存到数据库, 并更新本地数据源
  495. void DataTableWidget::itemChanged(QStandardItem *item)
  496. {
  497. // 排除程序的填充数据操作, 只关心用户操作
  498. if (m_isFillingData == true) {
  499. return;
  500. }
  501. // 校验输入字符的合法性, 只允许输入非负数
  502. // 遇到非法字符时, 恢复原值
  503. static bool useOldData = false;
  504. if (useOldData) {
  505. useOldData = false;
  506. return;
  507. }
  508. // ([0-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])
  509. // (-?[1-9][0-9]+)|(-?[0-9])|(-?[1-9]\\d+\\.\\d+)|(-?[0-9]\\.\\d+)
  510. QString Pattern("(\\d*\\.?\\d*)"); // 匹配非负数
  511. QRegExp reg(Pattern);
  512. if (!reg.exactMatch(item->text())) {
  513. useOldData = true;
  514. item->setText(item->data().toString());
  515. return;
  516. } else {
  517. if (item->data().toString() != item->text()) {
  518. item->setData(item->text());
  519. return;
  520. }
  521. }
  522. // 用户编辑实测数据, 包括权重数据和能力重要度评估数据
  523. bool weightData = m_process.type == SchemePlanManager::ImportWeightData
  524. && m_process.dSource == SchemePlanManager::FromMeasurement;
  525. bool evalData = m_process.type == SchemePlanManager::ImportEvalData
  526. && m_process.dSource == SchemePlanManager::FromMeasurement
  527. && m_process.indexType == ProjectManager::TechIndex;
  528. // 用户编辑方案数据, 包括方案优选评估数据和效能评估数据
  529. bool schemeData = m_process.type == SchemePlanManager::ImportEvalData
  530. && (m_process.indexType == ProjectManager::OptimalIndex
  531. || m_process.indexType == ProjectManager::EfficiencyIndex);
  532. if (weightData || evalData) {
  533. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_process.indexType);
  534. NodeMatrixInfo info;
  535. info.nodeValue = item->text();
  536. info.engineerId = m_process.projectId;
  537. info.tableMsg = indexName;
  538. info.strUuid = m_uuidStr;
  539. QStandardItem *hHeader = item->model()->horizontalHeaderItem(item->column());
  540. info.abscissa = hHeader->text();
  541. if (evalData) {
  542. QStandardItem *vHeader = item->model()->verticalHeaderItem(item->row());
  543. info.ordinate = vHeader->text();
  544. }
  545. qDebug() << __FUNCTION__ << __LINE__ << info.tableMsg << info.strUuid << info.abscissa << info.ordinate
  546. << info.nodeValue << endl;
  547. bool ret = NodeMatrixService().UpdateMeasureData(info);
  548. if (ret) {
  549. emit sigMeasureDataEdited(&info);
  550. }
  551. }
  552. if (schemeData) {
  553. int schemeIndex = item->column() - m_schemeStartIndex;
  554. if (schemeIndex < 0 || schemeIndex >= m_schemeList.size()) {
  555. return;
  556. }
  557. SchemaEval *scheme = m_schemeList[schemeIndex];
  558. QStringList valueList;
  559. for (int i = 0; i < item->model()->rowCount(); i++) {
  560. QStandardItem *vHeader = item->model()->verticalHeaderItem(i);
  561. QString indexName = vHeader->text();
  562. QString valueStr = "";
  563. QStandardItem *t = item->model()->item(i, item->column());
  564. if (t != nullptr && t->text().trimmed().length() > 0) {
  565. valueStr = t->text();
  566. }
  567. valueList.append(QString("%1:%2").arg(indexName).arg(valueStr));
  568. }
  569. scheme->valueStr = valueList.join(";");
  570. bool ret = SchemeInfoService().UpdateValueStrById(scheme->id, scheme->valueStr);
  571. qDebug() << __FUNCTION__ << __LINE__ << ret << endl;
  572. }
  573. }