123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- #include "SchemeFlowWidget.h"
- #include "shemeFlow/FlowGraphNodeWidget.h"
- #include "ProjectManager.h"
- #include <dbService/ClassSet.h>
- #include <dbService/SchemeProcessService.h>
- #include <QGroupBox>
- #include <QCheckBox>
- #include <QBoxLayout>
- #include <QDebug>
- #include <QtNodes/GraphicsView>
- using QtNodes::GraphicsView;
- static std::shared_ptr<NodeDelegateModelRegistry> registerDataModels()
- {
- auto ret = std::make_shared<NodeDelegateModelRegistry>();
- ret->registerModel<FlowTemplateDataModel>();
- ret->registerModel<FlowIndexDataModel>();
- ret->registerModel<FlowSampleDataModel>();
- ret->registerModel<FlowPCADataModel>();
- ret->registerModel<FlowWeightDataModel>();
- ret->registerModel<FlowResultDataModel>();
- ret->registerModel<FlowReportDataModel>();
- ret->registerModel<FlowEffiLevDataModel>();
- ret->registerModel<FlowSchemeDataModel>();
- ret->registerModel<FlowEffiDataModel>();
- ret->registerModel<FlowCommonDataModel>();
- 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<SchemePlanManager::SchemeProcessInfo> SchemeFlowWidget::schemes() const
- {
- QList<SchemePlanManager::SchemeProcessInfo> schemes;
- for (int id : m_graphModel->allNodeIds()) {
- auto v = m_graphModel->nodeData(id, NodeRole::Widget);
- FlowGraphCommonNodeWidget *w = v.value<FlowGraphCommonNodeWidget *>();
- SchemePlanManager::SchemeProcessInfo process = w->process();
- schemes.append(process);
- }
- return schemes;
- }
- void SchemeFlowWidget::loadSchemes(const QList<SchemePlanManager::SchemeProcessInfo> &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<FlowGraphCommonNodeWidget *>();
- 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);
- }
|