IndexSystemWidget.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #include "IndexSystemWidget.h"
  2. #include "EditNodeWidget.h"
  3. #include "ImportIndexWidget.h"
  4. #include <dbService/ClassSet.h>
  5. #include <dbService/CNodeDataService.h>
  6. #include <dbService/NodeMatrixService.h>
  7. #include <dbService/UserConfigService.h>
  8. #include <CMindView.h>
  9. #include <CMind.h>
  10. #include <CNodeItem.h>
  11. #include <Widgets/Menu.h>
  12. #include <QLayout>
  13. #include <QMenu>
  14. #include <QContextMenuEvent>
  15. #include <QTabWidget>
  16. #include <QDebug>
  17. IndexSystemWidget::IndexSystemWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent)
  18. {
  19. setTitle("指标体系设计");
  20. initWidgets();
  21. initLayout();
  22. connectSignalsAndSlots();
  23. }
  24. void IndexSystemWidget::setType(int type)
  25. {
  26. EvalWidget::setType(type);
  27. setupTabWidget();
  28. }
  29. void IndexSystemWidget::contextMenuEvent(QContextMenuEvent *event)
  30. {
  31. RoundMenu *menu = new RoundMenu();
  32. CMindView *m = (CMindView *)m_tab->currentWidget();
  33. if (m->root() == nullptr) {
  34. QAction *act3 = new QAction("创建指标体系");
  35. menu->addAction(act3);
  36. connect(act3, &QAction::triggered, this, &IndexSystemWidget::slotCreateRootNode);
  37. QAction *act4 = new QAction("导入指标体系");
  38. menu->addAction(act4);
  39. connect(act4, &QAction::triggered, this, &IndexSystemWidget::slotImportIndex);
  40. menu->exec(event->globalPos() + QPoint(-40, -20));
  41. } else {
  42. // QAction *act2 = new QAction("清空");
  43. // menu->addAction(act2);
  44. // connect(act2, &QAction::triggered, this, &IndexSystemWidget::slotClearAllNodes);
  45. }
  46. QWidget::contextMenuEvent(event);
  47. }
  48. void IndexSystemWidget::setupTabWidget()
  49. {
  50. m_tab->clear();
  51. for (int i : indexList()) {
  52. CMindView *m = new CMindView(this);
  53. ProjectManager::IndexType t = (ProjectManager::IndexType)i;
  54. QString s = ProjectManager::nameOfIndexType(t);
  55. m_tab->addTab(m, s);
  56. QList<CNodeData> list;
  57. bool ret = CNodeDataService().QueryAll(list, proj()->id, t);
  58. if (ret) {
  59. m->setNodeList(list);
  60. m->refreshItems();
  61. }
  62. connect(m, &CMindView::sigEditNode, this, &IndexSystemWidget::slotEditNode);
  63. connect(m, &CMindView::sigAddSubNode, this, &IndexSystemWidget::slotAddSubNode);
  64. connect(m->mind(), &CMind::sigRemoveNode, this, &IndexSystemWidget::slotRemoveNode);
  65. connect(m, &CMindView::sigNodeChanged, this, &IndexSystemWidget::slotUpdateNode);
  66. }
  67. }
  68. void IndexSystemWidget::initWidgets()
  69. {
  70. m_editNode = new EditNodeWidget(this);
  71. m_importIndex = new ImportIndexWidget(this);
  72. }
  73. void IndexSystemWidget::initLayout() { }
  74. void IndexSystemWidget::connectSignalsAndSlots()
  75. {
  76. connect(m_tab, &QTabWidget::currentChanged, this, &IndexSystemWidget::slotTabCurrentChanged);
  77. connect(m_editNode, &EditNodeWidget::sigSaveNode, this, &IndexSystemWidget::slotNodeEdited);
  78. connect(m_importIndex, &ImportIndexWidget::sigImport, this, &IndexSystemWidget::slotImportIndexConfirmed);
  79. }
  80. void IndexSystemWidget::addNode(CNodeData node)
  81. {
  82. CMindView *m = (CMindView *)m_tab->currentWidget();
  83. if (m->mind()->canAddNode(node)) {
  84. int id = CNodeDataService().AddCNodeData(node);
  85. if (id >= 0) {
  86. node.id = id;
  87. m->addNode(node);
  88. }
  89. }
  90. }
  91. bool IndexSystemWidget::hasData(QString indexName) const
  92. {
  93. bool ret = NodeMatrixService().hasMeasureData(m_proj->id, indexName);
  94. if (ret == true) {
  95. return true;
  96. }
  97. QList<UserConfig *> cfgList;
  98. ret = UserConfigService().QueryUserConfigListInfoByEngineerId(&cfgList, m_proj->id);
  99. if (ret == false) {
  100. return false;
  101. }
  102. for (UserConfig *cfg : cfgList) {
  103. ret = NodeMatrixService().hasExpertData(m_proj->id, indexName, cfg->userId);
  104. if (ret) {
  105. return true;
  106. }
  107. }
  108. return false;
  109. }
  110. void IndexSystemWidget::slotTabCurrentChanged(int c)
  111. {
  112. bool ret = hasData(m_tab->tabText(c));
  113. CMindView *m = (CMindView *)m_tab->currentWidget();
  114. if (m != nullptr) {
  115. m->setAllowEdit(!ret);
  116. QList<CNodeData> list = m->mind()->nodeList();
  117. m->setNodeList(list);
  118. }
  119. }
  120. void IndexSystemWidget::slotSelectAllNodes() { }
  121. void IndexSystemWidget::slotClearAllNodes()
  122. {
  123. CMindView *m = (CMindView *)m_tab->currentWidget();
  124. m->clear();
  125. }
  126. void IndexSystemWidget::slotCreateRootNode()
  127. {
  128. int t = indexList()[m_tab->currentIndex()];
  129. CNodeData n = CNodeData(m_proj->id, t, 0);
  130. n.name = m_proj->projectName;
  131. addNode(n);
  132. }
  133. void IndexSystemWidget::slotImportIndex()
  134. {
  135. m_importIndex->show();
  136. }
  137. void IndexSystemWidget::slotEditNode(CNodeData n)
  138. {
  139. m_editNode->setNode(n);
  140. m_editNode->show();
  141. }
  142. void IndexSystemWidget::slotAddSubNode(int pNumber)
  143. {
  144. if (pNumber < 0) {
  145. return;
  146. }
  147. CMindView *m = (CMindView *)m_tab->currentWidget();
  148. CNodeData data = m->root()->data();
  149. CNodeData n = CNodeData(data.projectId, data.indexType, m->mind()->maxNumber() + 1, pNumber);
  150. addNode(n);
  151. }
  152. void IndexSystemWidget::slotUpdateNode(CNodeData node)
  153. {
  154. CNodeDataService().UpdateCNodeData(node);
  155. }
  156. void IndexSystemWidget::slotRemoveNode(int id)
  157. {
  158. CNodeDataService().DeleteCNodeDataById(id);
  159. }
  160. void IndexSystemWidget::slotNodeEdited(CNodeData node)
  161. {
  162. // 在弹窗中编辑节点后, 先保存数据库, 再更新界面
  163. bool ret = CNodeDataService().UpdateCNodeData(node);
  164. if (ret) {
  165. CMindView *m = (CMindView *)m_tab->currentWidget();
  166. m->updateNode(node);
  167. }
  168. }
  169. void IndexSystemWidget::slotImportIndexConfirmed(int projId, int indexType)
  170. {
  171. m_importIndex->close();
  172. QList<CNodeData> list;
  173. bool ret = CNodeDataService().QueryAll(list, projId, indexType);
  174. if (ret == false) {
  175. return;
  176. }
  177. CMindView *m = (CMindView *)m_tab->currentWidget();
  178. int t = indexList()[m_tab->currentIndex()];
  179. for (int i = 0; i < list.size(); i++) {
  180. list[i].projectId = m_proj->id;
  181. list[i].indexType = t;
  182. list[i].isEffective = 0;
  183. int id = CNodeDataService().AddCNodeData(list[i]);
  184. if (id >= 0) {
  185. list[i].id = id;
  186. m->addNode(list[i]);
  187. }
  188. }
  189. m->refreshItems();
  190. }