Przeglądaj źródła

为需求评估创建多个指标体系

chengxr 1 rok temu
rodzic
commit
b7f6d640ba

+ 7 - 6
QFD/common/ProjectManager.cpp

@@ -39,12 +39,13 @@ QList<ProjectManager::IndexType> ProjectManager::indexListOfEvalTypes(EvalTypes
 {
     QList<IndexType> list;
 
-    if ((types & EngineerInfo::Importance) == EngineerInfo::Importance) {
-        list.append(AbilityIndex);
-        list.append(TechIndex);
-    }
-    if ((types & EngineerInfo::TechSchema) == EngineerInfo::TechSchema) {
-        list.append(OptimalIndex);
+    QMetaEnum metaEnum = QMetaEnum::fromType<IndexType>();
+
+    for (int i = 0; i < metaEnum.keyCount(); i++) {
+        IndexType t = IndexType(metaEnum.value(i));
+        if ((types & t) == t) {
+            list.append(t);
+        }
     }
 
     return list;

+ 3 - 1
QFD/common/ProjectManager.h

@@ -19,6 +19,8 @@ public:
         EfficiencyIndex = 0b1 << 3,  // 综合效能评估指标体系?
     };
 
+    Q_ENUM(IndexType)
+
     static QString nameOfIndexType(IndexType t);
 
     /// 评估方案类型
@@ -31,7 +33,7 @@ public:
         EfficiencyEval = EfficiencyIndex,           // 综合效能评估
     };
 
-    Q_ENUM(EvalType);
+    Q_ENUM(EvalType)
     Q_DECLARE_FLAGS(EvalTypes, EvalType)
 
     static QString nameOfEvalType(EvalType t);

+ 10 - 1
QFD/widgets/EvalWidget.cpp

@@ -1,7 +1,10 @@
 #include "EvalWidget.h"
 
+#include "dbService/ClassSet.h"
+
 #include <QLabel>
 #include <QLayout>
+#include <QTabWidget>
 
 #include <QDebug>
 
@@ -28,7 +31,9 @@ int EvalWidget::type() const
 
 void EvalWidget::setType(int type)
 {
-    m_type = type;
+    m_type                      = type;
+    ProjectManager::EvalTypes t = (ProjectManager::EvalTypes)type;
+    m_indexList                 = ProjectManager::indexListOfEvalTypes(t);
 }
 
 void EvalWidget::setTitle(const QString title)
@@ -49,6 +54,8 @@ void EvalWidget::initWidgets()
     pal.setColor(QPalette::Background, QColor("#aaaaaa"));
     m_seperator->setAutoFillBackground(true);
     m_seperator->setPalette(pal);
+
+    m_tab = new QTabWidget(this);
 }
 
 void EvalWidget::initLayout()
@@ -59,4 +66,6 @@ void EvalWidget::initLayout()
     m_layout->addWidget(m_title);
     m_layout->addWidget(m_seperator);
     m_layout->addLayout(m_contentLayout);
+
+    m_contentLayout->addWidget(m_tab);
 }

+ 7 - 0
QFD/widgets/EvalWidget.h

@@ -3,10 +3,13 @@
 
 #include <QWidget>
 
+#include "ProjectManager.h"
+
 class ProjectInfo;
 
 class QVBoxLayout;
 class QLabel;
+class QTabWidget;
 
 class EvalWidget : public QWidget
 {
@@ -30,6 +33,10 @@ protected:
     ProjectInfo *m_proj = nullptr;
     int m_type          = 0;  // 评估类型
 
+    QList<ProjectManager::IndexType> m_indexList;
+
+    QTabWidget *m_tab = nullptr;
+
     QVBoxLayout *m_layout        = nullptr;
     QVBoxLayout *m_contentLayout = nullptr;
 

+ 49 - 34
QFD/widgets/IndexSystemWidget.cpp

@@ -12,6 +12,7 @@
 #include <QLayout>
 #include <QMenu>
 #include <QContextMenuEvent>
+#include <QTabWidget>
 
 #include <QDebug>
 
@@ -23,40 +24,19 @@ IndexSystemWidget::IndexSystemWidget(ProjectInfo *proj, QWidget *parent) : EvalW
     connectSignalsAndSlots();
 }
 
-void IndexSystemWidget::initWidgets()
-{
-    m_mindView = new CMindView(this);
-}
-
-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);
-    connect(m_mindView, &CMindView::sigNodeChanged, this, &IndexSystemWidget::slotUpdateNode);
-}
-
 void IndexSystemWidget::setType(int type)
 {
     EvalWidget::setType(type);
-
-    QList<CNodeData> list;
-
-    bool ret = CNodeDataService().QueryAll(list, proj()->id, type);
-    if (ret) {
-        m_mindView->setNodeList(list);
-    }
+    setupTabWidget();
 }
 
 void IndexSystemWidget::contextMenuEvent(QContextMenuEvent *event)
 {
     RoundMenu *menu = new RoundMenu();
 
-    if (m_mindView->root() == nullptr) {
+    CMindView *m = (CMindView *)m_tab->currentWidget();
+
+    if (m->root() == nullptr) {
         QAction *act3 = new QAction("创建根节点");
         menu->addAction(act3);
         connect(act3, &QAction::triggered, this, &IndexSystemWidget::slotCreateRootNode);
@@ -71,31 +51,65 @@ void IndexSystemWidget::contextMenuEvent(QContextMenuEvent *event)
     QWidget::contextMenuEvent(event);
 }
 
+void IndexSystemWidget::setupTabWidget()
+{
+    m_tab->clear();
+    for (int i : m_indexList) {
+        CMindView *m                = new CMindView(this);
+        ProjectManager::IndexType t = (ProjectManager::IndexType)i;
+        QString s                   = ProjectManager::nameOfIndexType(t);
+        m_tab->addTab(m, s);
+
+        QList<CNodeData> list;
+        bool ret = CNodeDataService().QueryAll(list, proj()->id, t);
+        if (ret) {
+            m->setNodeList(list);
+        }
+
+        connect(m, &CMindView::sigAddSubNode, this, &IndexSystemWidget::slotAddSubNode);
+        connect(m->mind(), &CMind::sigRemoveNode, this, &IndexSystemWidget::slotRemoveNode);
+        connect(m, &CMindView::sigNodeChanged, this, &IndexSystemWidget::slotUpdateNode);
+    }
+}
+
+void IndexSystemWidget::initWidgets() { }
+
+void IndexSystemWidget::initLayout() { }
+
+void IndexSystemWidget::connectSignalsAndSlots()
+{
+    connect(m_tab, &QTabWidget::currentChanged, this, &IndexSystemWidget::slotTabCurrentChanged);
+}
+
 void IndexSystemWidget::addNode(CNodeData node)
 {
-    qDebug() << __FUNCTION__ << __LINE__ << node.number << endl;
-    if (m_mindView->mind()->canAddNode(node)) {
+    CMindView *m = (CMindView *)m_tab->currentWidget();
+    if (m->mind()->canAddNode(node)) {
         int id = CNodeDataService().AddCNodeData(node);
         if (id >= 0) {
             node.id = id;
-            m_mindView->addNode(node);
+            m->addNode(node);
         }
     }
 }
 
-void IndexSystemWidget::slotSelectAllNodes()
+void IndexSystemWidget::slotTabCurrentChanged(int c)
 {
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
+    Q_UNUSED(c)
 }
 
+void IndexSystemWidget::slotSelectAllNodes() { }
+
 void IndexSystemWidget::slotClearAllNodes()
 {
-    m_mindView->clear();
+    CMindView *m = (CMindView *)m_tab->currentWidget();
+    m->clear();
 }
 
 void IndexSystemWidget::slotCreateRootNode()
 {
-    CNodeData n = CNodeData(m_proj->id, m_type, 0);
+    int t       = m_indexList[m_tab->currentIndex()];
+    CNodeData n = CNodeData(m_proj->id, t, 0);
     n.name      = m_proj->projectName;
     addNode(n);
 }
@@ -105,8 +119,9 @@ void IndexSystemWidget::slotAddSubNode(int pNumber)
     if (pNumber < 0) {
         return;
     }
-    CNodeData data = m_mindView->root()->data();
-    CNodeData n    = CNodeData(data.projectId, data.indexType, m_mindView->mind()->maxNumber() + 1, pNumber);
+    CMindView *m   = (CMindView *)m_tab->currentWidget();
+    CNodeData data = m->root()->data();
+    CNodeData n    = CNodeData(data.projectId, data.indexType, m->mind()->maxNumber() + 1, pNumber);
 
     addNode(n);
 }

+ 9 - 5
QFD/widgets/IndexSystemWidget.h

@@ -17,19 +17,23 @@ class IndexSystemWidget : public EvalWidget
 public:
     explicit IndexSystemWidget(ProjectInfo *proj, QWidget *parent = nullptr);
 
-    void initWidgets();
-    void initLayout();
-    void connectSignalsAndSlots();
-
     void setType(int type) override;
 
     void contextMenuEvent(QContextMenuEvent *event) override;
 
+private:
+    void setupTabWidget();
+
+    void initWidgets();
+    void initLayout();
+    void connectSignalsAndSlots();
+
     void addNode(CNodeData node);
 
 signals:
 
 public slots:
+    void slotTabCurrentChanged(int c);
 
     void slotSelectAllNodes();
 
@@ -44,7 +48,7 @@ public slots:
     void slotRemoveNode(int id);
 
 private:
-    CMindView *m_mindView = nullptr;
+    //    CMindView *m_mindView = nullptr;
 };
 
 #endif  // INDEXSYSTEMWIDGET_H