SchemeFlowWidget.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. SchemePlanManager::SchemeProcessInfo process = schems[i];
  106. if (process.type == SchemePlanManager::OptimizeIndex) {
  107. continue;
  108. }
  109. NodeId id = m_graphModel->addNode(FlowCommonData().type().id);
  110. m_graphModel->setNodeData(id, NodeRole::Position, QPointF(0, y));
  111. FlowGraphCommonNodeWidget *w = new FlowGraphCommonNodeWidget();
  112. connect(w, &FlowGraphCommonNodeWidget::sigProcessEdited, this, &SchemeFlowWidget::slotSchemeProcessEdited);
  113. w->setProcess(process);
  114. if (w->isTitleHidden()) {
  115. m_graphModel->setNodeData(id, NodeRole::Caption, SchemePlanManager::processName(process));
  116. }
  117. m_graphModel->setNodeData(id, NodeRole::Widget, QVariant::fromValue(w));
  118. if (lastId < invalidId) {
  119. m_graphModel->addConnection(ConnectionId { lastId, 0, id, 0 });
  120. }
  121. QSize s = m_graphModel->nodeData(id, NodeRole::Size).toSize();
  122. y += (s.height() + space);
  123. lastId = id;
  124. }
  125. }
  126. void SchemeFlowWidget::initWidget()
  127. {
  128. m_graphModel = new DataFlowModel(registerDataModels());
  129. m_graphModel->setNodesLocked(true);
  130. m_graphModel->setDetachPossible(false);
  131. auto scene = new DataFlowGraphicsScene(*m_graphModel);
  132. GraphicsView *view = new GraphicsView(scene);
  133. scene->setOrientation(Qt::Vertical);
  134. QHBoxLayout *l = new QHBoxLayout(this);
  135. l->addWidget(view);
  136. }
  137. void SchemeFlowWidget::clearAllNodes()
  138. {
  139. for (int id : m_graphModel->allNodeIds()) {
  140. m_graphModel->deleteNode(id);
  141. }
  142. }
  143. void SchemeFlowWidget::slotSchemeProcessEdited(const SchemePlanManager::SchemeProcessInfo &process)
  144. {
  145. emit sigSchemeProcessEdited(process);
  146. }