chengxr 1 年之前
父节点
当前提交
7c776ad467

+ 9 - 39
QFD/CCanvas/CMindView.cpp

@@ -14,7 +14,6 @@
 CMindView::CMindView(QWidget *parent) : QGraphicsView(new QGraphicsScene(), parent)
 {
     setRenderHints(QPainter::Antialiasing);  // 抗锯齿
-    testItems();
 }
 
 CMind *CMindView::mind() const
@@ -28,49 +27,20 @@ void CMindView::setMind(CMind *mind)
     refresh();
 }
 
-void CMindView::refresh() { }
-
-void CMindView::setALignment(CMindView::Alignment align)
-{
-    m_align = align;
-}
-
-void CMindView::contextMenuEvent(QContextMenuEvent *event)
+void CMindView::refresh()
 {
-    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);
+    for (CNodeData n : m_mind->nodeList()) {
+        CNodeItem *item = new CNodeItem(n.number);
+        item->setText(n.name);
+        item->setPos(QPointF());
+        scene()->addItem(item->rectItem());
+        scene()->addItem(item->textItem());
     }
-
-    menu->exec(event->globalPos());
-
-    QGraphicsView::contextMenuEvent(event);
-}
-
-void CMindView::slotCreateRootNode()
-{
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
-
-    CNodeItem *item = new CNodeItem(0, this);
-    scene()->addItem(item->rectItem());
 }
 
-void CMindView::slotClearAllNodes()
-{
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
-}
-
-void CMindView::slotSelectAllNodes()
+void CMindView::setALignment(CMindView::Alignment align)
 {
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
+    m_align = align;
 }
 
 void CMindView::testItems()

+ 0 - 7
QFD/CCanvas/CMindView.h

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

+ 13 - 3
QFD/CCanvas/CNodeItem.cpp

@@ -7,10 +7,8 @@
 
 CNodeItem::CNodeItem(int number, QObject *parent) : QObject(parent), m_number(number)
 {
-    m_rectItem = new CRectItem(QRectF(200, 200, 100, 30));
+    m_rectItem = new CRectItem();
     m_textItem = new CTextItem(m_rectItem);
-    m_textItem->setPos(QPointF(210, 205));
-    setText("123456");
 }
 
 int CNodeItem::number() const
@@ -42,3 +40,15 @@ CTextItem *CNodeItem::textItem() const
 {
     return m_textItem;
 }
+
+QPointF CNodeItem::pos() const
+{
+    return m_pos;
+}
+
+void CNodeItem::setPos(const QPointF pos)
+{
+    m_pos = pos;
+    m_rectItem->setRect(QRectF(pos.x(), pos.y(), 100, 30));
+    m_textItem->setPos(pos + QPointF(10, 5));
+}

+ 6 - 0
QFD/CCanvas/CNodeItem.h

@@ -2,6 +2,7 @@
 #define CNODEITEM_H
 
 #include <QObject>
+#include <QPoint>
 
 class CRectItem;
 class CTextItem;
@@ -21,12 +22,17 @@ public:
     CRectItem *rectItem() const;
     CTextItem *textItem() const;
 
+    QPointF pos() const;
+    void setPos(const QPointF pos);
+
 signals:
 
 private:
     int m_number = -1;  // 对应 CNodeData.number
     CRectItem *m_rectItem;
     CTextItem *m_textItem;
+
+    QPointF m_pos;
 };
 
 #endif  // CNODEITEM_H

+ 1 - 0
QFD/CCanvas/CRectItem.cpp

@@ -17,6 +17,7 @@ QRectF CRectItem::rect() const
 void CRectItem::setRect(const QRectF &rect)
 {
     m_rect = rect;
+    updatePath();
 }
 
 int CRectItem::cornerRadius() const

+ 44 - 0
QFD/widgets/IndexSystemWidget.cpp

@@ -6,6 +6,10 @@
 #include <CMind.h>
 
 #include <QLayout>
+#include <QMenu>
+#include <QContextMenuEvent>
+
+#include <QDebug>
 
 IndexSystemWidget::IndexSystemWidget(ProjectInfo *proj, int type, QWidget *parent) : EvalWidget(proj, type, parent)
 {
@@ -25,3 +29,43 @@ void IndexSystemWidget::initLayout()
 {
     m_contentLayout->addWidget(m_mindView);
 }
+
+void IndexSystemWidget::contextMenuEvent(QContextMenuEvent *event)
+{
+    QMenu *menu = new QMenu();
+
+    QAction *selectAction = menu->addAction("全选");
+    connect(selectAction, &QAction::triggered, this, &IndexSystemWidget::slotSelectAllNodes);
+
+    QAction *clearAction = menu->addAction("清空");
+    connect(clearAction, &QAction::triggered, this, &IndexSystemWidget::slotClearAllNodes);
+
+    if (m_mindView->mind() != nullptr && m_mindView->mind()->nodeList().count() <= 0) {
+        QAction *root = menu->addAction("创建根节点");
+        connect(root, &QAction::triggered, this, &IndexSystemWidget::slotCreateRootNode);
+    }
+
+    menu->exec(event->globalPos());
+
+    QWidget::contextMenuEvent(event);
+}
+
+void IndexSystemWidget::slotSelectAllNodes()
+{
+    qDebug() << __FUNCTION__ << __LINE__ << endl;
+}
+
+void IndexSystemWidget::slotClearAllNodes()
+{
+    qDebug() << __FUNCTION__ << __LINE__ << endl;
+}
+
+void IndexSystemWidget::slotCreateRootNode()
+{
+    qDebug() << __FUNCTION__ << __LINE__ << endl;
+
+    CNodeData n = CNodeData(m_proj->id, m_type, 0);
+    n.name      = m_proj->projectName;
+    m_mindView->mind()->addNode(n);
+    m_mindView->refresh();
+}

+ 10 - 0
QFD/widgets/IndexSystemWidget.h

@@ -18,8 +18,18 @@ public:
     void initWidgets();
     void initLayout();
 
+    void contextMenuEvent(QContextMenuEvent *event) override;
+
 signals:
 
+public slots:
+
+    void slotSelectAllNodes();
+
+    void slotClearAllNodes();
+
+    void slotCreateRootNode();
+
 private:
     CMindView *m_mindView = nullptr;
 };