chengxr 1 year ago
parent
commit
c660d62420

+ 14 - 0
QFD/CCanvas/CCanvas.pri

@@ -0,0 +1,14 @@
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+    $$PWD/CMind.h \
+    $$PWD/CMindView.h \
+    $$PWD/CNode.h \
+    $$PWD/CRectItem.h
+
+SOURCES += \
+    $$PWD/CMind.cpp \
+    $$PWD/CMindView.cpp \
+    $$PWD/CNode.cpp \
+    $$PWD/CRectItem.cpp
+

+ 18 - 0
QFD/CCanvas/CMindView.cpp

@@ -0,0 +1,18 @@
+#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);
+}

+ 25 - 0
QFD/CCanvas/CMindView.h

@@ -0,0 +1,25 @@
+#ifndef CMINDVIEW_H
+#define CMINDVIEW_H
+
+#include <QGraphicsView>
+
+#include "CNode.h"
+
+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

+ 82 - 0
QFD/CCanvas/CNode.cpp

@@ -0,0 +1,82 @@
+#include "CNode.h"
+
+CNode::CNode(QObject *parent) : QObject(parent) { }
+
+const CNode *CNode::pNode() const
+{
+    return dynamic_cast<CNode *>(QObject::parent());
+}
+
+const CNode *CNode::rNode() const
+{
+    if (pNode() == nullptr) {
+        return this;
+    }
+    return pNode();
+}
+
+QList<CNode *> CNode::cNodes() const
+{
+    QList<CNode *> l;
+    for (QObject *o : children()) {
+        CNode *n = dynamic_cast<CNode *>(o);
+        if (n != nullptr) {
+            l.append(n);
+        }
+    }
+    return l;
+}
+
+int CNode::height() const
+{
+    int h = 1;
+    for (CNode *n : cNodes()) {
+        h = std::max(h, n->height() + 1);
+    }
+
+    return h;
+}
+
+int CNode::depth() const
+{
+    int d          = 1;
+    const CNode *n = this;
+
+    while (n->pNode() != nullptr) {
+        d++;
+        n = n->pNode();
+    }
+
+    return d;
+}
+
+int CNode::leafs() const
+{
+    int d = 1;
+    if (cNodes().count() > 0) {
+        d = 0;
+        for (CNode *n : cNodes()) {
+            d += n->leafs();
+        }
+    }
+
+    return d;
+}
+
+int CNode::sizeOfLevel(int lev) const
+{
+    if (lev < 1) {
+        return 0;
+    }
+
+    if (lev == 1) {
+        return 1;
+    }
+
+    int size = 0;
+    for (CNode *n : cNodes()) {
+        size += n->sizeOfLevel(lev - 1);
+    }
+
+    return size;
+}

+ 45 - 0
QFD/CCanvas/CNode.h

@@ -0,0 +1,45 @@
+#ifndef CNODE_H
+#define CNODE_H
+
+#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
+public:
+    explicit CNode(QObject *parent = nullptr);
+
+    const CNode *pNode() const;  // 父节点
+
+    const CNode *rNode() const;  // 根节点
+
+    QList<CNode *> cNodes() const;  // 孩子节点
+
+    int height() const;  // 节点的高度
+
+    int depth() const;  // 节点的深度
+
+    int leafs() const;  // 叶子节点个数或包含的路径条数
+
+    ///
+    /// \brief sizeOfLevel 以此节点为根节点的子树中,某一层的节点数
+    /// \param lev 节点层级,当前节点为1,向下递增
+    /// \return 节点数
+    ///
+    int sizeOfLevel(int lev) const;
+
+signals:
+};
+
+#endif  // CNODE_H

+ 0 - 3
QFD/CMindMap/CMapView.cpp

@@ -1,3 +0,0 @@
-#include "CMapView.h"
-
-CMapView::CMapView() { }

+ 0 - 12
QFD/CMindMap/CMapView.h

@@ -1,12 +0,0 @@
-#ifndef CMAPVIEW_H
-#define CMAPVIEW_H
-
-#include <QGraphicsView>
-
-class CMapView : public QGraphicsView
-{
-public:
-    CMapView();
-};
-
-#endif  // CMAPVIEW_H

+ 0 - 10
QFD/CMindMap/CMindMap.pri

@@ -1,10 +0,0 @@
-INCLUDEPATH += $$PWD
-
-HEADERS += \
-    $$PWD/CMapView.h \
-    $$PWD/CNode.h
-
-SOURCES += \
-    $$PWD/CMapView.cpp \
-    $$PWD/CNode.cpp
-

+ 0 - 8
QFD/CMindMap/CNode.cpp

@@ -1,8 +0,0 @@
-#include "CNode.h"
-
-CNode::CNode(QObject *parent) : QObject(parent) { }
-
-CNode::CNode(QString name, QObject *parent) : QObject(parent)
-{
-    data.name = name;
-}

+ 0 - 30
QFD/CMindMap/CNode.h

@@ -1,30 +0,0 @@
-#ifndef CNODE_H
-#define CNODE_H
-
-#include <QObject>
-
-class CNodeData
-{
-public:
-    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
-public:
-    explicit CNode(QObject *parent = nullptr);
-    explicit CNode(QString name, QObject *parent = nullptr);
-
-    CNodeData data;
-
-signals:
-};
-
-#endif  // CNODE_H

+ 1 - 1
QFD/QFD.pro

@@ -124,7 +124,7 @@ HEADERS += \
 
 
 include(./mindmap/mindmap.pri)
-include(./CMindMap/CMindMap.pri)
+include(./CCanvas/CCanvas.pri)
 include(./shemeTable/shemeTable.pri)
 include(./QtAwesome/QtAwesome.pri)
 include(./EasyQtSql/EasyQtSql.pri)