IndexSystemWidget.cpp 5.0 KB

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