#include "SchemeFlowWidget.h" #include "shemeFlow/FlowGraphNodeWidget.h" #include "ProjectManager.h" #include #include #include #include #include #include #include using QtNodes::GraphicsView; 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(); ret->registerModel(); return ret; } 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 } } )"); } SchemeFlowWidget::SchemeFlowWidget(QWidget *parent) : QWidget(parent) { setStyle_(); initWidget(); } SchemeFlowWidget::~SchemeFlowWidget() { delete m_graphModel; } QList SchemeFlowWidget::schemes() const { QList schemes; for (int id : m_graphModel->allNodeIds()) { auto v = m_graphModel->nodeData(id, NodeRole::Widget); FlowGraphCommonNodeWidget *w = v.value(); SchemePlanManager::SchemeProcessInfo process = w->process(); schemes.append(process); } return schemes; } void SchemeFlowWidget::loadSchemes(const QList &schems) { clearAllNodes(); int y = 0; // 流程图节点位置 int space = 30; // 流程图节点间距 NodeId invalidId = 999; NodeId lastId = invalidId; for (int i = 0; i < schems.count(); i++) { SchemePlanManager::SchemeProcessInfo process = schems[i]; if (process.type == SchemePlanManager::OptimizeIndex) { continue; } NodeId id = m_graphModel->addNode(FlowCommonData().type().id); m_graphModel->setNodeData(id, NodeRole::Position, QPointF(0, y)); FlowGraphCommonNodeWidget *w = new FlowGraphCommonNodeWidget(); w->setAllowEdit(m_allowEdit); connect(w, &FlowGraphCommonNodeWidget::sigProcessEdited, this, &SchemeFlowWidget::slotSchemeProcessEdited); w->setProcess(process); if (w->isTitleHidden()) { m_graphModel->setNodeData(id, NodeRole::Caption, SchemePlanManager::processName(process)); } m_graphModel->setNodeData(id, NodeRole::Widget, QVariant::fromValue(w)); if (lastId < invalidId) { m_graphModel->addConnection(ConnectionId { lastId, 0, id, 0 }); } QSize s = m_graphModel->nodeData(id, NodeRole::Size).toSize(); y += (s.height() + space); lastId = id; } } void SchemeFlowWidget::setAllowEdit(bool allow) { m_allowEdit = allow; for (int id : m_graphModel->allNodeIds()) { FlowGraphCommonNodeWidget *w = m_graphModel->nodeData(id, NodeRole::Widget).value(); w->setAllowEdit(allow); } } void SchemeFlowWidget::initWidget() { m_graphModel = new DataFlowModel(registerDataModels()); m_graphModel->setNodesLocked(true); m_graphModel->setDetachPossible(false); auto scene = new DataFlowGraphicsScene(*m_graphModel); GraphicsView *view = new GraphicsView(scene); scene->setOrientation(Qt::Vertical); QHBoxLayout *l = new QHBoxLayout(this); l->addWidget(view); } void SchemeFlowWidget::clearAllNodes() { for (int id : m_graphModel->allNodeIds()) { m_graphModel->deleteNode(id); } } void SchemeFlowWidget::slotSchemeProcessEdited(const SchemePlanManager::SchemeProcessInfo &process) { emit sigSchemeProcessEdited(process); }