Browse Source

存储节点数据

chengxr 1 year ago
parent
commit
56c5fe2d2d

+ 18 - 14
QFD/CCanvas/CMind.cpp

@@ -42,7 +42,9 @@ void CMind::setNodeList(QList<CNodeData> list)
 {
     m_nodeList.clear();
     for (CNodeData n : list) {
-        addNode(n);
+        if (canAddNode(n)) {
+            addNode(n);
+        }
     }
 }
 
@@ -71,37 +73,38 @@ bool CMind::containsNode(int number) const
     return numberList().contains(number);
 }
 
-void CMind::addNode(CNodeData n)
+bool CMind::canAddNode(CNodeData n)
 {
-    // 节点无效, 不添加
+    // 节点无效, 不添加
     if (isNodeValid(n) == false) {
-        return;
+        return false;
     }
 
-    // 指明了父节点, 但父节点无效, 不添加
+    // 指明了父节点, 但父节点无效, 不添加
     if (n.hasParent() && containsNode(n.pNumber) == false) {
-        return;
+        return false;
     }
 
-    // 节点编号重复, 不添加
+    // 节点编号重复, 不添加
     if (numberList().contains(n.number)) {
-        return;
+        return false;
     }
 
+    return true;
+}
+
+void CMind::addNode(CNodeData n)
+{
+
     m_nodeList.append(n);
 }
 
 void CMind::removeNode(int number)
 {
-    // 若是根节点, 则整体删除
-    if (number == minNumber()) {
-        m_nodeList.clear();
-        return;
-    }
-
     // 删除节点
     int i = numberList().indexOf(number);
     if (i >= 0 && i < m_nodeList.count()) {
+        emit sigRemoveNode(m_nodeList[i].id);
         m_nodeList.removeAt(i);
     }
 
@@ -110,6 +113,7 @@ void CMind::removeNode(int number)
         CNodeData n = m_nodeList[i];
         if (hasAncestor(n.number, number)) {
             m_nodeList.removeAt(i);
+            emit sigRemoveNode(n.id);
         }
     }
 }

+ 4 - 0
QFD/CCanvas/CMind.h

@@ -22,6 +22,7 @@ public:
 
     bool containsNode(int number) const;
 
+    bool canAddNode(CNodeData n);
     void addNode(CNodeData n);
     void removeNode(int number);
 
@@ -36,6 +37,9 @@ public:
 
     void clear();
 
+signals:
+    void sigRemoveNode(int id);
+
 private:
     QList<int> numberList() const;  // 节点编号列表
 

+ 2 - 9
QFD/CCanvas/CMindView.cpp

@@ -25,7 +25,7 @@ CMindView::CMindView(QWidget *parent) : QGraphicsView(new QGraphicsScene(), pare
     setStyleSheet("QGraphicsView {border: 1px solid rgba(0, 0, 0, 0.073);background: rgb(244, 244, "
                   "255);}");
 
-    testData();
+    //    testData();
 }
 
 CMind *CMindView::mind() const
@@ -199,14 +199,7 @@ void CMindView::testData()
 
 void CMindView::slotAddSubNode(int pNumber)
 {
-
-    if (pNumber < 0) {
-        return;
-    }
-    CNodeData data = root()->data();
-    CNodeData n    = CNodeData(data.projectId, data.evalType, m_mind->maxNumber() + 1, pNumber);
-
-    addNode(n);
+    emit sigAddSubNode(pNumber);
 }
 
 void CMindView::slotRemoveNode(int number)

+ 5 - 0
QFD/CCanvas/CMindView.h

@@ -12,6 +12,8 @@ class CNodeItem;
 class CMindView : public QGraphicsView
 {
 
+    Q_OBJECT
+
 public:
     explicit CMindView(QWidget *parent = nullptr);
 
@@ -49,6 +51,9 @@ public slots:
 
     void slotTextChanged();  // 编辑节点
 
+signals:
+    void sigAddSubNode(int pNumber);
+
 private:
     CMind *m_mind = nullptr;
 

+ 7 - 7
QFD/CCanvas/CNode.h

@@ -5,13 +5,13 @@
 
 struct CNodeData
 {
-    int id        = -1;  // 节点 id, 对应数据库节点表中的 id, 数据库自动生成
-    int projectId = -1;  // 项目 id, 对应数据库项目表中的 id, 为脑图所属项目, 数据库自动生成
-    int evalType  = 0;   // 评估类型
-    int number    = -1;  // 节点编号, 作用域为当前脑图, 0 为根节点
-    int pNumber   = -1;  // 父节点编号
-    QString name;        // 名称
-    QString remark;      // 备注
+    int id         = -1;  // 节点 id, 对应数据库节点表中的 id, 数据库自动生成
+    int projectId  = -1;  // 项目 id, 对应数据库项目表中的 id, 为脑图所属项目, 数据库自动生成
+    int evalType   = 0;   // 评估类型
+    int number     = -1;  // 节点编号, 作用域为当前脑图, 0 为根节点
+    int pNumber    = -1;  // 父节点编号
+    QString name   = "新节点";  // 名称
+    QString remark = "";        // 备注
 
     CNodeData(int projId = -1, int evalType = 0, int number = -1, int pNumber = -1, int id = -1);
 

+ 20 - 11
QFD/view/ProjectView.cpp

@@ -47,6 +47,17 @@ ProjectInfo *ProjectView::proj() const
     return m_proj;
 }
 
+void ProjectView::showEvalWidget(int eval, int task)
+{
+    m_stack->setCurrentIndex(task);
+    EvalWidget *w = (EvalWidget *)m_stack->widget(task);
+    w->setType(eval);
+
+    ProjectManager::EvalType type = (ProjectManager::EvalType)eval;
+
+    qDebug() << __FUNCTION__ << __LINE__ << type;
+}
+
 void ProjectView::initWidgets()
 {
     m_title = new QLabel(this);
@@ -81,11 +92,12 @@ void ProjectView::initWidgets()
     m_seperator->setAutoFillBackground(true);
     m_seperator->setPalette(pal);
 
-    m_stack          = new QStackedWidget(this);
-    m_indexSystem    = new IndexSystemWidget(m_proj, 1, m_stack);
-    m_evalScheme     = new EvalSchemeWidget(m_proj, 2, m_stack);
-    m_dataCollection = new DataCollectionWidget(m_proj, 3, m_stack);
-    m_dataProcessing = new DataProcessingWidget(m_proj, 4, m_stack);
+    m_stack = new QStackedWidget(this);
+
+    m_indexSystem    = new IndexSystemWidget(m_proj, m_stack);
+    m_evalScheme     = new EvalSchemeWidget(m_proj, m_stack);
+    m_dataCollection = new DataCollectionWidget(m_proj, m_stack);
+    m_dataProcessing = new DataProcessingWidget(m_proj, m_stack);
 
     m_stack->addWidget(m_indexSystem);
     m_stack->addWidget(m_evalScheme);
@@ -134,11 +146,8 @@ void ProjectView::itemClicked(QTreeWidgetItem *item, int column)
         item->child(taskIndex)->setSelected(true);
     }
 
-    ProjectManager::EvalType type = ProjectManager::evalTypeList(*m_proj)[typeIndex];
-    QString typeName              = ProjectManager::nameOfEvalType(type);
-
-    qDebug() << __FUNCTION__ << __LINE__ << typeIndex << taskIndex << m_proj->projectName << typeName
-             << m_tree->selectedItems().first()->text(0) << endl;
+    ProjectManager::EvalType eval = ProjectManager::evalTypeList(*m_proj)[typeIndex];
+    QString typeName              = ProjectManager::nameOfEvalType(eval);
 
-    m_stack->setCurrentIndex(taskIndex);
+    showEvalWidget(eval, taskIndex);
 }

+ 2 - 0
QFD/view/ProjectView.h

@@ -31,6 +31,8 @@ public:
 
     ProjectInfo *proj() const;
 
+    void showEvalWidget(int eval, int task);
+
 signals:
     void sigClose();
 

+ 1 - 2
QFD/widgets/DataCollectionWidget.cpp

@@ -1,7 +1,6 @@
 #include "DataCollectionWidget.h"
 
-DataCollectionWidget::DataCollectionWidget(ProjectInfo *proj, int type, QWidget *parent)
-    : EvalWidget(proj, type, parent)
+DataCollectionWidget::DataCollectionWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent)
 {
     setTitle("评估数据采集");
 }

+ 1 - 1
QFD/widgets/DataCollectionWidget.h

@@ -11,7 +11,7 @@ class DataCollectionWidget : public EvalWidget
 {
     Q_OBJECT
 public:
-    explicit DataCollectionWidget(ProjectInfo *proj, int type, QWidget *parent);
+    explicit DataCollectionWidget(ProjectInfo *proj, QWidget *parent);
 
 signals:
 };

+ 1 - 2
QFD/widgets/DataProcessingWidget.cpp

@@ -1,7 +1,6 @@
 #include "DataProcessingWidget.h"
 
-DataProcessingWidget::DataProcessingWidget(ProjectInfo *proj, int type, QWidget *parent)
-    : EvalWidget(proj, type, parent)
+DataProcessingWidget::DataProcessingWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent)
 {
     setTitle("评估数据处理");
 }

+ 1 - 1
QFD/widgets/DataProcessingWidget.h

@@ -11,7 +11,7 @@ class DataProcessingWidget : public EvalWidget
 {
     Q_OBJECT
 public:
-    explicit DataProcessingWidget(ProjectInfo *proj, int type, QWidget *parent);
+    explicit DataProcessingWidget(ProjectInfo *proj, QWidget *parent);
 
 signals:
 };

+ 1 - 1
QFD/widgets/EvalSchemeWidget.cpp

@@ -57,7 +57,7 @@ QString EvalSchemeWidget::nameOfAlgorithm(EvalSchemeWidget::Algorithm a)
     }
 }
 
-EvalSchemeWidget::EvalSchemeWidget(ProjectInfo *proj, int type, QWidget *parent) : EvalWidget(proj, type, parent)
+EvalSchemeWidget::EvalSchemeWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent)
 {
     setTitle("评估方案规划");
 

+ 1 - 1
QFD/widgets/EvalSchemeWidget.h

@@ -53,7 +53,7 @@ public:
 
     static QString nameOfAlgorithm(Algorithm a);
 
-    explicit EvalSchemeWidget(ProjectInfo *proj, int type, QWidget *parent);
+    explicit EvalSchemeWidget(ProjectInfo *proj, QWidget *parent);
 
     void initWidgets();
 

+ 1 - 1
QFD/widgets/EvalWidget.cpp

@@ -5,7 +5,7 @@
 
 #include <QDebug>
 
-EvalWidget::EvalWidget(ProjectInfo *proj, int type, QWidget *parent) : QWidget(parent), m_proj(proj), m_type(type)
+EvalWidget::EvalWidget(ProjectInfo *proj, QWidget *parent) : QWidget(parent), m_proj(proj)
 {
     initWidgets();
     initLayout();

+ 2 - 2
QFD/widgets/EvalWidget.h

@@ -12,7 +12,7 @@ class EvalWidget : public QWidget
 {
     Q_OBJECT
 public:
-    explicit EvalWidget(ProjectInfo *proj, int type, QWidget *parent = nullptr);
+    explicit EvalWidget(ProjectInfo *proj, QWidget *parent = nullptr);
 
     ProjectInfo *proj() const;
     void setProject(ProjectInfo *proj);
@@ -28,7 +28,7 @@ public:
 
 protected:
     ProjectInfo *m_proj = nullptr;
-    int m_type          = 0;
+    int m_type          = 0;  // 评估类型
 
     QVBoxLayout *m_layout        = nullptr;
     QVBoxLayout *m_contentLayout = nullptr;

+ 45 - 3
QFD/widgets/IndexSystemWidget.cpp

@@ -1,9 +1,11 @@
 #include "IndexSystemWidget.h"
 
 #include <dbService/ClassSet.h>
+#include <dbService/CNodeDataService.h>
 
-#include <CCanvas/CMindView.h>
+#include <CMindView.h>
 #include <CMind.h>
+#include <CNodeItem.h>
 
 #include <Widgets/Menu.h>
 
@@ -13,11 +15,12 @@
 
 #include <QDebug>
 
-IndexSystemWidget::IndexSystemWidget(ProjectInfo *proj, int type, QWidget *parent) : EvalWidget(proj, type, parent)
+IndexSystemWidget::IndexSystemWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent)
 {
     setTitle("指标体系设计");
     initWidgets();
     initLayout();
+    connectSignalsAndSlots();
 }
 
 void IndexSystemWidget::initWidgets()
@@ -30,6 +33,12 @@ void IndexSystemWidget::initLayout()
     m_contentLayout->addWidget(m_mindView);
 }
 
+void IndexSystemWidget::connectSignalsAndSlots()
+{
+    connect(m_mindView, &CMindView::sigAddSubNode, this, &IndexSystemWidget::slotAddSubNode);
+    connect(m_mindView->mind(), &CMind::sigRemoveNode, this, &IndexSystemWidget::slotRemoveNode);
+}
+
 void IndexSystemWidget::contextMenuEvent(QContextMenuEvent *event)
 {
     RoundMenu *menu = new RoundMenu();
@@ -49,6 +58,23 @@ void IndexSystemWidget::contextMenuEvent(QContextMenuEvent *event)
     QWidget::contextMenuEvent(event);
 }
 
+void IndexSystemWidget::addNode(CNodeData node)
+{
+    qDebug() << __FUNCTION__ << __LINE__ << node.number << endl;
+    if (m_mindView->mind()->canAddNode(node)) {
+        int id = CNodeDataService().AddCNodeData(node);
+        if (id >= 0) {
+            node.id = id;
+            m_mindView->addNode(node);
+        }
+    }
+}
+
+void IndexSystemWidget::removeNode(int id)
+{
+    qDebug() << __FUNCTION__ << __LINE__ << id << endl;
+}
+
 void IndexSystemWidget::slotSelectAllNodes()
 {
     qDebug() << __FUNCTION__ << __LINE__ << endl;
@@ -63,5 +89,21 @@ void IndexSystemWidget::slotCreateRootNode()
 {
     CNodeData n = CNodeData(m_proj->id, m_type, 0);
     n.name      = m_proj->projectName;
-    m_mindView->addNode(n);
+    addNode(n);
+}
+
+void IndexSystemWidget::slotAddSubNode(int pNumber)
+{
+    if (pNumber < 0) {
+        return;
+    }
+    CNodeData data = m_mindView->root()->data();
+    CNodeData n    = CNodeData(data.projectId, data.evalType, m_mindView->mind()->maxNumber() + 1, pNumber);
+
+    addNode(n);
+}
+
+void IndexSystemWidget::slotRemoveNode(int id)
+{
+    removeNode(id);
 }

+ 12 - 1
QFD/widgets/IndexSystemWidget.h

@@ -3,6 +3,8 @@
 
 #include "EvalWidget.h"
 
+#include <CNode.h>
+
 class CMindView;
 
 /**
@@ -13,13 +15,18 @@ class IndexSystemWidget : public EvalWidget
 {
     Q_OBJECT
 public:
-    explicit IndexSystemWidget(ProjectInfo *proj, int type = 0, QWidget *parent = nullptr);
+    explicit IndexSystemWidget(ProjectInfo *proj, QWidget *parent = nullptr);
 
     void initWidgets();
     void initLayout();
+    void connectSignalsAndSlots();
 
     void contextMenuEvent(QContextMenuEvent *event) override;
 
+    void addNode(CNodeData node);
+
+    void removeNode(int id);
+
 signals:
 
 public slots:
@@ -30,6 +37,10 @@ public slots:
 
     void slotCreateRootNode();
 
+    void slotAddSubNode(int pNumber);
+
+    void slotRemoveNode(int id);
+
 private:
     CMindView *m_mindView = nullptr;
 };