IndexSystemWidget.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "IndexSystemWidget.h"
  2. #include <dbService/ClassSet.h>
  3. #include <dbService/CNodeDataService.h>
  4. #include <CMindView.h>
  5. #include <CMind.h>
  6. #include <CNodeItem.h>
  7. #include <Widgets/Menu.h>
  8. #include <QLayout>
  9. #include <QMenu>
  10. #include <QContextMenuEvent>
  11. #include <QTabWidget>
  12. #include <QDebug>
  13. IndexSystemWidget::IndexSystemWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent)
  14. {
  15. setTitle("指标体系设计");
  16. initWidgets();
  17. initLayout();
  18. connectSignalsAndSlots();
  19. }
  20. void IndexSystemWidget::setType(int type)
  21. {
  22. EvalWidget::setType(type);
  23. setupTabWidget();
  24. }
  25. void IndexSystemWidget::contextMenuEvent(QContextMenuEvent *event)
  26. {
  27. RoundMenu *menu = new RoundMenu();
  28. CMindView *m = (CMindView *)m_tab->currentWidget();
  29. if (m->root() == nullptr) {
  30. QAction *act3 = new QAction("创建根节点");
  31. menu->addAction(act3);
  32. connect(act3, &QAction::triggered, this, &IndexSystemWidget::slotCreateRootNode);
  33. } else {
  34. QAction *act2 = new QAction("清空");
  35. menu->addAction(act2);
  36. connect(act2, &QAction::triggered, this, &IndexSystemWidget::slotClearAllNodes);
  37. }
  38. menu->exec(event->globalPos() + QPoint(-40, -20));
  39. QWidget::contextMenuEvent(event);
  40. }
  41. void IndexSystemWidget::setupTabWidget()
  42. {
  43. m_tab->clear();
  44. for (int i : m_indexList) {
  45. CMindView *m = new CMindView(this);
  46. ProjectManager::IndexType t = (ProjectManager::IndexType)i;
  47. QString s = ProjectManager::nameOfIndexType(t);
  48. m_tab->addTab(m, s);
  49. QList<CNodeData> list;
  50. bool ret = CNodeDataService().QueryAll(list, proj()->id, t);
  51. if (ret) {
  52. m->setNodeList(list);
  53. }
  54. connect(m, &CMindView::sigAddSubNode, this, &IndexSystemWidget::slotAddSubNode);
  55. connect(m->mind(), &CMind::sigRemoveNode, this, &IndexSystemWidget::slotRemoveNode);
  56. connect(m, &CMindView::sigNodeChanged, this, &IndexSystemWidget::slotUpdateNode);
  57. }
  58. }
  59. void IndexSystemWidget::initWidgets() { }
  60. void IndexSystemWidget::initLayout() { }
  61. void IndexSystemWidget::connectSignalsAndSlots()
  62. {
  63. connect(m_tab, &QTabWidget::currentChanged, this, &IndexSystemWidget::slotTabCurrentChanged);
  64. }
  65. void IndexSystemWidget::addNode(CNodeData node)
  66. {
  67. CMindView *m = (CMindView *)m_tab->currentWidget();
  68. if (m->mind()->canAddNode(node)) {
  69. int id = CNodeDataService().AddCNodeData(node);
  70. if (id >= 0) {
  71. node.id = id;
  72. m->addNode(node);
  73. }
  74. }
  75. }
  76. void IndexSystemWidget::slotTabCurrentChanged(int c)
  77. {
  78. Q_UNUSED(c)
  79. }
  80. void IndexSystemWidget::slotSelectAllNodes() { }
  81. void IndexSystemWidget::slotClearAllNodes()
  82. {
  83. CMindView *m = (CMindView *)m_tab->currentWidget();
  84. m->clear();
  85. }
  86. void IndexSystemWidget::slotCreateRootNode()
  87. {
  88. int t = m_indexList[m_tab->currentIndex()];
  89. CNodeData n = CNodeData(m_proj->id, t, 0);
  90. n.name = m_proj->projectName;
  91. addNode(n);
  92. }
  93. void IndexSystemWidget::slotAddSubNode(int pNumber)
  94. {
  95. if (pNumber < 0) {
  96. return;
  97. }
  98. CMindView *m = (CMindView *)m_tab->currentWidget();
  99. CNodeData data = m->root()->data();
  100. CNodeData n = CNodeData(data.projectId, data.indexType, m->mind()->maxNumber() + 1, pNumber);
  101. addNode(n);
  102. }
  103. void IndexSystemWidget::slotUpdateNode(CNodeData node)
  104. {
  105. CNodeDataService().UpdateCNodeData(node);
  106. }
  107. void IndexSystemWidget::slotRemoveNode(int id)
  108. {
  109. CNodeDataService().DeleteCNodeDataById(id);
  110. }