#include "DataFlowModel.h" #include "FlowGraphModel.h" #include "FlowTemplateDataModel.h" #include "ShemeFlowPanel.h" #include "FlowGraphNodeWidget.h" #include #include #include #include #include #include #include #include #include using QtNodes::BasicGraphicsScene; using QtNodes::ConnectionStyle; using QtNodes::DataFlowGraphicsScene; using QtNodes::GraphicsView; using QtNodes::GraphicsViewStyle; using QtNodes::NodeDelegateModelRegistry; using QtNodes::NodeRole; using QtNodes::NodeStyle; static std::shared_ptr registerDataModels() { auto ret = std::make_shared(); ret->registerModel(); ret->registerModel(); ret->registerModel(); ret->registerModel(); ret->registerModel(); ret->registerModel(); ret->registerModel(); ret->registerModel(); ret->registerModel(); ret->registerModel(); return ret; } static FlowGraphModel graphModel; static void setStyle_() { GraphicsViewStyle::setStyle( R"( { "GraphicsViewStyle": { "BackgroundColor": [255, 255, 255], "FineGridColor": [255, 255, 255], "CoarseGridColor": [255, 255, 255] } } )"); NodeStyle::setNodeStyle( R"( { "NodeStyle": { "NormalBoundaryColor": "darkgray", "SelectedBoundaryColor": "deepskyblue", "GradientColor0": "mintcream", "GradientColor1": "mintcream", "GradientColor2": "mintcream", "GradientColor3": "mintcream", "ShadowColor": [200, 200, 200], "FontColor": [10, 10, 10], "FontColorFaded": [100, 100, 100], "ConnectionPointColor": "white", "PenWidth": 2.0, "HoveredPenWidth": 2.5, "ConnectionPointDiameter": 10.0, "Opacity": 1.0 } } )"); ConnectionStyle::setConnectionStyle( R"( { "ConnectionStyle": { "ConstructionColor": "gray", "NormalColor": "black", "SelectedColor": "gray", "SelectedHaloColor": "deepskyblue", "HoveredColor": "deepskyblue", "LineWidth": 3.0, "ConstructionLineWidth": 2.0, "PointDiameter": 10.0, "UseDataDefinedColors": false } } )"); } ShemeFlowPanel::ShemeFlowPanel(QWidget *parent) : QWidget(parent) { setStyle_(); #if 1 DataFlowModel *graphModel = new DataFlowModel(registerDataModels()); // Initialize and connect two nodes. { NodeId id1 = graphModel->addNode(FlowIndexData().type().id); graphModel->setNodeData(id1, NodeRole::Position, QPointF(0, 0)); NodeId id2 = graphModel->addNode(FlowSampleData().type().id); graphModel->setNodeData(id2, NodeRole::Position, QPointF(200, 0)); graphModel->addConnection(ConnectionId { id1, 0, id2, 0 }); NodeId id3 = graphModel->addNode(FlowPCAData().type().id); graphModel->setNodeData(id3, NodeRole::Position, QPointF(400, 0)); graphModel->addConnection(ConnectionId { id2, 0, id3, 0 }); NodeId id4 = graphModel->addNode(FlowWeightData().type().id); graphModel->setNodeData(id4, NodeRole::Position, QPointF(600, 0)); graphModel->addConnection(ConnectionId { id3, 0, id4, 0 }); NodeId id5 = graphModel->addNode(FlowResultData().type().id); graphModel->setNodeData(id5, NodeRole::Position, QPointF(0, 200)); graphModel->addConnection(ConnectionId { id4, 0, id5, 0 }); NodeId id6 = graphModel->addNode(FlowReportData().type().id); graphModel->setNodeData(id6, NodeRole::Position, QPointF(200, 200)); graphModel->addConnection(ConnectionId { id5, 0, id6, 0 }); NodeId id7 = graphModel->addNode(FlowEffiLevData().type().id); graphModel->setNodeData(id7, NodeRole::Position, QPointF(400, 200)); graphModel->addConnection(ConnectionId { id6, 0, id7, 0 }); NodeId id8 = graphModel->addNode(FlowSchemeData().type().id); graphModel->setNodeData(id8, NodeRole::Position, QPointF(600, 200)); graphModel->addConnection(ConnectionId { id7, 0, id8, 0 }); NodeId id9 = graphModel->addNode(FlowEffiData().type().id); graphModel->setNodeData(id9, NodeRole::Position, QPointF(0, 400)); graphModel->addConnection(ConnectionId { id8, 0, id9, 0 }); } auto scene = new DataFlowGraphicsScene(*graphModel); QHBoxLayout *l = new QHBoxLayout(this); GraphicsView *view = new GraphicsView(scene); l->addWidget(view); QGroupBox *groupBox = new QGroupBox("Options"); QCheckBox *cb1 = new QCheckBox("Nodes are locked"); QCheckBox *cb2 = new QCheckBox("Connections detachable"); QVBoxLayout *vbl = new QVBoxLayout; vbl->addWidget(cb1); vbl->addWidget(cb2); vbl->addStretch(); groupBox->setLayout(vbl); QObject::connect(cb1, &QCheckBox::stateChanged, [graphModel](int state) { graphModel->setNodesLocked(state == Qt::Checked); }); QObject::connect(cb2, &QCheckBox::stateChanged, [graphModel](int state) { graphModel->setDetachPossible(state == Qt::Checked); }); l->addWidget(groupBox); graphModel->setNodesLocked(true); graphModel->setDetachPossible(false); cb1->setChecked(true); cb2->setChecked(false); this->setWindowTitle("Locked Nodes and Connections"); this->resize(800, 600); #else // Initialize and connect two nodes. { NodeId id1 = graphModel.addNode(); graphModel.setNodeData(id1, NodeRole::Position, QPointF(0, 0)); NodeId id2 = graphModel.addNode(); graphModel.setNodeData(id2, NodeRole::Position, QPointF(300, 300)); graphModel.addConnection(ConnectionId { id1, 0, id2, 0 }); } auto scene = new BasicGraphicsScene(graphModel); GraphicsView *view = new GraphicsView(scene); // // Setup context menu for creating new nodes. view->setContextMenuPolicy(Qt::ActionsContextMenu); QAction *createNodeAction = new QAction(QStringLiteral("Create Node"), view); QObject::connect(createNodeAction, &QAction::triggered, [&]() { // Mouse position in scene coordinates. QPointF posView = view->mapToScene(view->mapFromGlobal(QCursor::pos())); NodeId const newId = graphModel.addNode(); graphModel.setNodeData(newId, NodeRole::Position, posView); }); view->insertAction(view->actions().front(), createNodeAction); view->setWindowTitle("Simple Node Graph"); view->resize(800, 600); QHBoxLayout *l = new QHBoxLayout(this); l->addWidget(view); #endif }