Browse Source

评估方案规划

chengxr 1 year ago
parent
commit
8f096869d2

+ 2 - 2
QFD/main.cpp

@@ -30,8 +30,8 @@ int main(int argc, char *argv[])
     m.show();
     qDebug() << QSqlDatabase::drivers();
 
-    ShemeFlowPanel s;
-    s.show();
+    //    ShemeFlowPanel s;
+    //    s.show();
 
     return a.exec();
 }

+ 30 - 5
QFD/shemeFlow/FlowGraphNodeWidget.cpp

@@ -4,10 +4,11 @@
 #include <QLabel>
 #include <QCheckBox>
 #include <QComboBox>
+#include <QSpinBox>
 
 FlowGraphNodeWidget::FlowGraphNodeWidget(NodeWidgetType type, QWidget *parent) : QWidget(parent), m_type(type)
 {
-    setFixedSize(QSize(100, 40));
+    setFixedSize(QSize(130, 40));
 }
 
 FlowGraphNodeWidget::NodeWidgetType FlowGraphNodeWidget::type() const
@@ -25,6 +26,11 @@ FlowGraphPlainNodeWidget::FlowGraphPlainNodeWidget(QWidget *parent) : FlowGraphN
     l->addWidget(m_label);
 }
 
+void FlowGraphPlainNodeWidget::setText(const QString text)
+{
+    m_label->setText(text);
+}
+
 FlowGraphCheckNodeWidget::FlowGraphCheckNodeWidget(QWidget *parent) : FlowGraphNodeWidget(CheckBox, parent)
 {
     m_checkBox = new QCheckBox("执行", this);
@@ -37,11 +43,30 @@ FlowGraphCheckNodeWidget::FlowGraphCheckNodeWidget(QWidget *parent) : FlowGraphN
 FlowGraphComboNodeWidget::FlowGraphComboNodeWidget(QWidget *parent) : FlowGraphNodeWidget(ComboBox, parent)
 {
     m_combo = new QComboBox(this);
-    m_combo->addItem("算法一");
-    m_combo->addItem("算法二");
-    m_combo->addItem("算法三");
-    m_combo->addItem("算法四");
 
     QBoxLayout *l = new QVBoxLayout(this);
     l->addWidget(m_combo);
 }
+
+QList<QString> FlowGraphComboNodeWidget::items() const
+{
+    return m_items;
+}
+
+void FlowGraphComboNodeWidget::setItems(QList<QString> items)
+{
+    m_items = items;
+    m_combo->clear();
+    m_combo->addItems(items);
+}
+
+FlowGraphSpinNodeWidget::FlowGraphSpinNodeWidget(QWidget *parent) : FlowGraphNodeWidget(SpinBox, parent)
+{
+    m_spinBox = new QSpinBox(this);
+    m_spinBox->setMinimum(1);
+    m_spinBox->setMaximum(10);
+    m_spinBox->setValue(3);
+
+    QBoxLayout *l = new QVBoxLayout(this);
+    l->addWidget(m_spinBox);
+}

+ 19 - 1
QFD/shemeFlow/FlowGraphNodeWidget.h

@@ -6,6 +6,7 @@
 class QLabel;
 class QCheckBox;
 class QComboBox;
+class QSpinBox;
 
 class FlowGraphNodeWidget : public QWidget
 {
@@ -17,7 +18,7 @@ public:
         Plain,
         CheckBox,
         ComboBox,
-        DoubleComboBox,
+        SpinBox,
     };
 
     explicit FlowGraphNodeWidget(NodeWidgetType type, QWidget *parent = nullptr);
@@ -36,6 +37,8 @@ class FlowGraphPlainNodeWidget : public FlowGraphNodeWidget
 public:
     explicit FlowGraphPlainNodeWidget(QWidget *parent = nullptr);
 
+    void setText(const QString text);
+
 private:
     QLabel *m_label = nullptr;
 };
@@ -56,8 +59,23 @@ class FlowGraphComboNodeWidget : public FlowGraphNodeWidget
 public:
     explicit FlowGraphComboNodeWidget(QWidget *parent = nullptr);
 
+    QList<QString> items() const;
+    void setItems(QList<QString> items);
+
 private:
     QComboBox *m_combo = nullptr;
+
+    QList<QString> m_items;
+};
+
+class FlowGraphSpinNodeWidget : public FlowGraphNodeWidget
+{
+    Q_OBJECT
+public:
+    explicit FlowGraphSpinNodeWidget(QWidget *parent = nullptr);
+
+private:
+    QSpinBox *m_spinBox = nullptr;
 };
 
 #endif  // FLOWGRAPHNODEWIDGET_H

+ 20 - 7
QFD/shemeFlow/FlowTemplateDataModel.cpp

@@ -13,12 +13,16 @@ FlowIndexDataModel::FlowIndexDataModel() : NodeDelegateModel() { }
 
 QWidget *FlowIndexDataModel::embeddedWidget()
 {
-    return new FlowGraphPlainNodeWidget();
+    FlowGraphPlainNodeWidget *w = new FlowGraphPlainNodeWidget();
+    w->setText("构建指标体系");
+    return w;
 }
 
 QWidget *FlowSampleDataModel::embeddedWidget()
 {
-    return new FlowGraphComboNodeWidget();
+    FlowGraphComboNodeWidget *w = new FlowGraphComboNodeWidget();
+    w->setItems({ "专家打分", "导入数据" });
+    return w;
 }
 
 QWidget *FlowPCADataModel::embeddedWidget()
@@ -28,12 +32,16 @@ QWidget *FlowPCADataModel::embeddedWidget()
 
 QWidget *FlowWeightDataModel::embeddedWidget()
 {
-    return new FlowGraphComboNodeWidget();
+    FlowGraphComboNodeWidget *w = new FlowGraphComboNodeWidget();
+    w->setItems({ "熵值法", "层次分析法" });
+    return w;
 }
 
 QWidget *FlowResultDataModel::embeddedWidget()
 {
-    return nullptr;
+    FlowGraphPlainNodeWidget *w = new FlowGraphPlainNodeWidget();
+    w->setText("结果显示");
+    return w;
 }
 
 QWidget *FlowReportDataModel::embeddedWidget()
@@ -43,15 +51,20 @@ QWidget *FlowReportDataModel::embeddedWidget()
 
 QWidget *FlowEffiLevDataModel::embeddedWidget()
 {
-    return new FlowGraphComboNodeWidget();
+    FlowGraphSpinNodeWidget *w = new FlowGraphSpinNodeWidget();
+    return w;
 }
 
 QWidget *FlowSchemeDataModel::embeddedWidget()
 {
-    return new FlowGraphComboNodeWidget();
+    FlowGraphComboNodeWidget *w = new FlowGraphComboNodeWidget();
+    w->setItems({ "层次加权法", "集对分析法" });
+    return w;
 }
 
 QWidget *FlowEffiDataModel::embeddedWidget()
 {
-    return new FlowGraphComboNodeWidget();
+    FlowGraphComboNodeWidget *w = new FlowGraphComboNodeWidget();
+    w->setItems({ "物元分析法", "灰色聚类评估法" });
+    return w;
 }

+ 4 - 0
QFD/shemeFlow/FlowTemplateDataModel.h

@@ -77,6 +77,8 @@ public:
 
     QString caption() const override { return QString("构建指标体系"); }
 
+    bool captionVisible() const override { return false; }
+
     bool portCaptionVisible(PortType, PortIndex) const override { return false; }
 
     QString portCaption(PortType pt, PortIndex) const override
@@ -347,6 +349,8 @@ public:
 
     QString caption() const override { return QString("结果展示"); }
 
+    bool captionVisible() const override { return false; }
+
     bool portCaptionVisible(PortType, PortIndex) const override { return false; }
 
     QString portCaption(PortType pt, PortIndex) const override

+ 10 - 0
QFD/shemeFlow/ShemeFlowPanel.cpp

@@ -36,6 +36,8 @@ static std::shared_ptr<NodeDelegateModelRegistry> registerDataModels()
     ret->registerModel<FlowResultDataModel>();
     ret->registerModel<FlowReportDataModel>();
     ret->registerModel<FlowEffiLevDataModel>();
+    ret->registerModel<FlowSchemeDataModel>();
+    ret->registerModel<FlowEffiDataModel>();
 
     return ret;
 }
@@ -130,6 +132,14 @@ ShemeFlowPanel::ShemeFlowPanel(QWidget *parent) : QWidget(parent)
         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);

+ 2 - 9
QFD/widgets/SchemeDesignWidget.cpp

@@ -17,9 +17,7 @@ SchemeDesignWidget::SchemeDesignWidget(ProjectInfo *proj, QWidget *parent) : Eva
 void SchemeDesignWidget::setType(int type)
 {
     EvalWidget::setType(type);
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
     setupTabWidget();
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
 }
 
 void SchemeDesignWidget::setupTabWidget()
@@ -27,14 +25,9 @@ void SchemeDesignWidget::setupTabWidget()
     m_tab->clear();
 
     for (int i : indexList()) {
-        qDebug() << __FUNCTION__ << __LINE__ << endl;
-        SchemeFlowWidget *m = new SchemeFlowWidget(proj(), i, this);
-        qDebug() << __FUNCTION__ << __LINE__ << endl;
+        SchemeFlowWidget *m         = new SchemeFlowWidget(proj(), i, this);
         ProjectManager::IndexType t = (ProjectManager::IndexType)i;
-        qDebug() << __FUNCTION__ << __LINE__ << endl;
-        QString s = ProjectManager::nameOfIndexType(t);
-        qDebug() << __FUNCTION__ << __LINE__ << endl;
+        QString s                   = ProjectManager::nameOfIndexType(t);
         m_tab->addTab(m, s);
-        qDebug() << __FUNCTION__ << __LINE__ << endl;
     }
 }

+ 98 - 36
QFD/widgets/SchemeFlowWidget.cpp

@@ -1,5 +1,7 @@
 #include "SchemeFlowWidget.h"
 
+#include "ProjectManager.h"
+
 #include <dbService/ClassSet.h>
 
 #include <QGroupBox>
@@ -16,7 +18,16 @@ 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>();
 
     return ret;
 }
@@ -76,11 +87,13 @@ static void setStyle_()
   )");
 }
 
-SchemeFlowWidget::SchemeFlowWidget(ProjectInfo *proj, int indexType, QWidget *parent) : QWidget(parent)
+SchemeFlowWidget::SchemeFlowWidget(ProjectInfo *proj, int indexType, QWidget *parent) : QWidget(parent), m_proj(proj)
 {
     setStyle_();
-    initWidgets();
-    initLayout();
+
+    initWidget();
+
+    setType(indexType);
 }
 
 SchemeFlowWidget::~SchemeFlowWidget()
@@ -88,57 +101,106 @@ SchemeFlowWidget::~SchemeFlowWidget()
     delete graphModel;
 }
 
-void SchemeFlowWidget::initWidgets()
+void SchemeFlowWidget::setType(int t)
 {
+    m_indexType = t;
+    refresh();
+}
 
+void SchemeFlowWidget::initWidget()
+{
     graphModel = new DataFlowModel(registerDataModels());
+    graphModel->setNodesLocked(true);
+    graphModel->setDetachPossible(false);
 
-    // Initialize and connect two nodes.
-    {
-        NodeId id1 = graphModel->addNode(FlowIndexData().type().id);
-        graphModel->setNodeData(id1, NodeRole::Position, QPointF(0, 0));
+    auto scene         = new DataFlowGraphicsScene(*graphModel);
+    GraphicsView *view = new GraphicsView(scene);
+
+    QHBoxLayout *l = new QHBoxLayout(this);
+    l->addWidget(view);
+}
 
-        NodeId id2 = graphModel->addNode(FlowIndexData().type().id);
-        graphModel->setNodeData(id2, NodeRole::Position, QPointF(200, 0));
+void SchemeFlowWidget::clearAllNodes()
+{
+    for (int id : graphModel->allNodeIds()) {
+        graphModel->deleteNode(id);
+    }
+}
 
-        graphModel->addConnection(ConnectionId { id1, 0, id2, 0 });
+void SchemeFlowWidget::refresh()
+{
+    clearAllNodes();
 
-        NodeId id3 = graphModel->addNode(FlowIndexData().type().id);
-        graphModel->setNodeData(id3, NodeRole::Position, QPointF(400, 0));
+    qreal h = 240;
 
+    switch (m_indexType) {
+    case ProjectManager::AbilityIndex:
+    case ProjectManager::TechIndex: {
+        NodeId id1 = graphModel->addNode(FlowIndexData().type().id);
+        graphModel->setNodeData(id1, NodeRole::Position, QPointF(h * 0, 0));
+
+        NodeId id2 = graphModel->addNode(FlowSampleData().type().id);
+        graphModel->setNodeData(id2, NodeRole::Position, QPointF(h * 1, 0));
+        graphModel->addConnection(ConnectionId { id1, 0, id2, 0 });
+
+        NodeId id3 = graphModel->addNode(FlowPCAData().type().id);
+        graphModel->setNodeData(id3, NodeRole::Position, QPointF(h * 2, 0));
         graphModel->addConnection(ConnectionId { id2, 0, id3, 0 });
-    }
 
-    auto scene = new DataFlowGraphicsScene(*graphModel);
+        NodeId id4 = graphModel->addNode(FlowWeightData().type().id);
+        graphModel->setNodeData(id4, NodeRole::Position, QPointF(h * 0, 200));
+        graphModel->addConnection(ConnectionId { id3, 0, id4, 0 });
 
-    QHBoxLayout *l = new QHBoxLayout(this);
+        NodeId id5 = graphModel->addNode(FlowResultData().type().id);
+        graphModel->setNodeData(id5, NodeRole::Position, QPointF(h * 1, 200));
+        graphModel->addConnection(ConnectionId { id4, 0, id5, 0 });
 
-    GraphicsView *view = new GraphicsView(scene);
+        NodeId id6 = graphModel->addNode(FlowReportData().type().id);
+        graphModel->setNodeData(id6, NodeRole::Position, QPointF(h * 2, 200));
+        graphModel->addConnection(ConnectionId { id5, 0, id6, 0 });
+        break;
+    }
+    case ProjectManager::OptimalIndex: {
+        NodeId id1 = graphModel->addNode(FlowIndexData().type().id);
+        graphModel->setNodeData(id1, NodeRole::Position, QPointF(h * 0, 0));
 
-    l->addWidget(view);
+        NodeId id2 = graphModel->addNode(FlowSampleData().type().id);
+        graphModel->setNodeData(id2, NodeRole::Position, QPointF(h * 1, 0));
+        graphModel->addConnection(ConnectionId { id1, 0, id2, 0 });
 
-    QGroupBox *groupBox = new QGroupBox("Options");
+        NodeId id8 = graphModel->addNode(FlowSchemeData().type().id);
+        graphModel->setNodeData(id8, NodeRole::Position, QPointF(h * 2, 0));
+        graphModel->addConnection(ConnectionId { id2, 0, id8, 0 });
 
-    QCheckBox *cb1 = new QCheckBox("Nodes are locked");
-    QCheckBox *cb2 = new QCheckBox("Connections detachable");
-    cb2->setChecked(true);
+        NodeId id5 = graphModel->addNode(FlowResultData().type().id);
+        graphModel->setNodeData(id5, NodeRole::Position, QPointF(h * 0, 200));
+        graphModel->addConnection(ConnectionId { id8, 0, id5, 0 });
 
-    QVBoxLayout *vbl = new QVBoxLayout;
-    vbl->addWidget(cb1);
-    vbl->addWidget(cb2);
-    vbl->addStretch();
-    groupBox->setLayout(vbl);
+        NodeId id6 = graphModel->addNode(FlowReportData().type().id);
+        graphModel->setNodeData(id6, NodeRole::Position, QPointF(h * 1, 200));
+        graphModel->addConnection(ConnectionId { id5, 0, id6, 0 });
+        break;
+    }
+    case ProjectManager::EfficiencyIndex: {
+        NodeId id1 = graphModel->addNode(FlowIndexData().type().id);
+        graphModel->setNodeData(id1, NodeRole::Position, QPointF(h * 0, 0));
 
-    QObject::connect(cb1, &QCheckBox::stateChanged,
-                     [this](int state) { graphModel->setNodesLocked(state == Qt::Checked); });
+        NodeId id7 = graphModel->addNode(FlowEffiLevData().type().id);
+        graphModel->setNodeData(id7, NodeRole::Position, QPointF(h * 1, 0));
+        graphModel->addConnection(ConnectionId { id1, 0, id7, 0 });
 
-    QObject::connect(cb2, &QCheckBox::stateChanged,
-                     [this](int state) { graphModel->setDetachPossible(state == Qt::Checked); });
+        NodeId id9 = graphModel->addNode(FlowEffiData().type().id);
+        graphModel->setNodeData(id9, NodeRole::Position, QPointF(h * 2, 0));
+        graphModel->addConnection(ConnectionId { id7, 0, id9, 0 });
 
-    l->addWidget(groupBox);
+        NodeId id5 = graphModel->addNode(FlowResultData().type().id);
+        graphModel->setNodeData(id5, NodeRole::Position, QPointF(h * 0, 200));
+        graphModel->addConnection(ConnectionId { id9, 0, id5, 0 });
 
-    this->setWindowTitle("Locked Nodes and Connections");
-    this->resize(800, 600);
+        NodeId id6 = graphModel->addNode(FlowReportData().type().id);
+        graphModel->setNodeData(id6, NodeRole::Position, QPointF(h * 1, 200));
+        graphModel->addConnection(ConnectionId { id5, 0, id6, 0 });
+        break;
+    }
+    }
 }
-
-void SchemeFlowWidget::initLayout() { }

+ 8 - 3
QFD/widgets/SchemeFlowWidget.h

@@ -38,12 +38,17 @@ public:
 
     ~SchemeFlowWidget();
 
-    void initWidgets();
-
-    void initLayout();
+    void setType(int t);
 
 signals:
 
+private:
+    void initWidget();
+
+    void clearAllNodes();
+
+    void refresh();
+
 private:
     ProjectInfo *m_proj = nullptr;
     int m_indexType     = 0;