SchemeFlowWidget.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include "SchemeFlowWidget.h"
  2. #include <dbService/ClassSet.h>
  3. #include <QGroupBox>
  4. #include <QCheckBox>
  5. #include <QBoxLayout>
  6. #include <QDebug>
  7. #include <QtNodes/GraphicsView>
  8. using QtNodes::GraphicsView;
  9. static std::shared_ptr<NodeDelegateModelRegistry> registerDataModels()
  10. {
  11. auto ret = std::make_shared<NodeDelegateModelRegistry>();
  12. ret->registerModel<FlowTemplateDataModel>();
  13. return ret;
  14. }
  15. static void setStyle_()
  16. {
  17. GraphicsViewStyle::setStyle(
  18. R"(
  19. {
  20. "GraphicsViewStyle": {
  21. "BackgroundColor": [255, 255, 255],
  22. "FineGridColor": [255, 255, 255],
  23. "CoarseGridColor": [255, 255, 255]
  24. }
  25. }
  26. )");
  27. NodeStyle::setNodeStyle(
  28. R"(
  29. {
  30. "NodeStyle": {
  31. "NormalBoundaryColor": "darkgray",
  32. "SelectedBoundaryColor": "deepskyblue",
  33. "GradientColor0": "mintcream",
  34. "GradientColor1": "mintcream",
  35. "GradientColor2": "mintcream",
  36. "GradientColor3": "mintcream",
  37. "ShadowColor": [200, 200, 200],
  38. "FontColor": [10, 10, 10],
  39. "FontColorFaded": [100, 100, 100],
  40. "ConnectionPointColor": "white",
  41. "PenWidth": 2.0,
  42. "HoveredPenWidth": 2.5,
  43. "ConnectionPointDiameter": 10.0,
  44. "Opacity": 1.0
  45. }
  46. }
  47. )");
  48. ConnectionStyle::setConnectionStyle(
  49. R"(
  50. {
  51. "ConnectionStyle": {
  52. "ConstructionColor": "gray",
  53. "NormalColor": "black",
  54. "SelectedColor": "gray",
  55. "SelectedHaloColor": "deepskyblue",
  56. "HoveredColor": "deepskyblue",
  57. "LineWidth": 3.0,
  58. "ConstructionLineWidth": 2.0,
  59. "PointDiameter": 10.0,
  60. "UseDataDefinedColors": false
  61. }
  62. }
  63. )");
  64. }
  65. SchemeFlowWidget::SchemeFlowWidget(ProjectInfo *proj, int indexType, QWidget *parent) : QWidget(parent)
  66. {
  67. setStyle_();
  68. initWidgets();
  69. initLayout();
  70. }
  71. SchemeFlowWidget::~SchemeFlowWidget()
  72. {
  73. delete graphModel;
  74. }
  75. void SchemeFlowWidget::initWidgets()
  76. {
  77. graphModel = new DataFlowModel(registerDataModels());
  78. // Initialize and connect two nodes.
  79. {
  80. NodeId id1 = graphModel->addNode(FlowTemplateData().type().id);
  81. graphModel->setNodeData(id1, NodeRole::Position, QPointF(0, 0));
  82. NodeId id2 = graphModel->addNode(FlowTemplateData().type().id);
  83. graphModel->setNodeData(id2, NodeRole::Position, QPointF(200, 0));
  84. graphModel->addConnection(ConnectionId { id1, 0, id2, 0 });
  85. NodeId id3 = graphModel->addNode(FlowTemplateData().type().id);
  86. graphModel->setNodeData(id3, NodeRole::Position, QPointF(400, 0));
  87. graphModel->addConnection(ConnectionId { id2, 0, id3, 0 });
  88. }
  89. auto scene = new DataFlowGraphicsScene(*graphModel);
  90. QHBoxLayout *l = new QHBoxLayout(this);
  91. GraphicsView *view = new GraphicsView(scene);
  92. l->addWidget(view);
  93. QGroupBox *groupBox = new QGroupBox("Options");
  94. QCheckBox *cb1 = new QCheckBox("Nodes are locked");
  95. QCheckBox *cb2 = new QCheckBox("Connections detachable");
  96. cb2->setChecked(true);
  97. QVBoxLayout *vbl = new QVBoxLayout;
  98. vbl->addWidget(cb1);
  99. vbl->addWidget(cb2);
  100. vbl->addStretch();
  101. groupBox->setLayout(vbl);
  102. QObject::connect(cb1, &QCheckBox::stateChanged,
  103. [this](int state) { graphModel->setNodesLocked(state == Qt::Checked); });
  104. QObject::connect(cb2, &QCheckBox::stateChanged,
  105. [this](int state) { graphModel->setDetachPossible(state == Qt::Checked); });
  106. l->addWidget(groupBox);
  107. this->setWindowTitle("Locked Nodes and Connections");
  108. this->resize(800, 600);
  109. }
  110. void SchemeFlowWidget::initLayout() { }