SchemeFlowWidget.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #include "SchemeFlowWidget.h"
  2. #include "shemeFlow/FlowGraphNodeWidget.h"
  3. #include "ProjectManager.h"
  4. #include <dbService/ClassSet.h>
  5. #include <dbService/SchemeProcessService.h>
  6. #include <QGroupBox>
  7. #include <QCheckBox>
  8. #include <QBoxLayout>
  9. #include <QDebug>
  10. #include <QtNodes/GraphicsView>
  11. using QtNodes::GraphicsView;
  12. static std::shared_ptr<NodeDelegateModelRegistry> registerDataModels()
  13. {
  14. auto ret = std::make_shared<NodeDelegateModelRegistry>();
  15. ret->registerModel<FlowTemplateDataModel>();
  16. ret->registerModel<FlowIndexDataModel>();
  17. ret->registerModel<FlowSampleDataModel>();
  18. ret->registerModel<FlowPCADataModel>();
  19. ret->registerModel<FlowWeightDataModel>();
  20. ret->registerModel<FlowResultDataModel>();
  21. ret->registerModel<FlowReportDataModel>();
  22. ret->registerModel<FlowEffiLevDataModel>();
  23. ret->registerModel<FlowSchemeDataModel>();
  24. ret->registerModel<FlowEffiDataModel>();
  25. ret->registerModel<FlowCommonDataModel>();
  26. return ret;
  27. }
  28. static void setStyle_()
  29. {
  30. GraphicsViewStyle::setStyle(
  31. R"(
  32. {
  33. "GraphicsViewStyle": {
  34. "BackgroundColor": [255, 255, 255],
  35. "FineGridColor": [255, 255, 255],
  36. "CoarseGridColor": [255, 255, 255]
  37. }
  38. }
  39. )");
  40. NodeStyle::setNodeStyle(
  41. R"(
  42. {
  43. "NodeStyle": {
  44. "NormalBoundaryColor": "darkgray",
  45. "SelectedBoundaryColor": "deepskyblue",
  46. "GradientColor0": "mintcream",
  47. "GradientColor1": "mintcream",
  48. "GradientColor2": "mintcream",
  49. "GradientColor3": "mintcream",
  50. "ShadowColor": [200, 200, 200],
  51. "FontColor": [10, 10, 10],
  52. "FontColorFaded": [100, 100, 100],
  53. "ConnectionPointColor": "white",
  54. "PenWidth": 2.0,
  55. "HoveredPenWidth": 2.5,
  56. "ConnectionPointDiameter": 10.0,
  57. "Opacity": 1.0
  58. }
  59. }
  60. )");
  61. ConnectionStyle::setConnectionStyle(
  62. R"(
  63. {
  64. "ConnectionStyle": {
  65. "ConstructionColor": "gray",
  66. "NormalColor": "black",
  67. "SelectedColor": "gray",
  68. "SelectedHaloColor": "deepskyblue",
  69. "HoveredColor": "deepskyblue",
  70. "LineWidth": 3.0,
  71. "ConstructionLineWidth": 2.0,
  72. "PointDiameter": 10.0,
  73. "UseDataDefinedColors": false
  74. }
  75. }
  76. )");
  77. }
  78. SchemeFlowWidget::SchemeFlowWidget(QWidget *parent) : QWidget(parent)
  79. {
  80. setStyle_();
  81. initWidget();
  82. }
  83. SchemeFlowWidget::~SchemeFlowWidget()
  84. {
  85. delete m_graphModel;
  86. }
  87. QList<SchemePlanManager::SchemeProcessInfo> SchemeFlowWidget::schemes() const
  88. {
  89. QList<SchemePlanManager::SchemeProcessInfo> schemes;
  90. for (int id : m_graphModel->allNodeIds()) {
  91. auto v = m_graphModel->nodeData(id, NodeRole::Widget);
  92. FlowGraphCommonNodeWidget *w = v.value<FlowGraphCommonNodeWidget *>();
  93. SchemePlanManager::SchemeProcessInfo process = w->process();
  94. }
  95. return schemes;
  96. }
  97. void SchemeFlowWidget::loadSchemes(const QList<SchemePlanManager::SchemeProcessInfo> &schems)
  98. {
  99. clearAllNodes();
  100. int y = 0; // 流程图节点位置
  101. int space = 30; // 流程图节点间距
  102. NodeId invalidId = 999;
  103. NodeId lastId = invalidId;
  104. for (int i = 0; i < schems.count(); i++) {
  105. NodeId id = m_graphModel->addNode(FlowCommonData().type().id);
  106. m_graphModel->setNodeData(id, NodeRole::Position, QPointF(0, y));
  107. FlowGraphCommonNodeWidget *w = new FlowGraphCommonNodeWidget();
  108. connect(w, &FlowGraphCommonNodeWidget::sigProcessEdited, this, &SchemeFlowWidget::slotSchemeProcessEdited);
  109. SchemePlanManager::SchemeProcessInfo process = schems[i];
  110. w->setProcess(process);
  111. if (w->isTitleHidden()) {
  112. m_graphModel->setNodeData(id, NodeRole::Caption, SchemePlanManager::processName(process));
  113. }
  114. m_graphModel->setNodeData(id, NodeRole::Widget, QVariant::fromValue(w));
  115. if (lastId < invalidId) {
  116. m_graphModel->addConnection(ConnectionId { lastId, 0, id, 0 });
  117. }
  118. QSize s = m_graphModel->nodeData(id, NodeRole::Size).toSize();
  119. y += (s.height() + space);
  120. lastId = id;
  121. }
  122. }
  123. void SchemeFlowWidget::initWidget()
  124. {
  125. m_graphModel = new DataFlowModel(registerDataModels());
  126. m_graphModel->setNodesLocked(true);
  127. m_graphModel->setDetachPossible(false);
  128. auto scene = new DataFlowGraphicsScene(*m_graphModel);
  129. GraphicsView *view = new GraphicsView(scene);
  130. scene->setOrientation(Qt::Vertical);
  131. QHBoxLayout *l = new QHBoxLayout(this);
  132. l->addWidget(view);
  133. }
  134. void SchemeFlowWidget::clearAllNodes()
  135. {
  136. for (int id : m_graphModel->allNodeIds()) {
  137. m_graphModel->deleteNode(id);
  138. }
  139. }
  140. void SchemeFlowWidget::slotSchemeProcessEdited(const SchemePlanManager::SchemeProcessInfo &process)
  141. {
  142. emit sigSchemeProcessEdited(process);
  143. }