IndexSystemWidget.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <QDebug>
  12. IndexSystemWidget::IndexSystemWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent)
  13. {
  14. setTitle("指标体系设计");
  15. initWidgets();
  16. initLayout();
  17. connectSignalsAndSlots();
  18. }
  19. void IndexSystemWidget::initWidgets()
  20. {
  21. m_mindView = new CMindView(this);
  22. }
  23. void IndexSystemWidget::initLayout()
  24. {
  25. m_contentLayout->addWidget(m_mindView);
  26. }
  27. void IndexSystemWidget::connectSignalsAndSlots()
  28. {
  29. connect(m_mindView, &CMindView::sigAddSubNode, this, &IndexSystemWidget::slotAddSubNode);
  30. connect(m_mindView->mind(), &CMind::sigRemoveNode, this, &IndexSystemWidget::slotRemoveNode);
  31. connect(m_mindView, &CMindView::sigNodeChanged, this, &IndexSystemWidget::slotUpdateNode);
  32. }
  33. void IndexSystemWidget::setType(int type)
  34. {
  35. EvalWidget::setType(type);
  36. QList<CNodeData> list;
  37. bool ret = CNodeDataService().QueryAll(list, proj()->id, type);
  38. if (ret) {
  39. m_mindView->setNodeList(list);
  40. }
  41. }
  42. void IndexSystemWidget::contextMenuEvent(QContextMenuEvent *event)
  43. {
  44. RoundMenu *menu = new RoundMenu();
  45. if (m_mindView->root() == nullptr) {
  46. QAction *act3 = new QAction("创建根节点");
  47. menu->addAction(act3);
  48. connect(act3, &QAction::triggered, this, &IndexSystemWidget::slotCreateRootNode);
  49. } else {
  50. QAction *act2 = new QAction("清空");
  51. menu->addAction(act2);
  52. connect(act2, &QAction::triggered, this, &IndexSystemWidget::slotClearAllNodes);
  53. }
  54. menu->exec(event->globalPos() + QPoint(-40, -20));
  55. QWidget::contextMenuEvent(event);
  56. }
  57. void IndexSystemWidget::addNode(CNodeData node)
  58. {
  59. qDebug() << __FUNCTION__ << __LINE__ << node.number << endl;
  60. if (m_mindView->mind()->canAddNode(node)) {
  61. int id = CNodeDataService().AddCNodeData(node);
  62. if (id >= 0) {
  63. node.id = id;
  64. m_mindView->addNode(node);
  65. }
  66. }
  67. }
  68. void IndexSystemWidget::slotSelectAllNodes()
  69. {
  70. qDebug() << __FUNCTION__ << __LINE__ << endl;
  71. }
  72. void IndexSystemWidget::slotClearAllNodes()
  73. {
  74. m_mindView->clear();
  75. }
  76. void IndexSystemWidget::slotCreateRootNode()
  77. {
  78. CNodeData n = CNodeData(m_proj->id, m_type, 0);
  79. n.name = m_proj->projectName;
  80. addNode(n);
  81. }
  82. void IndexSystemWidget::slotAddSubNode(int pNumber)
  83. {
  84. if (pNumber < 0) {
  85. return;
  86. }
  87. CNodeData data = m_mindView->root()->data();
  88. CNodeData n = CNodeData(data.projectId, data.evalType, m_mindView->mind()->maxNumber() + 1, pNumber);
  89. addNode(n);
  90. }
  91. void IndexSystemWidget::slotUpdateNode(CNodeData node)
  92. {
  93. CNodeDataService().UpdateCNodeData(node);
  94. }
  95. void IndexSystemWidget::slotRemoveNode(int id)
  96. {
  97. CNodeDataService().DeleteCNodeDataById(id);
  98. }