MatrixPanelWidget.cpp 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. #include "MatrixPanelWidget.h"
  2. #include "MatrixTableTechMeasuresWidget.h"
  3. #include "MatrixTableWidget.h"
  4. #include "dbService/DBServiceSet.h"
  5. #include "dbService/NodeMatrixService.h"
  6. #include "ui_MatrixPanelWidget.h"
  7. #include <xlsxdocument.h>
  8. #include <QDebug>
  9. #include <QMessageBox>
  10. #include <QFileDialog>
  11. MatrixPanelWidget::MatrixPanelWidget(QWidget *parent) : QWidget(parent), ui(new Ui::MatrixPanelWidget)
  12. {
  13. ui->setupUi(this);
  14. firstLayout = new QGridLayout;
  15. firstPlainWidget = nullptr;
  16. ui->stackedWidget->widget(0)->setLayout(firstLayout);
  17. secondLayout = new QGridLayout;
  18. secondPlainWidget = nullptr;
  19. ui->stackedWidget->widget(1)->setLayout(secondLayout);
  20. ui->stackedWidget->setCurrentIndex(0);
  21. ui->saveBtn->setDisabled(false);
  22. ui->exportBtn->setDisabled(true);
  23. ui->importBtn->setVisible(true);
  24. }
  25. MatrixPanelWidget::MatrixPanelWidget(QWidget *parent, ProfessorInfo professor)
  26. : QWidget(parent), ui(new Ui::MatrixPanelWidget)
  27. {
  28. ui->setupUi(this);
  29. firstLayout = new QGridLayout;
  30. firstPlainWidget = nullptr;
  31. ui->stackedWidget->widget(0)->setLayout(firstLayout);
  32. secondLayout = new QGridLayout;
  33. secondPlainWidget = nullptr;
  34. ui->stackedWidget->widget(1)->setLayout(secondLayout);
  35. ui->stackedWidget->setCurrentIndex(0);
  36. m_professor = professor;
  37. if (m_professor.tableMsg != "技术措施重要度评估对象") {
  38. ui->saveBtn->setDisabled(false);
  39. ui->exportBtn->setDisabled(true);
  40. }
  41. ui->importBtn->setVisible(false);
  42. ui->exportBtn->setVisible(false);
  43. }
  44. MatrixPanelWidget::~MatrixPanelWidget()
  45. {
  46. if (currentMindNodes) {
  47. delete currentMindNodes;
  48. }
  49. if (classifiedNodes) {
  50. delete classifiedNodes;
  51. }
  52. if (indexsRefClassifiedNodes) {
  53. delete indexsRefClassifiedNodes;
  54. }
  55. delete ui;
  56. }
  57. void MatrixPanelWidget::init(const QStringList indexsRef, const QStringList indexs)
  58. {
  59. qDebug() << "MatrixPanelWidget---init";
  60. indexsRefClassifiedNodes = nullptr;
  61. if (!indexsRef.isEmpty()) {
  62. MindNodeManager *indexsRefNodes = new MindNodeManager(); // 是否参考指标体系
  63. getMindNodes(indexsRefNodes, indexsRef);
  64. indexsRefClassifiedNodes = new QList<QList<MindNodeManager::NodeMessage>>;
  65. sortMindNodes(*indexsRefNodes, indexsRefClassifiedNodes);
  66. delete indexsRefNodes;
  67. }
  68. if (!indexs.isEmpty()) {
  69. currentMindNodes = new MindNodeManager();
  70. classifiedNodes = new QList<QList<MindNodeManager::NodeMessage>>;
  71. getMindNodes(currentMindNodes, indexs);
  72. sortMindNodes(*currentMindNodes, classifiedNodes);
  73. } else {
  74. currentMindNodes = nullptr;
  75. classifiedNodes = nullptr;
  76. }
  77. ui->toatalPagesLabel->setText(QString("共%1页").arg(getPages()));
  78. ui->currPageLabel->setText(QString("当前第0页"));
  79. QList<NodeMatrixInfo *> nodeValueInfoList;
  80. // DBServiceSet().QueryNodeMatrixListByExpertIdAndEngineerId2(&nodeValueInfoList, m_professor.id,
  81. // m_professor.engineer.engineerId,
  82. // m_professor.tableMsg);
  83. if (!indexsRef.isEmpty()) {
  84. currentTab = "技术措施重要度评估对象";
  85. initPlainTechMeasuresWidget(nodeValueInfoList);
  86. setPage(1);
  87. return;
  88. }
  89. if (!indexs.isEmpty()) {
  90. currentTab = "";
  91. initPlainWidget(nodeValueInfoList);
  92. setPage(1);
  93. return;
  94. }
  95. }
  96. void MatrixPanelWidget::initImportData(const QStringList indexsRef, const QStringList indexs,
  97. QList<NodeMatrixInfo *> nodeValueInfoList)
  98. {
  99. // qDebug() << "MatrixPanelWidget---initImportData" << endl;
  100. indexsRefClassifiedNodes = nullptr;
  101. if (!indexsRef.isEmpty()) {
  102. MindNodeManager *indexsRefNodes = new MindNodeManager(); // 是否参考指标体系
  103. getMindNodes(indexsRefNodes, indexsRef);
  104. indexsRefClassifiedNodes = new QList<QList<MindNodeManager::NodeMessage>>;
  105. sortMindNodes(*indexsRefNodes, indexsRefClassifiedNodes);
  106. delete indexsRefNodes;
  107. }
  108. if (!indexs.isEmpty()) {
  109. currentMindNodes = new MindNodeManager();
  110. classifiedNodes = new QList<QList<MindNodeManager::NodeMessage>>;
  111. getMindNodes(currentMindNodes, indexs);
  112. sortMindNodes(*currentMindNodes, classifiedNodes);
  113. } else {
  114. currentMindNodes = nullptr;
  115. classifiedNodes = nullptr;
  116. }
  117. ui->toatalPagesLabel->setText(QString("共%1页").arg(getPages()));
  118. ui->currPageLabel->setText(QString("当前第0页"));
  119. if (!indexsRef.isEmpty()) {
  120. currentTab = "技术措施重要度评估对象";
  121. qDebug() << "MatrixPanelWidget---init" << currentTab;
  122. initPlainTechMeasuresWidget(nodeValueInfoList);
  123. setPage(1);
  124. return;
  125. }
  126. if (!indexs.isEmpty()) {
  127. currentTab = "";
  128. initPlainWidget(nodeValueInfoList);
  129. setPage(1);
  130. return;
  131. }
  132. }
  133. void MatrixPanelWidget::sortMindNodes(const MindNodeManager &manager,
  134. QList<QList<MindNodeManager::NodeMessage>> *classify)
  135. {
  136. for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) {
  137. QStringList nodePonit = msg.node.split(".");
  138. while (nodePonit.count() - 1 > classify->count()) {
  139. (*classify) << QList<MindNodeManager::NodeMessage>();
  140. }
  141. (*classify)[nodePonit.count() - 2] << msg;
  142. }
  143. }
  144. void MatrixPanelWidget::getMindNodes(MindNodeManager *manager, QStringList listNodes)
  145. {
  146. int sn[16];
  147. memset(sn, 0, sizeof(int) * 16);
  148. int spaceNum = -1;
  149. int level = 0;
  150. MindNodeManager::NodeMessage temp;
  151. manager->setMindName(listNodes[0].trimmed());
  152. for (int i = 1; i < listNodes.count(); i++) {
  153. int tempSpace = 0;
  154. for (QString s : listNodes[i]) {
  155. if (s == " ") {
  156. tempSpace++;
  157. } else {
  158. break;
  159. }
  160. }
  161. tempSpace /= 4;
  162. if (tempSpace == 1) { // 一级
  163. spaceNum = tempSpace;
  164. level = 0;
  165. sn[level]++;
  166. memset((void *)&sn[1], 0, sizeof(int) * 15);
  167. } else {
  168. if (spaceNum < tempSpace) { // 空格增加
  169. spaceNum = tempSpace;
  170. level++;
  171. sn[level]++;
  172. } else if (spaceNum == tempSpace) { // 同一级
  173. sn[level]++;
  174. } else {
  175. memset((void *)&sn[tempSpace], 0, sizeof(int) * (16 - tempSpace));
  176. level -= spaceNum - tempSpace;
  177. spaceNum = tempSpace;
  178. sn[level]++;
  179. }
  180. }
  181. QString node = "1";
  182. for (int l : sn) {
  183. if (l > 0) {
  184. node += QString(".%1").arg(l);
  185. } else {
  186. break;
  187. }
  188. }
  189. if (listNodes[i].trimmed().isEmpty()) {
  190. temp.name = QString("NULL(节点%1)").arg(node);
  191. temp.node = node;
  192. temp.remark = "";
  193. manager->pushNewMind(temp);
  194. } else {
  195. temp.name = listNodes[i].trimmed().split("\t")[0];
  196. temp.node = node;
  197. temp.remark = listNodes[i].trimmed().split("\t")[1];
  198. manager->pushNewMind(temp);
  199. }
  200. }
  201. }
  202. QStringList MatrixPanelWidget::getFirstIndexNodes(const MindNodeManager &manager)
  203. {
  204. QList<QList<MindNodeManager::NodeMessage>> classify;
  205. for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) {
  206. QStringList nodePonit = msg.node.split(".");
  207. while (nodePonit.count() - 1 > classify.count()) {
  208. classify << QList<MindNodeManager::NodeMessage>();
  209. }
  210. classify[nodePonit.count() - 2] << msg;
  211. }
  212. QStringList firstNodes;
  213. for (MindNodeManager::NodeMessage msg : classify.first()) {
  214. firstNodes << msg.name;
  215. }
  216. return firstNodes;
  217. }
  218. QStringList MatrixPanelWidget::getLastIndexNodes(const MindNodeManager &manager)
  219. {
  220. QList<QList<MindNodeManager::NodeMessage>> classify;
  221. for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) {
  222. QStringList nodePonit = msg.node.split(".");
  223. while (nodePonit.count() - 1 > classify.count()) {
  224. classify << QList<MindNodeManager::NodeMessage>();
  225. }
  226. classify[nodePonit.count() - 2] << msg;
  227. }
  228. QStringList lastNodes;
  229. for (MindNodeManager::NodeMessage msg : classify.last()) {
  230. lastNodes << msg.name;
  231. }
  232. return lastNodes;
  233. }
  234. int MatrixPanelWidget::getPages()
  235. {
  236. #if 0
  237. int max = 0;
  238. for (MindNodeManager::NodeMessage msg : currentMindNodes->getMindNodes()) {
  239. QStringList nodePonit = msg.node.split(".");
  240. if (max < nodePonit.count() - 1) { max = nodePonit.count() - 1; }
  241. }
  242. return max;
  243. #else
  244. if (!classifiedNodes) {
  245. return 0;
  246. }
  247. int pages = classifiedNodes->count();
  248. if (pages == 1) {
  249. ui->nextPageBtn->setVisible(false);
  250. ui->prePageBtn->setVisible(false);
  251. }
  252. return classifiedNodes->count();
  253. #endif
  254. }
  255. void MatrixPanelWidget::setPage(int page)
  256. {
  257. if (page < 1 || page > getPages()) {
  258. return;
  259. }
  260. currentPage = page;
  261. ui->currPageLabel->setText(QString("当前第%1页").arg(currentPage));
  262. if (currentPage == 1) {
  263. ui->prePageBtn->setDisabled(true);
  264. ui->nextPageBtn->setDisabled(false);
  265. } else if (currentPage == getPages()) {
  266. ui->prePageBtn->setDisabled(false);
  267. ui->nextPageBtn->setDisabled(true);
  268. } else {
  269. ui->prePageBtn->setDisabled(false);
  270. ui->nextPageBtn->setDisabled(false);
  271. }
  272. paintPlainWidget();
  273. }
  274. // 能力重要度评估指标体系初始化
  275. void MatrixPanelWidget::initPlainWidget(QList<NodeMatrixInfo *> nodeValueInfoList)
  276. {
  277. qDeleteAll(modelList);
  278. modelList.clear();
  279. if (getPages() == 0) {
  280. return;
  281. }
  282. if (nodeValueInfoList.size() > 0) {
  283. ui->saveBtn->setDisabled(false);
  284. ui->exportBtn->setDisabled(false);
  285. isAutoSave = true;
  286. }
  287. // 准备第一页,非tab的
  288. MatrixTableWidget *table = new MatrixTableWidget((indexsRefClassifiedNodes == nullptr), nullptr);
  289. table->setCurrentPage(1);
  290. table->setMsgName("总体");
  291. table->setTableIndexAndTableMsg(0, m_professor.engineer.engineerId, m_professor.id, m_table_msg);
  292. connect(table, &MatrixTableWidget::dataReady, this, &MatrixPanelWidget::oneTableDataReady);
  293. // connect(table, &MatrixTableWidget::autoSave, this, &MatrixPanelWidget::oneTableDataSave);
  294. connect(table, &MatrixTableWidget::returnModel, this, &MatrixPanelWidget::getTableModel);
  295. connect(table, &MatrixTableWidget::returnModelName, this, &MatrixPanelWidget::getTableModelName);
  296. if (indexsRefClassifiedNodes) {
  297. for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) {
  298. // qDebug() << msg.node << msg.name << msg.remark;
  299. table->addRowNode(msg.node, msg.name, msg.remark);
  300. }
  301. }
  302. for (MindNodeManager::NodeMessage msg : classifiedNodes->first()) {
  303. table->addColNode(msg.node, msg.name, msg.remark);
  304. if (indexsRefClassifiedNodes == nullptr) {
  305. table->addRowNode(msg.node, msg.name, msg.remark);
  306. }
  307. }
  308. NodeMatrixService().QueryNodesByExpertNameAndEngineerId2(
  309. &nodeValueInfoList, m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, "1", 0);
  310. table->paintMatrixTable(nodeValueInfoList);
  311. firstLayout->addWidget(table);
  312. qDeleteAll(nodeValueInfoList);
  313. nodeValueInfoList.clear();
  314. // 准备第二页,tab组合的
  315. for (int p = 1; p < getPages(); ++p) {
  316. QTabWidget *tab = new QTabWidget;
  317. tab->setTabPosition(QTabWidget::South);
  318. int index = 0;
  319. for (MindNodeManager::NodeMessage msg : classifiedNodes->at(p - 1)) {
  320. ++index;
  321. QString node = msg.node;
  322. // MatrixTableWidget *table = nullptr;
  323. table = nullptr;
  324. for (MindNodeManager::NodeMessage info : classifiedNodes->at(p)) {
  325. if ((info.node.count('.') == msg.node.count('.') + 1)
  326. && (info.node.left(msg.node.count()) == msg.node)) {
  327. if (!table) {
  328. table = new MatrixTableWidget((indexsRefClassifiedNodes == nullptr), nullptr);
  329. connect(table, &MatrixTableWidget::returnModel, this, &MatrixPanelWidget::getTableModel);
  330. connect(table, &MatrixTableWidget::returnModelName, this,
  331. &MatrixPanelWidget::getTableModelName);
  332. table->setCurrentPage(2);
  333. table->setTableIndexAndTableMsg(index, m_professor.engineer.engineerId, m_professor.id,
  334. m_table_msg);
  335. }
  336. if (table) {
  337. table->addColNode(info.node, info.name, info.remark);
  338. if (!indexsRefClassifiedNodes) {
  339. table->addRowNode(info.node, info.name, info.remark);
  340. }
  341. }
  342. }
  343. }
  344. if (indexsRefClassifiedNodes) {
  345. for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) {
  346. table->addRowNode(msg.node, msg.name, msg.remark);
  347. }
  348. }
  349. if (table) {
  350. table->setMsgName(msg.name);
  351. // qDebug() << "专家界面tab" << msg.name;
  352. NodeMatrixService().QueryNodesByExpertNameAndEngineerId2(
  353. &nodeValueInfoList, m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg,
  354. QString::number(p + 1), index - 1);
  355. table->paintMatrixTable(nodeValueInfoList);
  356. tab->addTab(table, msg.name);
  357. qDebug() << "tabmes===" << msg.name;
  358. connect(table, &MatrixTableWidget::dataReady, this, &MatrixPanelWidget::oneTableDataReady);
  359. qDeleteAll(nodeValueInfoList);
  360. nodeValueInfoList.clear();
  361. }
  362. }
  363. tabWidgets << tab;
  364. }
  365. // secondLayout->addWidget(tab);
  366. }
  367. void MatrixPanelWidget::initPlainTechMeasuresWidget(QList<NodeMatrixInfo *> nodeValueInfoList)
  368. {
  369. qDeleteAll(modelList);
  370. modelList.clear();
  371. // qDebug() << "initPlainTechMeasuresWidget" << endl;
  372. if (getPages() == 0) {
  373. return;
  374. }
  375. if (nodeValueInfoList.size() > 0) {
  376. ui->saveBtn->setDisabled(false);
  377. ui->exportBtn->setDisabled(false);
  378. }
  379. // 准备第一页,非tab的
  380. MatrixTableTechMeasuresWidget *table = new MatrixTableTechMeasuresWidget(nullptr);
  381. connect(table, &MatrixTableTechMeasuresWidget::dataReady, this, &MatrixPanelWidget::oneTechMeasureTableDataReady);
  382. connect(table, &MatrixTableTechMeasuresWidget::returnModel, this, &MatrixPanelWidget::getTableModel);
  383. connect(table, &MatrixTableTechMeasuresWidget::returnModelName, this, &MatrixPanelWidget::getTableModelName);
  384. if (indexsRefClassifiedNodes) {
  385. for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) {
  386. // qDebug() << "mes.node" << msg.name;
  387. table->addRowNode(msg.node, msg.name, msg.remark);
  388. }
  389. }
  390. for (MindNodeManager::NodeMessage msg : classifiedNodes->first()) {
  391. // qDebug() << "mes.node" << msg.name;
  392. table->addColNode(msg.node, msg.name, msg.remark);
  393. technicalCols.append(msg);
  394. if (indexsRefClassifiedNodes == nullptr) {
  395. table->addRowNode(msg.node, msg.name, msg.remark);
  396. }
  397. }
  398. NodeMatrixService().QueryNodesByExpertNameAndEngineerId2(
  399. &nodeValueInfoList, m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, "1", 0);
  400. table->setTableName("总体");
  401. table->paintMatrixTable(nodeValueInfoList);
  402. firstLayout->addWidget(table);
  403. qDeleteAll(nodeValueInfoList);
  404. nodeValueInfoList.clear();
  405. // 准备第二页,tab组合的
  406. for (int p = 1; p < getPages(); ++p) {
  407. QTabWidget *tab = new QTabWidget;
  408. tab->setTabPosition(QTabWidget::South);
  409. int index = 0;
  410. for (MindNodeManager::NodeMessage msg : classifiedNodes->at(p - 1)) {
  411. ++index;
  412. QString node = msg.node;
  413. // MatrixTableWidget *table = nullptr;
  414. table = nullptr;
  415. for (MindNodeManager::NodeMessage info : classifiedNodes->at(p)) {
  416. if ((info.node.count('.') == msg.node.count('.') + 1)
  417. && (info.node.left(msg.node.count()) == msg.node)) {
  418. if (!table) {
  419. table = new MatrixTableTechMeasuresWidget(nullptr);
  420. connect(table, &MatrixTableTechMeasuresWidget::returnModel, this,
  421. &MatrixPanelWidget::getTableModel);
  422. connect(table, &MatrixTableTechMeasuresWidget::returnModelName, this,
  423. &MatrixPanelWidget::getTableModelName);
  424. }
  425. if (table) {
  426. table->addColNode(info.node, info.name, info.remark);
  427. if (!indexsRefClassifiedNodes) {
  428. table->addRowNode(info.node, info.name, info.remark);
  429. }
  430. }
  431. }
  432. }
  433. if (indexsRefClassifiedNodes) {
  434. for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) {
  435. table->addRowNode(msg.node, msg.name, msg.remark);
  436. }
  437. }
  438. if (table) {
  439. NodeMatrixService().QueryNodesByExpertNameAndEngineerId2(
  440. &nodeValueInfoList, m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg,
  441. QString::number(p + 1), index - 1);
  442. table->setTableName(msg.name);
  443. table->paintMatrixTable(nodeValueInfoList);
  444. tab->addTab(table, msg.name);
  445. connect(table, &MatrixTableTechMeasuresWidget::dataReady, this,
  446. &MatrixPanelWidget::oneTechMeasureTableDataReady);
  447. qDeleteAll(nodeValueInfoList);
  448. nodeValueInfoList.clear();
  449. }
  450. }
  451. tabWidgets << tab;
  452. }
  453. // secondLayout->addWidget(tab);
  454. }
  455. bool MatrixPanelWidget::checkTableDateReady()
  456. {
  457. bool filled = true;
  458. if (m_table_msg == "技术措施重要度评估对象") {
  459. MatrixTableTechMeasuresWidget *first =
  460. qobject_cast<MatrixTableTechMeasuresWidget *>(firstLayout->itemAt(0)->widget());
  461. if (!first->isDataReady()) {
  462. filled = false;
  463. }
  464. for (QTabWidget *tab : tabWidgets) {
  465. for (int t = 0; t < tab->count(); ++t) {
  466. MatrixTableTechMeasuresWidget *table = qobject_cast<MatrixTableTechMeasuresWidget *>(tab->widget(t));
  467. if (!table->isDataReady()) {
  468. filled = false;
  469. }
  470. }
  471. }
  472. } else {
  473. MatrixTableWidget *first = qobject_cast<MatrixTableWidget *>(firstLayout->itemAt(0)->widget());
  474. if (!first->isDataReady()) {
  475. filled = false;
  476. }
  477. for (QTabWidget *tab : tabWidgets) {
  478. for (int t = 0; t < tab->count(); ++t) {
  479. MatrixTableWidget *table = qobject_cast<MatrixTableWidget *>(tab->widget(t));
  480. if (!table->isDataReady()) {
  481. filled = false;
  482. }
  483. }
  484. }
  485. }
  486. return filled;
  487. }
  488. void MatrixPanelWidget::paintPlainWidget()
  489. {
  490. bool firstShow = true;
  491. if (getPages() == 0) {
  492. return;
  493. }
  494. if (currentPage > 1) {
  495. firstShow = false;
  496. }
  497. if (firstShow) {
  498. ui->stackedWidget->setCurrentIndex(0);
  499. } else {
  500. QTabWidget *newTab = tabWidgets.at(currentPage - 2);
  501. if (secondLayout->count() == 0) {
  502. secondLayout->addWidget(newTab);
  503. newTab->show();
  504. } else {
  505. QTabWidget *currTab = qobject_cast<QTabWidget *>(secondLayout->itemAt(0)->widget());
  506. if (newTab == currTab) {
  507. qDebug() << "same tab";
  508. } else {
  509. secondLayout->removeWidget(currTab);
  510. currTab->hide();
  511. secondLayout->addWidget(newTab);
  512. newTab->show();
  513. }
  514. }
  515. ui->stackedWidget->setCurrentIndex(1);
  516. }
  517. }
  518. void MatrixPanelWidget::on_prePageBtn_clicked()
  519. {
  520. setPage(currentPage - 1);
  521. }
  522. void MatrixPanelWidget::on_nextPageBtn_clicked()
  523. {
  524. setPage(currentPage + 1);
  525. }
  526. void MatrixPanelWidget::setTableMsg(QString tableMsg)
  527. {
  528. m_table_msg = tableMsg;
  529. }
  530. // 采集完成保存
  531. void MatrixPanelWidget::on_saveBtn_clicked()
  532. {
  533. bool saveFlag = true;
  534. int tabIndex = 0;
  535. QList<NodeMatrixInfo *> nodeInfoList;
  536. if (currentTab == "技术措施重要度评估对象") {
  537. if (currentPage == 1) {
  538. MatrixTableTechMeasuresWidget *first =
  539. qobject_cast<MatrixTableTechMeasuresWidget *>(firstLayout->itemAt(0)->widget());
  540. // 保存第一页数据
  541. for (MatrixDataSource s : first->getSource()) {
  542. NodeMatrixInfo *t = new NodeMatrixInfo();
  543. t->abscissa = s.abscissa;
  544. t->ordinate = s.ordinate;
  545. t->node = s.node;
  546. t->nodeValue = s.nodeValue == "" ? "0" : s.nodeValue;
  547. t->expertId = QString::number(m_professor.id);
  548. t->expertName = m_professor.name;
  549. t->engineerId = m_professor.engineer.engineerId;
  550. t->writeDate = m_professor.createDataTime;
  551. t->mark = "1";
  552. t->tableMsg = m_professor.tableMsg;
  553. t->tabIndex = tabIndex;
  554. nodeInfoList.append(t);
  555. if (t->nodeValue.isEmpty()) {
  556. saveFlag = false;
  557. }
  558. }
  559. } else {
  560. QTabWidget *currTab = qobject_cast<QTabWidget *>(secondLayout->itemAt(0)->widget());
  561. tabIndex = currTab->currentIndex();
  562. // 保存第二页数据,如果有
  563. // for (QTabWidget *tabWidget : tabWidgets) {
  564. for (int ta = 0; ta < tabWidgets.count(); ta++) {
  565. if (ta + 2 == currentPage) {
  566. for (int i = 0; i < tabWidgets[ta]->count(); ++i) {
  567. MatrixTableTechMeasuresWidget *table =
  568. dynamic_cast<MatrixTableTechMeasuresWidget *>(tabWidgets[ta]->widget(tabIndex));
  569. for (MatrixDataSource s : table->getSource()) {
  570. NodeMatrixInfo *t = new NodeMatrixInfo();
  571. t->abscissa = s.abscissa;
  572. t->ordinate = s.ordinate;
  573. t->node = s.node;
  574. t->nodeValue = s.nodeValue == "" ? "0" : s.nodeValue;
  575. t->expertId = QString::number(m_professor.id);
  576. t->expertName = m_professor.name;
  577. t->engineerId = m_professor.engineer.engineerId;
  578. t->writeDate = m_professor.createDataTime;
  579. t->mark = QString::number(currentPage);
  580. t->tableMsg = m_professor.tableMsg;
  581. t->tabIndex = tabIndex;
  582. nodeInfoList.append(t);
  583. if (t->nodeValue.isEmpty()) {
  584. saveFlag = false;
  585. }
  586. }
  587. }
  588. }
  589. }
  590. }
  591. } else {
  592. // 能力重要度
  593. if (currentPage == 1) {
  594. MatrixTableWidget *first = qobject_cast<MatrixTableWidget *>(firstLayout->itemAt(0)->widget());
  595. // 保存第一页数据
  596. for (MatrixDataSource s : first->getSource()) {
  597. NodeMatrixInfo *t = new NodeMatrixInfo();
  598. t->abscissa = s.abscissa;
  599. t->ordinate = s.ordinate;
  600. t->node = s.node;
  601. t->nodeValue = s.nodeValue;
  602. t->expertId = QString::number(m_professor.id);
  603. t->expertName = m_professor.name;
  604. t->engineerId = m_professor.engineer.engineerId;
  605. t->writeDate = m_professor.createDataTime;
  606. t->mark = "1";
  607. t->tableMsg = m_professor.tableMsg;
  608. t->tabIndex = tabIndex;
  609. nodeInfoList.append(t);
  610. if (t->nodeValue.isEmpty()) {
  611. saveFlag = false;
  612. }
  613. }
  614. } else {
  615. qDebug() << "currentPage--------" << currentPage;
  616. QTabWidget *currTab = qobject_cast<QTabWidget *>(secondLayout->itemAt(0)->widget());
  617. tabIndex = currTab->currentIndex();
  618. // 保存第二页数据,如果有
  619. // for (QTabWidget *tabWidget : tabWidgets) {
  620. for (int ta = 0; ta < tabWidgets.count(); ta++) {
  621. if (ta + 2 == currentPage) {
  622. qDebug() << "----" << tabWidgets[ta]->count();
  623. MatrixTableWidget *table = dynamic_cast<MatrixTableWidget *>(tabWidgets[ta]->widget(tabIndex));
  624. for (MatrixDataSource s : table->getSource()) {
  625. NodeMatrixInfo *t = new NodeMatrixInfo();
  626. t->abscissa = s.abscissa;
  627. t->ordinate = s.ordinate;
  628. t->node = s.node;
  629. t->nodeValue = s.nodeValue;
  630. t->expertId = QString::number(m_professor.id);
  631. t->expertName = m_professor.name;
  632. t->engineerId = m_professor.engineer.engineerId;
  633. t->writeDate = m_professor.createDataTime;
  634. t->mark = QString::number(currentPage);
  635. t->tableMsg = m_professor.tableMsg;
  636. t->tabIndex = tabIndex;
  637. qDebug() << t->abscissa << "----" << t->ordinate << "-----" << t->node << "-----"
  638. << t->nodeValue;
  639. nodeInfoList.append(t);
  640. if (t->nodeValue.isEmpty()) {
  641. saveFlag = false;
  642. }
  643. }
  644. }
  645. }
  646. }
  647. }
  648. if (saveFlag) {
  649. if (NodeMatrixService().QueryNodeMatrixListByExpertNameAndEngineerId2(
  650. m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg,
  651. QString::number(currentPage), tabIndex)) {
  652. qDebug() << "存在数据";
  653. NodeMatrixService().UpdateNodeMatrixNodeValueList2(nodeInfoList);
  654. } else {
  655. qDebug() << "新插入数据";
  656. NodeMatrixService().AddNodeMatrixInfoList2(nodeInfoList);
  657. }
  658. } else {
  659. QMessageBox::warning(this, "警告", "请先填写数据,保证数据完整性!");
  660. return;
  661. }
  662. QMessageBox::information(this, tr("成功"), tr("数据保存成功"));
  663. qDeleteAll(nodeInfoList);
  664. }
  665. void MatrixPanelWidget::saveNodes()
  666. {
  667. if (currentTab == "技术措施重要度评估对象") {
  668. // qDebug() << "技术措施---保存" << endl;
  669. int tabIndex = 0;
  670. QList<NodeMatrixInfo *> nodeInfoList;
  671. MatrixTableTechMeasuresWidget *first =
  672. qobject_cast<MatrixTableTechMeasuresWidget *>(firstLayout->itemAt(0)->widget());
  673. // 保存第一页数据
  674. for (MatrixDataSource s : first->getSource()) {
  675. NodeMatrixInfo *t = new NodeMatrixInfo();
  676. t->abscissa = s.abscissa;
  677. t->ordinate = s.ordinate;
  678. t->node = s.node;
  679. t->nodeValue = s.nodeValue == "" ? "0" : s.nodeValue;
  680. t->expertId = QString::number(m_professor.id);
  681. t->expertName = m_professor.name;
  682. t->engineerId = m_professor.engineer.engineerId;
  683. t->writeDate = m_professor.createDataTime;
  684. t->mark = "1";
  685. t->tableMsg = m_professor.tableMsg;
  686. t->tabIndex = tabIndex;
  687. nodeInfoList.append(t);
  688. }
  689. if (NodeMatrixService().QueryNodeMatrixListByExpertNameAndEngineerId2(
  690. m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, "1", tabIndex)) {
  691. qDebug() << "存在数据";
  692. NodeMatrixService().UpdateNodeMatrixNodeValueList2(nodeInfoList);
  693. } else {
  694. qDebug() << "新插入数据";
  695. NodeMatrixService().AddNodeMatrixInfoList2(nodeInfoList);
  696. }
  697. // 保存第二页数据,如果有
  698. // for (QTabWidget *tabWidget : tabWidgets) {
  699. for (int ta = 0; ta < tabWidgets.count(); ta++) {
  700. for (int i = 0; i < tabWidgets[ta]->count(); i++) {
  701. QList<NodeMatrixInfo *> secondNodeInfoList;
  702. secondNodeInfoList.clear();
  703. MatrixTableTechMeasuresWidget *table =
  704. dynamic_cast<MatrixTableTechMeasuresWidget *>(tabWidgets[ta]->widget(i));
  705. for (MatrixDataSource s : table->getSource()) {
  706. NodeMatrixInfo *t = new NodeMatrixInfo();
  707. t->abscissa = s.abscissa;
  708. t->ordinate = s.ordinate;
  709. t->node = s.node;
  710. t->nodeValue = s.nodeValue == "" ? "0" : s.nodeValue;
  711. t->expertId = QString::number(m_professor.id);
  712. t->expertName = m_professor.name;
  713. t->engineerId = m_professor.engineer.engineerId;
  714. t->writeDate = m_professor.createDataTime;
  715. t->mark = QString::number(ta + 2);
  716. t->tableMsg = m_professor.tableMsg;
  717. t->tabIndex = i;
  718. secondNodeInfoList.append(t);
  719. }
  720. if (NodeMatrixService().QueryNodeMatrixListByExpertNameAndEngineerId2(
  721. m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg,
  722. QString::number(ta + 2), i)) {
  723. qDebug() << "存在数据";
  724. NodeMatrixService().UpdateNodeMatrixNodeValueList2(secondNodeInfoList);
  725. } else {
  726. qDebug() << "新插入数据";
  727. NodeMatrixService().AddNodeMatrixInfoList2(secondNodeInfoList);
  728. }
  729. }
  730. }
  731. } else {
  732. QList<NodeMatrixInfo *> nodeInfoList;
  733. MatrixTableWidget *first = qobject_cast<MatrixTableWidget *>(firstLayout->itemAt(0)->widget());
  734. // 保存第一页数据
  735. int tabIndex = 0;
  736. for (MatrixDataSource s : first->getSource()) {
  737. NodeMatrixInfo *t = new NodeMatrixInfo();
  738. t->abscissa = s.abscissa;
  739. t->ordinate = s.ordinate;
  740. t->node = s.node;
  741. t->nodeValue = s.nodeValue;
  742. t->expertId = QString::number(m_professor.id);
  743. t->expertName = m_professor.name;
  744. t->engineerId = m_professor.engineer.engineerId;
  745. t->writeDate = m_professor.createDataTime;
  746. t->mark = "1";
  747. t->tableMsg = m_professor.tableMsg;
  748. t->tabIndex = tabIndex;
  749. nodeInfoList.append(t);
  750. }
  751. if (NodeMatrixService().QueryNodeMatrixListByExpertNameAndEngineerId2(
  752. m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, "1", tabIndex)) {
  753. qDebug() << "存在数据";
  754. NodeMatrixService().UpdateNodeMatrixNodeValueList2(nodeInfoList);
  755. } else {
  756. qDebug() << "新插入数据";
  757. NodeMatrixService().AddNodeMatrixInfoList2(nodeInfoList);
  758. }
  759. qDeleteAll(nodeInfoList);
  760. // 保存第二页数据,如果有
  761. // for (QTabWidget *tabWidget : tabWidgets) {
  762. for (int ta = 0; ta < tabWidgets.count(); ta++) {
  763. for (int i = 0; i < tabWidgets[ta]->count(); i++) {
  764. QList<NodeMatrixInfo *> secondNodeInfoList;
  765. secondNodeInfoList.clear();
  766. MatrixTableWidget *table = dynamic_cast<MatrixTableWidget *>(tabWidgets[ta]->widget(i));
  767. for (MatrixDataSource s : table->getSource()) {
  768. NodeMatrixInfo *t = new NodeMatrixInfo();
  769. t->abscissa = s.abscissa;
  770. t->ordinate = s.ordinate;
  771. t->node = s.node;
  772. t->nodeValue = s.nodeValue;
  773. t->expertId = QString::number(m_professor.id);
  774. t->expertName = m_professor.name;
  775. t->engineerId = m_professor.engineer.engineerId;
  776. t->writeDate = m_professor.createDataTime;
  777. t->mark = QString::number(ta + 2);
  778. t->tableMsg = m_professor.tableMsg;
  779. t->tabIndex = i;
  780. secondNodeInfoList.append(t);
  781. }
  782. if (NodeMatrixService().QueryNodeMatrixListByExpertNameAndEngineerId2(
  783. m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg,
  784. QString::number(ta + 2), i)) {
  785. qDebug() << "存在数据";
  786. NodeMatrixService().UpdateNodeMatrixNodeValueList2(secondNodeInfoList);
  787. } else {
  788. qDebug() << "新插入数据";
  789. NodeMatrixService().AddNodeMatrixInfoList2(secondNodeInfoList);
  790. }
  791. qDeleteAll(secondNodeInfoList);
  792. }
  793. }
  794. }
  795. }
  796. void MatrixPanelWidget::oneTableDataSave()
  797. {
  798. if (isAutoSave) {
  799. on_saveBtn_clicked();
  800. }
  801. }
  802. void MatrixPanelWidget::oneTableDataReady(bool status)
  803. {
  804. if (status) {
  805. bool filled = true;
  806. MatrixTableWidget *first = qobject_cast<MatrixTableWidget *>(firstLayout->itemAt(0)->widget());
  807. if (!first->isDataReady()) {
  808. filled = false;
  809. }
  810. for (QTabWidget *tab : tabWidgets) {
  811. for (int t = 0; t < tab->count(); ++t) {
  812. MatrixTableWidget *table = qobject_cast<MatrixTableWidget *>(tab->widget(t));
  813. if (!table->isDataReady()) {
  814. filled = false;
  815. }
  816. }
  817. }
  818. if (filled) {
  819. ui->saveBtn->setDisabled(false);
  820. ui->exportBtn->setDisabled(false);
  821. } else {
  822. ui->saveBtn->setDisabled(false);
  823. ui->exportBtn->setDisabled(true);
  824. }
  825. } else {
  826. ui->saveBtn->setDisabled(false);
  827. ui->exportBtn->setDisabled(true);
  828. }
  829. }
  830. void MatrixPanelWidget::oneTechMeasureTableDataReady(bool status)
  831. {
  832. if (status) {
  833. bool filled = true;
  834. MatrixTableTechMeasuresWidget *first =
  835. qobject_cast<MatrixTableTechMeasuresWidget *>(firstLayout->itemAt(0)->widget());
  836. if (!first->isDataReady()) {
  837. filled = false;
  838. }
  839. for (QTabWidget *tab : tabWidgets) {
  840. for (int t = 0; t < tab->count(); ++t) {
  841. MatrixTableTechMeasuresWidget *table = qobject_cast<MatrixTableTechMeasuresWidget *>(tab->widget(t));
  842. if (!table->isDataReady()) {
  843. filled = false;
  844. }
  845. }
  846. }
  847. if (filled) {
  848. ui->saveBtn->setDisabled(false);
  849. ui->exportBtn->setDisabled(false);
  850. } else {
  851. ui->saveBtn->setDisabled(false);
  852. ui->exportBtn->setDisabled(true);
  853. }
  854. } else {
  855. ui->saveBtn->setDisabled(false);
  856. ui->exportBtn->setDisabled(true);
  857. }
  858. }
  859. void MatrixPanelWidget::getTableModel(QStandardItemModel *item)
  860. {
  861. modelList.append(item);
  862. }
  863. void MatrixPanelWidget::getTableModelName(QString itemName)
  864. {
  865. qDebug() << "-----tabeName----" << itemName;
  866. modelName.append(itemName);
  867. }
  868. // 导出table数据
  869. void MatrixPanelWidget::on_exportBtn_clicked()
  870. {
  871. if (!checkTableDateReady()) {
  872. QMessageBox::warning(this, "警告", "请确保xlsx数据的完整性!");
  873. return;
  874. }
  875. // 文件夹路径
  876. QFileDialog::Options options;
  877. options |= QFileDialog::DontUseNativeDialog;
  878. QString filePath = QFileDialog::getExistingDirectory(nullptr, "导出资源包", "/", options);
  879. if (filePath.isEmpty()) {
  880. return;
  881. }
  882. QString fileName = m_professor.name + "-" + m_table_msg + "-" + m_professor.engineer.engineerName;
  883. // QString filePath = "";
  884. // filePath = QCoreApplication::applicationDirPath();
  885. QDir dirReportPath(filePath);
  886. if (!dirReportPath.exists()) {
  887. if (dirReportPath.mkpath(filePath)) {
  888. filePath = filePath + "/" + fileName + tr(".xlsx");
  889. }
  890. } else {
  891. filePath = filePath + "/" + fileName + tr(".xlsx");
  892. }
  893. QFile file(fileName);
  894. if (file.exists()) {
  895. file.remove();
  896. }
  897. QXlsx::Format format;
  898. format.setFontSize(12); // 字体大小
  899. // format.setFontBold(true); //加粗
  900. // format.setFontColor(QColor(73, 88, 233)); //颜色
  901. // 可以用rgb,也可以用系统自带 QColor(Qt::red)
  902. format.setHorizontalAlignment(QXlsx::Format::AlignHCenter); // 水平居中
  903. format.setVerticalAlignment(QXlsx::Format::AlignVCenter); // 垂直居中
  904. QXlsx::Document exprot;
  905. // 判断是否需要多sheet页
  906. // QList<QString> strList;
  907. // qDebug() << "modelListSize-----------------" << modelList.size();
  908. // if (modelList.size() > 1) {
  909. // QStandardItemModel *model = modelList.at(0);
  910. // for (int c = 0; c < model->columnCount(); c++) {
  911. // QStandardItem *head = model->horizontalHeaderItem(c);
  912. // if (head != nullptr) {
  913. // strList.append(head->text() == "" ? "总体" : head->text());
  914. // qDebug() << "modelListSize-----------------" << head->text();
  915. // }
  916. // }
  917. // } else {
  918. // strList.append("总体");
  919. // }
  920. for (int i = 0; i < modelList.size(); i++) {
  921. QStandardItemModel *model = modelList.at(i);
  922. // qDebug() << strList.at(i);
  923. exprot.addSheet(modelName.at(i));
  924. int row = model->rowCount();
  925. int col = model->columnCount();
  926. // 先把表头获取到添加
  927. for (int c = 1; c < col + 1; c++) {
  928. QStandardItem *head = model->horizontalHeaderItem(c - 1);
  929. exprot.write(1, c, head->text(), format);
  930. exprot.setColumnWidth(c, head->text().size() == 0 ? 40 : head->text().size() * 4);
  931. }
  932. for (int r = 2; r < row + 2; r++) {
  933. for (int c = 1; c < col + 1; c++) {
  934. QStandardItem *item = model->item(r - 2, c - 1);
  935. exprot.write(r, c, item->text(), format);
  936. }
  937. }
  938. }
  939. // 添加专家基本信息
  940. exprot.addSheet("专家信息");
  941. exprot.write(1, 1, "ID", format);
  942. exprot.write(1, 2, "账号", format);
  943. exprot.write(1, 3, "单位", format);
  944. exprot.write(1, 4, "职务", format);
  945. exprot.write(1, 5, "专业", format);
  946. exprot.write(1, 6, "联系方式", format);
  947. exprot.write(1, 7, "填写时间", format);
  948. exprot.write(1, 8, "备注", format);
  949. exprot.write(2, 1, m_professor.id, format);
  950. exprot.write(2, 2, m_professor.name, format);
  951. exprot.write(2, 3, m_professor.department, format);
  952. exprot.write(2, 4, m_professor.job, format);
  953. exprot.write(2, 5, m_professor.major, format);
  954. exprot.write(2, 6, m_professor.phone, format);
  955. exprot.write(2, 7, m_professor.createDataTime, format);
  956. exprot.write(2, 8, m_professor.remark, format);
  957. exprot.saveAs(filePath);
  958. QMessageBox::information(this, tr("成功"), tr("数据导出成功"));
  959. saveNodes();
  960. }
  961. // 导入数据
  962. void MatrixPanelWidget::on_importBtn_clicked()
  963. {
  964. // 打开文件
  965. QDir dir;
  966. QFileDialog::Options options;
  967. options |= QFileDialog::DontUseNativeDialog;
  968. QString selectedFilter;
  969. QString fileName =
  970. QFileDialog::getOpenFileName(this, "选择Excel文件", "", "Excel (*.xls *.xlsx)", &selectedFilter, options);
  971. if (fileName.isEmpty())
  972. return;
  973. // 获取node节点
  974. QList<NodeMatrixInfo *> nodeValueInfoList;
  975. NodeMatrixService().QueryNodeMatrixListByExpertNameAndEngineerId(&nodeValueInfoList, m_professor.name,
  976. m_professor.engineer.engineerId);
  977. // 读取文件内容
  978. QXlsx::Document xlsxR(fileName);
  979. QStringList str = xlsxR.sheetNames();
  980. // 遍历sheet页
  981. for (int i = 0; i < str.size(); i++) {
  982. xlsxR.selectSheet(str.at(i));
  983. if (xlsxR.load()) {
  984. int row = xlsxR.dimension().lastRow();
  985. int col = xlsxR.dimension().lastColumn();
  986. for (int r = 2; r <= row; r++) {
  987. for (int c = 2; c <= col; c++) {
  988. QString abscissa;
  989. QString ordinate;
  990. QXlsx::Cell *cellAbscissa = xlsxR.cellAt(r, 1);
  991. if (cellAbscissa != NULL) {
  992. QVariant var = cellAbscissa->readValue();
  993. abscissa = var.toString();
  994. }
  995. QXlsx::Cell *cellOrdinate = xlsxR.cellAt(1, c);
  996. if (cellOrdinate != NULL) {
  997. QVariant var = cellOrdinate->readValue();
  998. ordinate = var.toString();
  999. }
  1000. for (int index = 0; index < nodeValueInfoList.size(); index++) {
  1001. NodeMatrixInfo *nodeInfo = nodeValueInfoList.at(index);
  1002. if (abscissa == nodeInfo->abscissa && ordinate == nodeInfo->ordinate) {
  1003. QXlsx::Cell *value = xlsxR.cellAt(r, c);
  1004. if (value != NULL) {
  1005. QVariant var = value->readValue();
  1006. nodeInfo->nodeValue = var.toString();
  1007. }
  1008. }
  1009. }
  1010. }
  1011. }
  1012. }
  1013. }
  1014. emit importData(nodeValueInfoList);
  1015. }