MatrixPanelWidget111.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. #include "MatrixPanelWidget.h"
  2. #include "ui_MatrixPanelWidget.h"
  3. #include "MatrixTableWidget.h"
  4. #include "MatrixTableTechMeasuresWidget.h"
  5. #include "dbService/DBServiceSet.h"
  6. #include <CollectKnowledgeWidget.h>
  7. MatrixPanelWidget::MatrixPanelWidget(QWidget *parent) : QWidget(parent), ui(new Ui::MatrixPanelWidget)
  8. {
  9. ui->setupUi(this);
  10. firstLayout = new QGridLayout;
  11. firstPlainWidget = nullptr;
  12. ui->stackedWidget->widget(0)->setLayout(firstLayout);
  13. secondLayout = new QGridLayout;
  14. secondPlainWidget = nullptr;
  15. ui->stackedWidget->widget(1)->setLayout(secondLayout);
  16. ui->stackedWidget->setCurrentIndex(0);
  17. ui->saveBtn->setDisabled(true);
  18. }
  19. MatrixPanelWidget::MatrixPanelWidget(QWidget *parent, ProfessorInfo professor)
  20. : QWidget(parent), ui(new Ui::MatrixPanelWidget)
  21. {
  22. ui->setupUi(this);
  23. firstLayout = new QGridLayout;
  24. firstPlainWidget = nullptr;
  25. ui->stackedWidget->widget(0)->setLayout(firstLayout);
  26. secondLayout = new QGridLayout;
  27. secondPlainWidget = nullptr;
  28. ui->stackedWidget->widget(1)->setLayout(secondLayout);
  29. ui->stackedWidget->setCurrentIndex(0);
  30. ui->saveBtn->setDisabled(true);
  31. m_professor = professor;
  32. }
  33. MatrixPanelWidget::~MatrixPanelWidget()
  34. {
  35. if (currentMindNodes) { delete currentMindNodes; }
  36. if (classifiedNodes) { delete classifiedNodes; }
  37. if (indexsRefClassifiedNodes) { delete indexsRefClassifiedNodes; }
  38. delete ui;
  39. }
  40. void MatrixPanelWidget::init(const QStringList indexsRef, const QStringList indexs)
  41. {
  42. indexsRefClassifiedNodes = nullptr;
  43. if (!indexsRef.isEmpty()) {
  44. MindNodeManager *indexsRefNodes = new MindNodeManager(); //是否参考指标体系
  45. getMindNodes(indexsRefNodes, indexsRef);
  46. indexsRefClassifiedNodes = new QList<QList<MindNodeManager::NodeMessage>>;
  47. sortMindNodes(*indexsRefNodes, indexsRefClassifiedNodes);
  48. delete indexsRefNodes;
  49. }
  50. if (!indexs.isEmpty()) {
  51. currentMindNodes = new MindNodeManager();
  52. classifiedNodes = new QList<QList<MindNodeManager::NodeMessage>>;
  53. getMindNodes(currentMindNodes, indexs);
  54. sortMindNodes(*currentMindNodes, classifiedNodes);
  55. } else {
  56. currentMindNodes = nullptr;
  57. classifiedNodes = nullptr;
  58. }
  59. ui->toatalPagesLabel->setText(QString("共%1页").arg(getPages()));
  60. ui->currPageLabel->setText(QString("当前第0页"));
  61. if (!indexsRef.isEmpty()) {
  62. currentTab = "技术措施";
  63. initPlainTechMeasuresWidget();
  64. setPage(1);
  65. return;
  66. }
  67. if (!indexs.isEmpty()) {
  68. currentTab = "";
  69. initPlainWidget();
  70. setPage(1);
  71. return;
  72. }
  73. }
  74. void MatrixPanelWidget::sortMindNodes(const MindNodeManager &manager,
  75. QList<QList<MindNodeManager::NodeMessage>> *classify)
  76. {
  77. for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) {
  78. QStringList nodePonit = msg.node.split(".");
  79. while (nodePonit.count() - 1 > classify->count()) {
  80. (*classify) << QList<MindNodeManager::NodeMessage>();
  81. }
  82. (*classify)[nodePonit.count() - 2] << msg;
  83. }
  84. }
  85. void MatrixPanelWidget::getMindNodes(MindNodeManager *manager, QStringList listNodes)
  86. {
  87. int sn[16];
  88. memset(sn, 0, sizeof(int) * 16);
  89. int spaceNum = -1;
  90. int level = 0;
  91. MindNodeManager::NodeMessage temp;
  92. manager->setMindName(listNodes[0].trimmed());
  93. for (int i = 1; i < listNodes.count(); i++) {
  94. int tempSpace = 0;
  95. for (QString s : listNodes[i]) {
  96. if (s == " ") {
  97. tempSpace++;
  98. } else {
  99. break;
  100. }
  101. }
  102. tempSpace /= 4;
  103. if (tempSpace == 1) { //一级
  104. spaceNum = tempSpace;
  105. level = 0;
  106. sn[level]++;
  107. memset((void *)&sn[1], 0, sizeof(int) * 15);
  108. } else {
  109. if (spaceNum < tempSpace) { //空格增加
  110. spaceNum = tempSpace;
  111. level++;
  112. sn[level]++;
  113. } else if (spaceNum == tempSpace) { //同一级
  114. sn[level]++;
  115. } else {
  116. spaceNum = tempSpace;
  117. sn[level] = 0;
  118. level--;
  119. sn[level]++;
  120. }
  121. }
  122. QString node = "1";
  123. for (int l : sn) {
  124. if (l > 0) {
  125. node += QString(".%1").arg(l);
  126. } else {
  127. break;
  128. }
  129. }
  130. if (listNodes[i].trimmed().isEmpty()) {
  131. temp.name = QString("NULL(节点%1)").arg(node);
  132. temp.node = node;
  133. temp.remark = "";
  134. manager->pushNewMind(temp);
  135. } else {
  136. temp.name = listNodes[i].trimmed().split("\t")[0];
  137. temp.node = node;
  138. temp.remark = listNodes[i].trimmed().split("\t")[1];
  139. manager->pushNewMind(temp);
  140. }
  141. }
  142. }
  143. QStringList MatrixPanelWidget::getFirstIndexNodes(const MindNodeManager &manager)
  144. {
  145. QList<QList<MindNodeManager::NodeMessage>> classify;
  146. for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) {
  147. QStringList nodePonit = msg.node.split(".");
  148. while (nodePonit.count() - 1 > classify.count()) {
  149. classify << QList<MindNodeManager::NodeMessage>();
  150. }
  151. classify[nodePonit.count() - 2] << msg;
  152. }
  153. QStringList firstNodes;
  154. for (MindNodeManager::NodeMessage msg : classify.first()) {
  155. firstNodes << msg.name;
  156. }
  157. return firstNodes;
  158. }
  159. QStringList MatrixPanelWidget::getLastIndexNodes(const MindNodeManager &manager)
  160. {
  161. QList<QList<MindNodeManager::NodeMessage>> classify;
  162. for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) {
  163. QStringList nodePonit = msg.node.split(".");
  164. while (nodePonit.count() - 1 > classify.count()) {
  165. classify << QList<MindNodeManager::NodeMessage>();
  166. }
  167. classify[nodePonit.count() - 2] << msg;
  168. }
  169. QStringList lastNodes;
  170. for (MindNodeManager::NodeMessage msg : classify.last()) {
  171. lastNodes << msg.name;
  172. }
  173. return lastNodes;
  174. }
  175. int MatrixPanelWidget::getPages()
  176. {
  177. #if 0
  178. int max = 0;
  179. for (MindNodeManager::NodeMessage msg : currentMindNodes->getMindNodes()) {
  180. QStringList nodePonit = msg.node.split(".");
  181. if (max < nodePonit.count() - 1) { max = nodePonit.count() - 1; }
  182. }
  183. return max;
  184. #else
  185. if (!classifiedNodes) { return 0; }
  186. return classifiedNodes->count();
  187. #endif
  188. }
  189. void MatrixPanelWidget::setPage(int page)
  190. {
  191. if (page < 1 || page > getPages()) { return; }
  192. currentPage = page;
  193. ui->currPageLabel->setText(QString("当前第%1页").arg(currentPage));
  194. if (currentPage == 1) {
  195. ui->prePageBtn->setDisabled(true);
  196. ui->nextPageBtn->setDisabled(false);
  197. } else if (currentPage == getPages()) {
  198. ui->prePageBtn->setDisabled(false);
  199. ui->nextPageBtn->setDisabled(true);
  200. } else {
  201. ui->prePageBtn->setDisabled(false);
  202. ui->nextPageBtn->setDisabled(false);
  203. }
  204. paintPlainWidget();
  205. }
  206. void MatrixPanelWidget::initPlainWidget()
  207. {
  208. if (getPages() == 0) { return; }
  209. //准备第一页,非tab的
  210. MatrixTableWidget *table = new MatrixTableWidget((indexsRefClassifiedNodes == nullptr), nullptr);
  211. connect(table, &MatrixTableWidget::dataReady, this, &MatrixPanelWidget::oneTableDataReady);
  212. if (indexsRefClassifiedNodes) {
  213. for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) {
  214. table->addRowNode(msg.node, msg.name, msg.remark);
  215. }
  216. }
  217. for (MindNodeManager::NodeMessage msg : classifiedNodes->first()) {
  218. table->addColNode(msg.node, msg.name, msg.remark);
  219. if (indexsRefClassifiedNodes == nullptr) { table->addRowNode(msg.node, msg.name, msg.remark); }
  220. }
  221. table->paintMatrixTable();
  222. firstLayout->addWidget(table);
  223. //准备第二页,tab组合的
  224. for (int p = 1; p < getPages(); ++p) {
  225. QTabWidget *tab = new QTabWidget;
  226. tab->setTabPosition(QTabWidget::South);
  227. for (MindNodeManager::NodeMessage msg : classifiedNodes->at(p - 1)) {
  228. QString node = msg.node;
  229. // MatrixTableWidget *table = nullptr;
  230. table = nullptr;
  231. for (MindNodeManager::NodeMessage info : classifiedNodes->at(p)) {
  232. if ((info.node.count('.') == msg.node.count('.') + 1)
  233. && (info.node.left(msg.node.count()) == msg.node)) {
  234. if (!table) { table = new MatrixTableWidget((indexsRefClassifiedNodes == nullptr), nullptr); }
  235. if (table) {
  236. table->addColNode(info.node, info.name, info.remark);
  237. if (!indexsRefClassifiedNodes) { table->addRowNode(info.node, info.name, info.remark); }
  238. }
  239. }
  240. }
  241. if (indexsRefClassifiedNodes) {
  242. for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) {
  243. table->addRowNode(msg.node, msg.name, msg.remark);
  244. }
  245. }
  246. if (table) {
  247. table->paintMatrixTable();
  248. tab->addTab(table, msg.name);
  249. connect(table, &MatrixTableWidget::dataReady, this, &MatrixPanelWidget::oneTableDataReady);
  250. }
  251. }
  252. tabWidgets << tab;
  253. }
  254. // secondLayout->addWidget(tab);
  255. }
  256. void MatrixPanelWidget::initPlainTechMeasuresWidget()
  257. {
  258. if (getPages() == 0) { return; }
  259. //准备第一页,非tab的
  260. MatrixTableTechMeasuresWidget *table = new MatrixTableTechMeasuresWidget(nullptr);
  261. connect(table, &MatrixTableTechMeasuresWidget::dataReady, this, &MatrixPanelWidget::oneTechMeasureTableDataReady);
  262. if (indexsRefClassifiedNodes) {
  263. for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) {
  264. table->addRowNode(msg.node, msg.name, msg.remark);
  265. }
  266. }
  267. for (MindNodeManager::NodeMessage msg : classifiedNodes->first()) {
  268. table->addColNode(msg.node, msg.name, msg.remark);
  269. if (indexsRefClassifiedNodes == nullptr) { table->addRowNode(msg.node, msg.name, msg.remark); }
  270. }
  271. table->paintMatrixTable();
  272. firstLayout->addWidget(table);
  273. //准备第二页,tab组合的
  274. for (int p = 1; p < getPages(); ++p) {
  275. QTabWidget *tab = new QTabWidget;
  276. tab->setTabPosition(QTabWidget::South);
  277. for (MindNodeManager::NodeMessage msg : classifiedNodes->at(p - 1)) {
  278. QString node = msg.node;
  279. // MatrixTableWidget *table = nullptr;
  280. table = nullptr;
  281. for (MindNodeManager::NodeMessage info : classifiedNodes->at(p)) {
  282. if ((info.node.count('.') == msg.node.count('.') + 1)
  283. && (info.node.left(msg.node.count()) == msg.node)) {
  284. if (!table) { table = new MatrixTableTechMeasuresWidget(nullptr); }
  285. if (table) {
  286. table->addColNode(info.node, info.name, info.remark);
  287. if (!indexsRefClassifiedNodes) { table->addRowNode(info.node, info.name, info.remark); }
  288. }
  289. }
  290. }
  291. if (indexsRefClassifiedNodes) {
  292. for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) {
  293. table->addRowNode(msg.node, msg.name, msg.remark);
  294. }
  295. }
  296. if (table) {
  297. table->paintMatrixTable();
  298. tab->addTab(table, msg.name);
  299. connect(table, &MatrixTableTechMeasuresWidget::dataReady, this,
  300. &MatrixPanelWidget::oneTechMeasureTableDataReady);
  301. }
  302. }
  303. tabWidgets << tab;
  304. }
  305. // secondLayout->addWidget(tab);
  306. }
  307. void MatrixPanelWidget::paintPlainWidget()
  308. {
  309. bool firstShow = true;
  310. if (getPages() == 0) { return; }
  311. if (currentPage > 1) { firstShow = false; }
  312. if (firstShow) {
  313. ui->stackedWidget->setCurrentIndex(0);
  314. } else {
  315. QTabWidget *newTab = tabWidgets.at(currentPage - 2);
  316. if (secondLayout->count() == 0) {
  317. secondLayout->addWidget(newTab);
  318. newTab->show();
  319. } else {
  320. QTabWidget *currTab = qobject_cast<QTabWidget *>(secondLayout->itemAt(0)->widget());
  321. if (newTab == currTab) {
  322. qDebug() << "same tab";
  323. } else {
  324. secondLayout->removeWidget(currTab);
  325. currTab->hide();
  326. secondLayout->addWidget(newTab);
  327. newTab->show();
  328. }
  329. }
  330. ui->stackedWidget->setCurrentIndex(1);
  331. }
  332. }
  333. void MatrixPanelWidget::on_prePageBtn_clicked()
  334. {
  335. setPage(currentPage - 1);
  336. }
  337. void MatrixPanelWidget::on_nextPageBtn_clicked()
  338. {
  339. setPage(currentPage + 1);
  340. }
  341. void MatrixPanelWidget::on_saveBtn_clicked()
  342. {
  343. if (currentTab == "技术措施") {
  344. QList<NodeMatrixInfo *> nodeInfoList;
  345. MatrixTableTechMeasuresWidget *first =
  346. qobject_cast<MatrixTableTechMeasuresWidget *>(firstLayout->itemAt(0)->widget());
  347. //保存第一页数据
  348. for (MatrixDataSource s : first->getSource()) {
  349. NodeMatrixInfo *t = new NodeMatrixInfo();
  350. t->abscissa = s.abscissa;
  351. t->ordinate = s.ordinate;
  352. t->node = s.node;
  353. t->nodeValue = s.nodeValue;
  354. t->expertId = m_professor.id;
  355. t->expertName = m_professor.name;
  356. t->engineerId = m_professor.engineer.engineerId;
  357. t->writeDate = m_professor.createDataTime;
  358. nodeInfoList.append(t);
  359. }
  360. DBServiceSet().AddNodeMatrixInfoList(nodeInfoList);
  361. //保存第二页数据,如果有
  362. QList<NodeMatrixInfo *> secondNodeInfoList;
  363. for (QTabWidget *tabWidget : tabWidgets) {
  364. for (int i = 0; i < tabWidget->count(); ++i) {
  365. MatrixTableTechMeasuresWidget *table =
  366. dynamic_cast<MatrixTableTechMeasuresWidget *>(tabWidget->widget(i));
  367. for (MatrixDataSource s : table->getSource()) {
  368. NodeMatrixInfo *t = new NodeMatrixInfo();
  369. t->abscissa = s.abscissa;
  370. t->ordinate = s.ordinate;
  371. t->node = s.node;
  372. t->nodeValue = s.nodeValue;
  373. secondNodeInfoList.append(t);
  374. }
  375. }
  376. }
  377. DBServiceSet().AddNodeMatrixInfoList(secondNodeInfoList);
  378. QMessageBox::information(this, tr("成功"), tr("数据保存成功"));
  379. this->close();
  380. } else {
  381. QList<NodeMatrixInfo *> nodeInfoList;
  382. MatrixTableWidget *first = qobject_cast<MatrixTableWidget *>(firstLayout->itemAt(0)->widget());
  383. //保存第一页数据
  384. for (MatrixDataSource s : first->getSource()) {
  385. NodeMatrixInfo *t = new NodeMatrixInfo();
  386. t->abscissa = s.abscissa;
  387. t->ordinate = s.ordinate;
  388. t->node = s.node;
  389. t->nodeValue = s.nodeValue;
  390. nodeInfoList.append(t);
  391. }
  392. DBServiceSet().AddNodeMatrixInfoList(nodeInfoList);
  393. //保存第二页数据,如果有
  394. QList<NodeMatrixInfo *> secondNodeInfoList;
  395. for (QTabWidget *tabWidget : tabWidgets) {
  396. for (int i = 0; i < tabWidget->count(); ++i) {
  397. MatrixTableWidget *table = dynamic_cast<MatrixTableWidget *>(tabWidget->widget(i));
  398. for (MatrixDataSource s : table->getSource()) {
  399. NodeMatrixInfo *t = new NodeMatrixInfo();
  400. t->abscissa = s.abscissa;
  401. t->ordinate = s.ordinate;
  402. t->node = s.node;
  403. t->nodeValue = s.nodeValue;
  404. t->expertId = m_professor.name;
  405. t->expertName = m_professor.name;
  406. t->engineerId = m_professor.engineer.engineerId;
  407. t->writeDate = m_professor.createDataTime;
  408. secondNodeInfoList.append(t);
  409. }
  410. }
  411. DBServiceSet().AddNodeMatrixInfoList(secondNodeInfoList);
  412. QMessageBox::information(this, tr("成功"), tr("数据保存成功"));
  413. this->close();
  414. }
  415. }
  416. void MatrixPanelWidget::oneTableDataReady(bool status)
  417. {
  418. if (status) {
  419. bool filled = true;
  420. MatrixTableWidget *first = qobject_cast<MatrixTableWidget *>(firstLayout->itemAt(0)->widget());
  421. if (!first->isDataReady()) { filled = false; }
  422. for (QTabWidget *tab : tabWidgets) {
  423. for (int t = 0; t < tab->count(); ++t) {
  424. MatrixTableWidget *table = qobject_cast<MatrixTableWidget *>(tab->widget(t));
  425. if (!table->isDataReady()) { filled = false; }
  426. }
  427. }
  428. if (filled) {
  429. ui->saveBtn->setDisabled(false);
  430. } else {
  431. ui->saveBtn->setDisabled(true);
  432. }
  433. } else {
  434. ui->saveBtn->setDisabled(true);
  435. }
  436. }
  437. void MatrixPanelWidget::oneTechMeasureTableDataReady(bool status)
  438. {
  439. qDebug() << "status = " << status;
  440. if (status) {
  441. bool filled = true;
  442. MatrixTableTechMeasuresWidget *first =
  443. qobject_cast<MatrixTableTechMeasuresWidget *>(firstLayout->itemAt(0)->widget());
  444. if (!first->isDataReady()) { filled = false; }
  445. qDebug() << "filled1 = " << filled;
  446. qDebug() << "tabWidgets = " << tabWidgets.size();
  447. for (QTabWidget *tab : tabWidgets) {
  448. for (int t = 0; t < tab->count(); ++t) {
  449. MatrixTableTechMeasuresWidget *table =
  450. qobject_cast<MatrixTableTechMeasuresWidget *>(tab->widget(t));
  451. qDebug() << "table = " << table->isDataReady();
  452. if (!table->isDataReady()) { filled = false; }
  453. }
  454. }
  455. qDebug() << "filled2 = " << filled;
  456. if (filled) {
  457. ui->saveBtn->setDisabled(false);
  458. } else {
  459. ui->saveBtn->setDisabled(true);
  460. }
  461. } else {
  462. ui->saveBtn->setDisabled(true);
  463. }
  464. }