IndexSystemWidget.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. }
  32. void IndexSystemWidget::setType(int type)
  33. {
  34. EvalWidget::setType(type);
  35. QList<CNodeData> list;
  36. bool ret = CNodeDataService().QueryAll(list, proj()->id, type);
  37. if (ret) {
  38. m_mindView->setNodeList(list);
  39. }
  40. }
  41. void IndexSystemWidget::contextMenuEvent(QContextMenuEvent *event)
  42. {
  43. RoundMenu *menu = new RoundMenu();
  44. if (m_mindView->root() == nullptr) {
  45. QAction *act3 = new QAction("创建根节点");
  46. menu->addAction(act3);
  47. connect(act3, &QAction::triggered, this, &IndexSystemWidget::slotCreateRootNode);
  48. } else {
  49. QAction *act2 = new QAction("清空");
  50. menu->addAction(act2);
  51. connect(act2, &QAction::triggered, this, &IndexSystemWidget::slotClearAllNodes);
  52. }
  53. menu->exec(event->globalPos() + QPoint(-40, -20));
  54. QWidget::contextMenuEvent(event);
  55. }
  56. void IndexSystemWidget::addNode(CNodeData node)
  57. {
  58. qDebug() << __FUNCTION__ << __LINE__ << node.number << endl;
  59. if (m_mindView->mind()->canAddNode(node)) {
  60. int id = CNodeDataService().AddCNodeData(node);
  61. if (id >= 0) {
  62. node.id = id;
  63. m_mindView->addNode(node);
  64. }
  65. }
  66. }
  67. void IndexSystemWidget::removeNode(int id)
  68. {
  69. qDebug() << __FUNCTION__ << __LINE__ << id << endl;
  70. }
  71. void IndexSystemWidget::slotSelectAllNodes()
  72. {
  73. qDebug() << __FUNCTION__ << __LINE__ << endl;
  74. }
  75. void IndexSystemWidget::slotClearAllNodes()
  76. {
  77. m_mindView->clear();
  78. }
  79. void IndexSystemWidget::slotCreateRootNode()
  80. {
  81. CNodeData n = CNodeData(m_proj->id, m_type, 0);
  82. n.name = m_proj->projectName;
  83. addNode(n);
  84. }
  85. void IndexSystemWidget::slotAddSubNode(int pNumber)
  86. {
  87. if (pNumber < 0) {
  88. return;
  89. }
  90. CNodeData data = m_mindView->root()->data();
  91. CNodeData n = CNodeData(data.projectId, data.evalType, m_mindView->mind()->maxNumber() + 1, pNumber);
  92. addNode(n);
  93. }
  94. void IndexSystemWidget::slotRemoveNode(int id)
  95. {
  96. removeNode(id);
  97. }