Browse Source

MindView 右键菜单

chengxr 1 year ago
parent
commit
32ddc3ac1e

+ 42 - 0
QFD/CCanvas/CMindView.cpp

@@ -4,6 +4,13 @@
 #include "CLineItem.h"
 #include "CTextItem.h"
 
+#include "CMind.h"
+
+#include <QMenu>
+#include <QContextMenuEvent>
+
+#include <QDebug>
+
 CMindView::CMindView(QWidget *parent) : QGraphicsView(new QGraphicsScene(), parent)
 {
     setRenderHints(QPainter::Antialiasing);  // 抗锯齿
@@ -28,6 +35,41 @@ void CMindView::setALignment(CMindView::Alignment align)
     m_align = align;
 }
 
+void CMindView::contextMenuEvent(QContextMenuEvent *event)
+{
+    QMenu *menu = new QMenu();
+
+    QAction *selectAction = menu->addAction("全选");
+    connect(selectAction, &QAction::triggered, this, &CMindView::slotSelectAllNodes);
+
+    QAction *clearAction = menu->addAction("清空");
+    connect(clearAction, &QAction::triggered, this, &CMindView::slotClearAllNodes);
+
+    if (m_mind != nullptr && m_mind->nodeList().count() <= 0) {
+        QAction *root = menu->addAction("创建根节点");
+        connect(root, &QAction::triggered, this, &CMindView::slotCreateRootNode);
+    }
+
+    menu->exec(event->globalPos());
+
+    QGraphicsView::contextMenuEvent(event);
+}
+
+void CMindView::slotCreateRootNode()
+{
+    qDebug() << __FUNCTION__ << __LINE__ << endl;
+}
+
+void CMindView::slotClearAllNodes()
+{
+    qDebug() << __FUNCTION__ << __LINE__ << endl;
+}
+
+void CMindView::slotSelectAllNodes()
+{
+    qDebug() << __FUNCTION__ << __LINE__ << endl;
+}
+
 void CMindView::testItems()
 {
     CRectItem *r = new CRectItem(QRectF(0, 0, 100, 100));

+ 7 - 0
QFD/CCanvas/CMindView.h

@@ -24,6 +24,13 @@ public:
 
     void setALignment(Alignment align);
 
+    void contextMenuEvent(QContextMenuEvent *event) override;
+
+public slots:
+    void slotCreateRootNode();
+    void slotClearAllNodes();
+    void slotSelectAllNodes();
+
 private:
     CMind *m_mind = nullptr;
 

+ 4 - 4
QFD/view/ProjectView.cpp

@@ -82,10 +82,10 @@ void ProjectView::initWidgets()
     m_seperator->setPalette(pal);
 
     m_stack          = new QStackedWidget(this);
-    m_indexSystem    = new IndexSystemWidget(m_stack, 1);
-    m_evalScheme     = new EvalSchemeWidget(m_stack, 2);
-    m_dataCollection = new DataCollectionWidget(m_stack, 3);
-    m_dataProcessing = new DataProcessingWidget(m_stack, 4);
+    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->addWidget(m_indexSystem);
     m_stack->addWidget(m_evalScheme);

+ 2 - 1
QFD/widgets/DataCollectionWidget.cpp

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

+ 1 - 1
QFD/widgets/DataCollectionWidget.h

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

+ 2 - 1
QFD/widgets/DataProcessingWidget.cpp

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

+ 1 - 1
QFD/widgets/DataProcessingWidget.h

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

+ 1 - 1
QFD/widgets/EvalSchemeWidget.cpp

@@ -1,6 +1,6 @@
 #include "EvalSchemeWidget.h"
 
-EvalSchemeWidget::EvalSchemeWidget(QWidget *parent, int type) : EvalWidget(type, parent)
+EvalSchemeWidget::EvalSchemeWidget(ProjectInfo *proj, int type, QWidget *parent) : EvalWidget(proj, type, parent)
 {
     setTitle("评估方案规划");
 }

+ 1 - 1
QFD/widgets/EvalSchemeWidget.h

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

+ 11 - 1
QFD/widgets/EvalWidget.cpp

@@ -5,12 +5,22 @@
 
 #include <QDebug>
 
-EvalWidget::EvalWidget(int type, QWidget *parent) : QWidget(parent), m_type(type)
+EvalWidget::EvalWidget(ProjectInfo *proj, int type, QWidget *parent) : QWidget(parent), m_proj(proj), m_type(type)
 {
     initWidgets();
     initLayout();
 }
 
+ProjectInfo *EvalWidget::proj() const
+{
+    return m_proj;
+}
+
+void EvalWidget::setProject(ProjectInfo *proj)
+{
+    m_proj = proj;
+}
+
 int EvalWidget::type() const
 {
     return m_type;

+ 8 - 2
QFD/widgets/EvalWidget.h

@@ -3,6 +3,8 @@
 
 #include <QWidget>
 
+class ProjectInfo;
+
 class QVBoxLayout;
 class QLabel;
 
@@ -10,7 +12,10 @@ class EvalWidget : public QWidget
 {
     Q_OBJECT
 public:
-    explicit EvalWidget(int type, QWidget *parent = nullptr);
+    explicit EvalWidget(ProjectInfo *proj, int type, QWidget *parent = nullptr);
+
+    ProjectInfo *proj() const;
+    void setProject(ProjectInfo *proj);
 
     int type() const;
     void setType(int type);
@@ -22,7 +27,8 @@ public:
     void initLayout();
 
 protected:
-    int m_type = 0;
+    ProjectInfo *m_proj = nullptr;
+    int m_type          = 0;
 
     QVBoxLayout *m_layout        = nullptr;
     QVBoxLayout *m_contentLayout = nullptr;

+ 8 - 3
QFD/widgets/IndexSystemWidget.cpp

@@ -1,10 +1,13 @@
 #include "IndexSystemWidget.h"
 
+#include <dbService/ClassSet.h>
+
 #include <CCanvas/CMindView.h>
+#include <CMind.h>
 
 #include <QLayout>
 
-IndexSystemWidget::IndexSystemWidget(QWidget *parent, int type) : EvalWidget(type, parent)
+IndexSystemWidget::IndexSystemWidget(ProjectInfo *proj, int type, QWidget *parent) : EvalWidget(proj, type, parent)
 {
     setTitle("指标体系设计");
     initWidgets();
@@ -13,10 +16,12 @@ IndexSystemWidget::IndexSystemWidget(QWidget *parent, int type) : EvalWidget(typ
 
 void IndexSystemWidget::initWidgets()
 {
-    m_mind = new CMindView(this);
+    m_mindView  = new CMindView(this);
+    CMind *mind = new CMind(m_proj->id, m_type, m_mindView);
+    m_mindView->setMind(mind);
 }
 
 void IndexSystemWidget::initLayout()
 {
-    m_contentLayout->addWidget(m_mind);
+    m_contentLayout->addWidget(m_mindView);
 }

+ 2 - 2
QFD/widgets/IndexSystemWidget.h

@@ -13,7 +13,7 @@ class IndexSystemWidget : public EvalWidget
 {
     Q_OBJECT
 public:
-    explicit IndexSystemWidget(QWidget *parent = nullptr, int type = 0);
+    explicit IndexSystemWidget(ProjectInfo *proj, int type = 0, QWidget *parent = nullptr);
 
     void initWidgets();
     void initLayout();
@@ -21,7 +21,7 @@ public:
 signals:
 
 private:
-    CMindView *m_mind = nullptr;
+    CMindView *m_mindView = nullptr;
 };
 
 #endif  // INDEXSYSTEMWIDGET_H