Przeglądaj źródła

加载方案到页面;
从页面提取已编辑的方案;

chengxr 1 rok temu
rodzic
commit
3f721dd4a5

+ 14 - 14
QFD/dbService/SchemeProcessService.cpp

@@ -55,7 +55,7 @@ bool SchemeProcessService::UpdateSchemeProcess(const SchemePlanManager::SchemePr
 }
 
 bool SchemeProcessService::QueryAllByProjectIdAndIndexType(
-        QList<SchemePlanManager::SchemeProcessInfo *> *schemeProcessInfo)
+        QList<SchemePlanManager::SchemeProcessInfo> &schemeProcessInfo)
 {
     QSqlDatabase db = SqlDBHelper::getDatabase();
     QSqlQuery query(db);
@@ -66,19 +66,19 @@ bool SchemeProcessService::QueryAllByProjectIdAndIndexType(
     if (query.exec(selectSql)) {
         while (query.next()) {
             if (query.isNull(0) == false) {
-                SchemePlanManager::SchemeProcessInfo *info = new SchemePlanManager::SchemeProcessInfo();
-                info->id                                   = query.value(0).toInt();
-                info->projectId                            = query.value(1).toInt();
-                info->indexType                            = query.value(2).toInt();
-                info->step                                 = query.value(3).toInt();
-                info->type             = (SchemePlanManager::SchemeProcessType)query.value(4).toInt();
-                info->name             = query.value(5).toString();
-                info->dSource          = (SchemePlanManager::SchemeDataSource)query.value(6).toInt();
-                info->algorithm        = (SchemePlanManager::Algorithm)query.value(7).toInt();
-                info->efficiencyGrades = query.value(8).toInt();
-                info->isOptional       = query.value(9).toInt();
-                info->isChecked        = query.value(10).toInt();
-                schemeProcessInfo->append(info);
+                SchemePlanManager::SchemeProcessInfo info;
+                info.id               = query.value(0).toInt();
+                info.projectId        = query.value(1).toInt();
+                info.indexType        = query.value(2).toInt();
+                info.step             = query.value(3).toInt();
+                info.type             = (SchemePlanManager::SchemeProcessType)query.value(4).toInt();
+                info.name             = query.value(5).toString();
+                info.dSource          = (SchemePlanManager::SchemeDataSource)query.value(6).toInt();
+                info.algorithm        = (SchemePlanManager::Algorithm)query.value(7).toInt();
+                info.efficiencyGrades = query.value(8).toInt();
+                info.isOptional       = query.value(9).toInt();
+                info.isChecked        = query.value(10).toInt();
+                schemeProcessInfo.append(info);
             }
         }
         ret = true;

+ 1 - 1
QFD/dbService/SchemeProcessService.h

@@ -13,7 +13,7 @@ public:
     bool UpdateSchemeProcess(const SchemePlanManager::SchemeProcessInfo &schemeProcessInfo);
 
     //查询所有
-    bool QueryAllByProjectIdAndIndexType(QList<SchemePlanManager::SchemeProcessInfo *> *schemeProcessInfo);
+    bool QueryAllByProjectIdAndIndexType(QList<SchemePlanManager::SchemeProcessInfo> &schemeProcessInfo);
 
     //根据id删除
     bool DeleteById(int id);

+ 38 - 6
QFD/shemeFlow/FlowGraphNodeWidget.cpp

@@ -110,6 +110,11 @@ void FlowGraphCommonNodeWidget::setProcess(SchemePlanManager::SchemeProcessInfo
     loadInfo();
 }
 
+void FlowGraphCommonNodeWidget::setProcessId(int id)
+{
+    m_process.id = id;
+}
+
 bool FlowGraphCommonNodeWidget::isTitleHidden() const
 {
     QList<SchemePlanManager::Algorithm> algs        = SchemePlanManager::processOptionalAlgorithms(m_process);
@@ -153,6 +158,8 @@ void FlowGraphCommonNodeWidget::connectSignalsAndSlots()
 
 void FlowGraphCommonNodeWidget::loadInfo()
 {
+    m_isLoaded = false;
+
     QList<SchemePlanManager::Algorithm> algs        = optionalAlgs();
     QList<SchemePlanManager::SchemeDataSource> dsrc = optionaldSource();
     bool opt                                        = isOptional();
@@ -195,6 +202,8 @@ void FlowGraphCommonNodeWidget::loadInfo()
     m_spinBox->setHidden(m_process.indexType != ProjectManager::EfficiencyIndex
                          || m_process.type != SchemePlanManager::RunEvaluate);
     m_spinBox->setValue(m_process.efficiencyGrades);
+
+    m_isLoaded = true;
 }
 
 QString FlowGraphCommonNodeWidget::title() const
@@ -220,25 +229,48 @@ bool FlowGraphCommonNodeWidget::isOptional() const
 void FlowGraphCommonNodeWidget::slotAlgComboChanged(int index)
 {
     QList<SchemePlanManager::Algorithm> list = optionalAlgs();
-    m_process.algorithm                      = list.at(index);
-    emit sigProcessChanged(m_process);
+    if (m_process.algorithm == list.at(index)) {
+        return;
+    }
+    m_process.algorithm = list.at(index);
+    if (m_isLoaded) {
+        emit sigProcessChanged(m_process);
+    }
 }
 
 void FlowGraphCommonNodeWidget::slotDataComboChanged(int index)
 {
     QList<SchemePlanManager::SchemeDataSource> list = optionaldSource();
-    m_process.dSource                               = list.at(index);
-    emit sigProcessChanged(m_process);
+    if (m_process.dSource == list.at(index)) {
+        return;
+    }
+
+    m_process.dSource = list.at(index);
+    if (m_isLoaded) {
+        emit sigProcessChanged(m_process);
+    }
 }
 
 void FlowGraphCommonNodeWidget::slotSpinBoxChanged(int value)
 {
+    if (m_process.efficiencyGrades == value) {
+        return;
+    }
+
     m_process.efficiencyGrades = value;
-    emit sigProcessChanged(m_process);
+    if (m_isLoaded) {
+        emit sigProcessChanged(m_process);
+    }
 }
 
 void FlowGraphCommonNodeWidget::slotCheckBoxChanged()
 {
+    if (m_process.isChecked == m_checkBox->isChecked()) {
+        return;
+    }
+
     m_process.isChecked = m_checkBox->isChecked();
-    emit sigProcessChanged(m_process);
+    if (m_isLoaded) {
+        emit sigProcessChanged(m_process);
+    }
 }

+ 4 - 0
QFD/shemeFlow/FlowGraphNodeWidget.h

@@ -93,6 +93,8 @@ public:
 
     void setProcess(SchemePlanManager::SchemeProcessInfo &i);
 
+    void setProcessId(int id);
+
     bool isTitleHidden() const;
 
 signals:
@@ -126,6 +128,8 @@ private:
     QCheckBox *m_checkBox  = nullptr;
 
     QVBoxLayout *m_layout = nullptr;
+
+    bool m_isLoaded = false;
 };
 
 #endif  // FLOWGRAPHNODEWIDGET_H

+ 1 - 1
QFD/widgets/EvalWidget.cpp

@@ -68,7 +68,7 @@ void EvalWidget::initWidgets()
 void EvalWidget::initLayout()
 {
     m_layout    = new QVBoxLayout(this);
-    m_topLayout = new QHBoxLayout(this);
+    m_topLayout = new QHBoxLayout();
     m_layout->addLayout(m_topLayout);
     m_layout->addWidget(m_seperator);
     m_contentLayout = new QHBoxLayout();

+ 39 - 13
QFD/widgets/SchemeFlowWidget.cpp

@@ -4,6 +4,7 @@
 #include "ProjectManager.h"
 
 #include <dbService/ClassSet.h>
+#include <dbService/SchemeProcessService.h>
 
 #include <QGroupBox>
 #include <QCheckBox>
@@ -89,13 +90,10 @@ static void setStyle_()
   )");
 }
 
-SchemeFlowWidget::SchemeFlowWidget(ProjectInfo *proj, int indexType, QWidget *parent) : QWidget(parent), m_proj(proj)
+SchemeFlowWidget::SchemeFlowWidget(ProjectInfo *proj, QWidget *parent) : QWidget(parent), m_proj(proj)
 {
     setStyle_();
-
     initWidget();
-
-    setType(indexType);
 }
 
 SchemeFlowWidget::~SchemeFlowWidget()
@@ -103,23 +101,52 @@ SchemeFlowWidget::~SchemeFlowWidget()
     delete m_graphModel;
 }
 
+ProjectInfo *SchemeFlowWidget::proj() const
+{
+    return m_proj;
+}
+
 void SchemeFlowWidget::setType(int t)
 {
     m_indexType = t;
-    refresh();
+
+    QList<SchemePlanManager::SchemeProcessInfo> schemes;
+
+    bool ret = SchemeProcessService().QueryAllByProjectIdAndIndexType(schemes);
+
+    if (ret && schemes.count() <= 1) {
+        schemes = templateSchemes(m_proj->id, m_indexType);
+        emit sigSchemeProcessCreated();
+    }
+    loadSchemes(schemes);
 }
 
-QList<SchemePlanManager::SchemeProcessInfo> SchemeFlowWidget::schemeTemplate(int projId, int indexType)
+int SchemeFlowWidget::indexType() const
 {
-    /// 方案流程模板
+    return m_indexType;
+}
 
+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();
+    }
+
+    return schemes;
+}
+
+QList<SchemePlanManager::SchemeProcessInfo> SchemeFlowWidget::templateSchemes(int projId, int indexType)
+{
     QList<SchemePlanManager::SchemeProcessType> types;
     switch (indexType) {
     case ProjectManager::AbilityIndex: {
         types = { SchemePlanManager::IndexSystem,    SchemePlanManager::ImportWeightData,
                   SchemePlanManager::OptimizeIndex,  SchemePlanManager::CalculateWeight,
                   SchemePlanManager::ShowEvalResult, SchemePlanManager::GenerateReport };
-        //        types = { SchemePlanManager::IndexSystem };
         break;
     }
     case ProjectManager::TechIndex: {
@@ -177,7 +204,7 @@ void SchemeFlowWidget::clearAllNodes()
     }
 }
 
-void SchemeFlowWidget::refresh()
+void SchemeFlowWidget::loadSchemes(const QList<SchemePlanManager::SchemeProcessInfo> &schems)
 {
     clearAllNodes();
 
@@ -186,13 +213,12 @@ void SchemeFlowWidget::refresh()
     NodeId invalidId = 999;
     NodeId lastId    = invalidId;
 
-    QList<SchemePlanManager::SchemeProcessInfo> scheme = schemeTemplate(m_proj->id, m_indexType);
-    for (int i = 0; i < scheme.count(); i++) {
+    for (int i = 0; i < schems.count(); i++) {
         NodeId id = m_graphModel->addNode(FlowCommonData().type().id);
         m_graphModel->setNodeData(id, NodeRole::Position, QPointF(0, y));
         FlowGraphCommonNodeWidget *w = new FlowGraphCommonNodeWidget();
         connect(w, &FlowGraphCommonNodeWidget::sigProcessChanged, this, &SchemeFlowWidget::slotSchemeProcessEdited);
-        SchemePlanManager::SchemeProcessInfo process = scheme[i];
+        SchemePlanManager::SchemeProcessInfo process = schems[i];
         w->setProcess(process);
         if (w->isTitleHidden()) {
             m_graphModel->setNodeData(id, NodeRole::Caption, SchemePlanManager::processName(process));
@@ -211,5 +237,5 @@ void SchemeFlowWidget::refresh()
 
 void SchemeFlowWidget::slotSchemeProcessEdited(const SchemePlanManager::SchemeProcessInfo &process)
 {
-    qDebug() << __FUNCTION__ << __LINE__ << process.algorithm << endl;
+    emit sigSchemeProcessEdited(process);
 }

+ 13 - 3
QFD/widgets/SchemeFlowWidget.h

@@ -40,21 +40,31 @@ class SchemeFlowWidget : public QWidget
 {
     Q_OBJECT
 public:
-    explicit SchemeFlowWidget(ProjectInfo *proj, int indexType, QWidget *parent = nullptr);
+    explicit SchemeFlowWidget(ProjectInfo *proj, QWidget *parent = nullptr);
 
     ~SchemeFlowWidget();
 
+    ProjectInfo *proj() const;
+
     void setType(int t);
+    int indexType() const;
+
+    /// 当前页面的评估方案
+    QList<SchemePlanManager::SchemeProcessInfo> schemes() const;
 
-    QList<SchemePlanManager::SchemeProcessInfo> schemeTemplate(int projId, int indexType);
+    /// 方案流程模板
+    /// 当项目中没有评估方案时, 可加载此处的模板
+    static QList<SchemePlanManager::SchemeProcessInfo> templateSchemes(int projId, int indexType);
 signals:
+    void sigSchemeProcessCreated();
+    void sigSchemeProcessEdited(const SchemePlanManager::SchemeProcessInfo &process);
 
 private:
     void initWidget();
 
     void clearAllNodes();
 
-    void refresh();
+    void loadSchemes(const QList<SchemePlanManager::SchemeProcessInfo> &schems);
 
 private slots:
     void slotSchemeProcessEdited(const SchemePlanManager::SchemeProcessInfo &process);

+ 25 - 6
QFD/widgets/SchemePlanWidget.cpp

@@ -26,11 +26,12 @@ void SchemePlanWidget::setType(int type)
 void SchemePlanWidget::setupUI()
 {
     m_topLayout->addStretch();
-    m_save = new PushButton("保存", this);
-    m_topLayout->addWidget(m_save);
+    m_export = new PushButton("保存", this);
+    m_export->setEnabled(false);
+    m_topLayout->addWidget(m_export);
     m_topLayout->addSpacing(10);
 
-    connect(m_save, &PushButton::clicked, this, &SchemePlanWidget::slotSaveClicked);
+    connect(m_export, &PushButton::clicked, this, &SchemePlanWidget::slotExportClicked);
 }
 
 void SchemePlanWidget::setupTabWidget()
@@ -38,14 +39,32 @@ void SchemePlanWidget::setupTabWidget()
     m_tab->clear();
 
     for (int i : indexList()) {
-        SchemeFlowWidget *m         = new SchemeFlowWidget(proj(), i, this);
+        SchemeFlowWidget *m = new SchemeFlowWidget(proj(), this);
+        connect(m, &SchemeFlowWidget::sigSchemeProcessCreated, this, &SchemePlanWidget::slotSchemeCreated);
+        connect(m, &SchemeFlowWidget::sigSchemeProcessEdited, this, &SchemePlanWidget::slotSchemeProcessEdited);
+        m->setType(i);
+
         ProjectManager::IndexType t = (ProjectManager::IndexType)i;
         QString s                   = ProjectManager::nameOfIndexType(t);
         m_tab->addTab(m, s);
     }
 }
 
-void SchemePlanWidget::slotSaveClicked()
+void SchemePlanWidget::slotExportClicked()
+{
+    for (int i = 0; i < m_tab->count(); i++) {
+        SchemeFlowWidget *w                                 = (SchemeFlowWidget *)m_tab->widget(i);
+        QList<SchemePlanManager::SchemeProcessInfo> schemes = w->schemes();
+    }
+}
+
+void SchemePlanWidget::slotSchemeCreated()
+{
+    SchemeFlowWidget *w = (SchemeFlowWidget *)sender();
+    qDebug() << __FUNCTION__ << __LINE__ << w->indexType() << endl;
+}
+
+void SchemePlanWidget::slotSchemeProcessEdited(const SchemePlanManager::SchemeProcessInfo &process)
 {
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
+    qDebug() << __FUNCTION__ << __LINE__ << process.id << endl;
 }

+ 8 - 2
QFD/widgets/SchemePlanWidget.h

@@ -3,6 +3,8 @@
 
 #include "EvalWidget.h"
 
+#include "SchemePlanManager.h"
+
 class PushButton;
 
 /**
@@ -23,10 +25,14 @@ private:
     void setupTabWidget();
 
 private slots:
-    void slotSaveClicked();
+    void slotExportClicked();
+
+    void slotSchemeCreated();
+
+    void slotSchemeProcessEdited(const SchemePlanManager::SchemeProcessInfo &process);
 
 private:
-    PushButton *m_save = nullptr;
+    PushButton *m_export = nullptr;
 };
 
 #endif  // SCHEMEPLANWIDGET_H