chengxr 1 year ago
parent
commit
bc158d8e9b

+ 63 - 2
QFD/CCanvas/CMind.cpp

@@ -1,6 +1,67 @@
-#include "CMind.h"
+#include "CMind.h"
 
-CMind::CMind()
+CMind::CMind(QObject *parent) : QObject(parent) { }
+
+QList<CNodeData> CMind::nodeList() const
+{
+    return m_nodeList;
+}
+
+void CMind::setNodeList(QList<CNodeData> list)
+{
+    m_nodeList = list;
+}
+
+bool CMind::containsNode(CNodeData node) const
+{
+    return containsNodeWithId(node.id);
+}
+
+bool CMind::containsNodeWithId(int id) const
+{
+    for (auto n : m_nodeList) {
+        if (n.id == id) {
+            return true;
+        }
+    }
+    return false;
+}
+
+bool CMind::containsNodeWithNumber(int num) const
+{
+    for (auto n : m_nodeList) {
+        if (n.number == num) {
+            return true;
+        }
+    }
+    return false;
+}
+
+void CMind::addNode(CNodeData node)
+{
+    m_nodeList.append(node);
+}
+
+void CMind::removeNode(CNodeData node, bool removeChildren)
+{
+    removeNodeById(node.id, removeChildren);
+}
+
+void CMind::removeNodeById(int id, bool removeChildren)
 {
+    for (auto n : m_nodeList) {
+        if (n.id == id) {
+            removeNodeByNumber(n.number, removeChildren);
+        }
+    }
+}
 
+void CMind::removeNodeByNumber(int number, bool removeChildren)
+{
+    for (int i = 0; i < m_nodeList.count(); i++) {
+        CNodeData n = m_nodeList[i];
+        if (n.number == number || (removeChildren && n.pNumber == number)) {
+            m_nodeList.removeAt(i);
+        }
+    }
 }

+ 33 - 4
QFD/CCanvas/CMind.h

@@ -1,11 +1,40 @@
-#ifndef CMIND_H
+#ifndef CMIND_H
 #define CMIND_H
 
+#include <QObject>
 
-class CMind
+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;      // 备注
+};
+
+class CMind : public QObject
+{
+    Q_OBJECT
+
 public:
-    CMind();
+    explicit CMind(QObject *parent = nullptr);
+
+    // 节点数据
+    QList<CNodeData> nodeList() const;
+    void setNodeList(QList<CNodeData> list);
+
+    bool containsNode(CNodeData node) const;
+    bool containsNodeWithId(int id) const;
+    bool containsNodeWithNumber(int num) const;
+    void addNode(CNodeData node);
+    void removeNode(CNodeData node, bool removeChildren = true);
+    void removeNodeById(int id, bool removeChildren = true);
+    void removeNodeByNumber(int number, bool removeChildren = true);
+
+private:
+    QList<CNodeData> m_nodeList;
 };
 
-#endif // CMIND_H
+#endif  // CMIND_H

+ 0 - 15
QFD/CCanvas/CMindView.cpp

@@ -1,18 +1,3 @@
 #include "CMindView.h"
 
 CMindView::CMindView(QWidget *parent) : QGraphicsView(new QGraphicsScene(), parent) { }
-
-QList<CNodeData> CMindView::nodeList() const
-{
-    return m_nodeList;
-}
-
-void CMindView::setNodeList(QList<CNodeData> list)
-{
-    m_nodeList = list;
-}
-
-void CMindView::addNode(CNodeData node)
-{
-    m_nodeList.append(node);
-}

+ 0 - 11
QFD/CCanvas/CMindView.h

@@ -9,17 +9,6 @@ class CMindView : public QGraphicsView
 {
 public:
     CMindView(QWidget *parent = nullptr);
-
-    // 节点数据
-    QList<CNodeData> nodeList() const;
-    void setNodeList(QList<CNodeData> list);
-
-    void addNode(CNodeData node);
-    void removeNode(CNodeData data, bool removeChildren = true);
-    void removeNode(int id, bool remoeChildren = true);
-
-private:
-    QList<CNodeData> m_nodeList;
 };
 
 #endif  // CMINDVIEW_H

+ 0 - 11
QFD/CCanvas/CNode.h

@@ -3,17 +3,6 @@
 
 #include <QObject>
 
-struct CNodeData
-{
-    int id        = -1;
-    int projectId = -1;
-    int evalType  = 0;
-    int number    = -1;
-    int pNumber   = -1;
-    QString name;
-    QString remark;
-};
-
 class CNode : public QObject
 {
     Q_OBJECT

+ 1 - 1
QFD/dbService/ProjectService.cpp

@@ -42,7 +42,7 @@ bool ProjectService::UpdateProjectInfo(const ProjectInfo &proInfo)
                 .set("estimate_objective", proInfo.estimateObjective)
                 .set("estimate_dept", proInfo.estimateDept)
                 .set("estimatePerson", proInfo.estimatePerson)
-                .set("estimateType", proInfo.estimateType)
+                .set("estimatedType", proInfo.estimateType)
                 .set("positionalTitles", proInfo.positionalTitles)
                 .set("updateTime", proInfo.updateTime)
                 .where("id = ?", proInfo.id);