IndexSystemWidget.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 : 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::sigEditNode, this, &IndexSystemWidget::slotEditNode);
  55. connect(m, &CMindView::sigAddSubNode, this, &IndexSystemWidget::slotAddSubNode);
  56. connect(m->mind(), &CMind::sigRemoveNode, this, &IndexSystemWidget::slotRemoveNode);
  57. connect(m, &CMindView::sigNodeChanged, this, &IndexSystemWidget::slotUpdateNode);
  58. }
  59. }
  60. void IndexSystemWidget::initWidgets() { }
  61. void IndexSystemWidget::initLayout() { }
  62. void IndexSystemWidget::connectSignalsAndSlots()
  63. {
  64. connect(m_tab, &QTabWidget::currentChanged, this, &IndexSystemWidget::slotTabCurrentChanged);
  65. }
  66. void IndexSystemWidget::addNode(CNodeData node)
  67. {
  68. CMindView *m = (CMindView *)m_tab->currentWidget();
  69. if (m->mind()->canAddNode(node)) {
  70. int id = CNodeDataService().AddCNodeData(node);
  71. if (id >= 0) {
  72. node.id = id;
  73. m->addNode(node);
  74. }
  75. }
  76. }
  77. void IndexSystemWidget::slotTabCurrentChanged(int c)
  78. {
  79. Q_UNUSED(c)
  80. }
  81. void IndexSystemWidget::slotSelectAllNodes() { }
  82. void IndexSystemWidget::slotClearAllNodes()
  83. {
  84. CMindView *m = (CMindView *)m_tab->currentWidget();
  85. m->clear();
  86. }
  87. void IndexSystemWidget::slotCreateRootNode()
  88. {
  89. int t = indexList()[m_tab->currentIndex()];
  90. CNodeData n = CNodeData(m_proj->id, t, 0);
  91. n.name = m_proj->projectName;
  92. addNode(n);
  93. }
  94. void IndexSystemWidget::slotEditNode(CNodeData n)
  95. {
  96. qDebug() << __FUNCTION__ << __LINE__ << n.name << endl;
  97. }
  98. void IndexSystemWidget::slotAddSubNode(int pNumber)
  99. {
  100. if (pNumber < 0) {
  101. return;
  102. }
  103. CMindView *m = (CMindView *)m_tab->currentWidget();
  104. CNodeData data = m->root()->data();
  105. CNodeData n = CNodeData(data.projectId, data.indexType, m->mind()->maxNumber() + 1, pNumber);
  106. addNode(n);
  107. }
  108. void IndexSystemWidget::slotUpdateNode(CNodeData node)
  109. {
  110. CNodeDataService().UpdateCNodeData(node);
  111. }
  112. void IndexSystemWidget::slotRemoveNode(int id)
  113. {
  114. CNodeDataService().DeleteCNodeDataById(id);
  115. }