SchemeFlowWidget.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. schemes.append(process);
  95. }
  96. return schemes;
  97. }
  98. void SchemeFlowWidget::loadSchemes(const QList<SchemePlanManager::SchemeProcessInfo> &schems)
  99. {
  100. clearAllNodes();
  101. int y = 0; // 流程图节点位置
  102. int space = 30; // 流程图节点间距
  103. NodeId invalidId = 999;
  104. NodeId lastId = invalidId;
  105. for (int i = 0; i < schems.count(); i++) {
  106. SchemePlanManager::SchemeProcessInfo process = schems[i];
  107. if (process.type == SchemePlanManager::OptimizeIndex) {
  108. continue;
  109. }
  110. NodeId id = m_graphModel->addNode(FlowCommonData().type().id);
  111. m_graphModel->setNodeData(id, NodeRole::Position, QPointF(0, y));
  112. FlowGraphCommonNodeWidget *w = new FlowGraphCommonNodeWidget();
  113. w->setAllowEdit(m_allowEdit);
  114. connect(w, &FlowGraphCommonNodeWidget::sigProcessEdited, this, &SchemeFlowWidget::slotSchemeProcessEdited);
  115. w->setProcess(process);
  116. if (w->isTitleHidden()) {
  117. m_graphModel->setNodeData(id, NodeRole::Caption, SchemePlanManager::processName(process));
  118. }
  119. m_graphModel->setNodeData(id, NodeRole::Widget, QVariant::fromValue(w));
  120. if (lastId < invalidId) {
  121. m_graphModel->addConnection(ConnectionId { lastId, 0, id, 0 });
  122. }
  123. QSize s = m_graphModel->nodeData(id, NodeRole::Size).toSize();
  124. y += (s.height() + space);
  125. lastId = id;
  126. }
  127. }
  128. void SchemeFlowWidget::setAllowEdit(bool allow)
  129. {
  130. m_allowEdit = allow;
  131. for (int id : m_graphModel->allNodeIds()) {
  132. FlowGraphCommonNodeWidget *w =
  133. m_graphModel->nodeData(id, NodeRole::Widget).value<FlowGraphCommonNodeWidget *>();
  134. w->setAllowEdit(allow);
  135. }
  136. }
  137. void SchemeFlowWidget::initWidget()
  138. {
  139. m_graphModel = new DataFlowModel(registerDataModels());
  140. m_graphModel->setNodesLocked(true);
  141. m_graphModel->setDetachPossible(false);
  142. auto scene = new DataFlowGraphicsScene(*m_graphModel);
  143. GraphicsView *view = new GraphicsView(scene);
  144. scene->setOrientation(Qt::Vertical);
  145. QHBoxLayout *l = new QHBoxLayout(this);
  146. l->addWidget(view);
  147. }
  148. void SchemeFlowWidget::clearAllNodes()
  149. {
  150. for (int id : m_graphModel->allNodeIds()) {
  151. m_graphModel->deleteNode(id);
  152. }
  153. }
  154. void SchemeFlowWidget::slotSchemeProcessEdited(const SchemePlanManager::SchemeProcessInfo &process)
  155. {
  156. emit sigSchemeProcessEdited(process);
  157. }