Browse Source

修复删除拥有子节点的节点时的crash;

chengxr 1 year ago
parent
commit
cd9b5a5b7f
3 changed files with 13 additions and 17 deletions
  1. 9 3
      QFD/CCanvas/CMindView.cpp
  2. 0 3
      QFD/CCanvas/CNodeItem.cpp
  3. 4 11
      QFD/widgets/IndexSystemWidget.cpp

+ 9 - 3
QFD/CCanvas/CMindView.cpp

@@ -19,6 +19,8 @@ CMindView::CMindView(QWidget *parent) : QGraphicsView(new QGraphicsScene(), pare
     m_group = new QGraphicsItemGroup();
     m_group->setFlags(QGraphicsItem::ItemIsMovable);
     m_group->setHandlesChildEvents(false);
+
+    scene()->addItem(m_group);
 }
 
 CMind *CMindView::mind() const
@@ -76,6 +78,7 @@ void CMindView::clear()
     m_mind->nodeList().clear();
     delete m_root;
     m_root = nullptr;
+
     refreshItems();
 }
 
@@ -86,8 +89,6 @@ void CMindView::refreshItems()
     }
     m_items.clear();
 
-    scene()->addItem(m_group);
-
     refreshNodeGeometry(m_root);
     collectItems(m_root);
     for (QGraphicsItem *item : m_items) {
@@ -142,7 +143,12 @@ CNodeItem *CMindView::root() const
 }
 
 void CMindView::refreshNodeGeometry(CNodeItem *node, QPointF topLeft)
-{  /// 边框
+{
+    /// 边框
+    if (node == nullptr) {
+        return;
+    }
+
     QRect borderRect = QRect(topLeft.x(), topLeft.y() + (node->treeHeight() - node->borderHeight()) / 2,
                              node->borderWidth(), node->borderHeight());
     node->rectItem()->setRect(borderRect);

+ 0 - 3
QFD/CCanvas/CNodeItem.cpp

@@ -255,18 +255,15 @@ qreal CNodeItem::maxBorderWidthOfLevel(int lev) const
 
 void CNodeItem::slotSelect()
 {
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
     m_rectItem->setHighlighted(!m_rectItem->highlighted());
 }
 
 void CNodeItem::slotSubNode()
 {
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
     emit sigAddSubItem(data().number);
 }
 
 void CNodeItem::slotRemove()
 {
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
     emit sigRemoveItem(data().number);
 }

+ 4 - 11
QFD/widgets/IndexSystemWidget.cpp

@@ -30,21 +30,16 @@ void IndexSystemWidget::initLayout()
 
 void IndexSystemWidget::contextMenuEvent(QContextMenuEvent *event)
 {
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
-
     QMenu *menu = new QMenu();
 
     if (m_mindView->root() == nullptr) {
         QAction *act3 = menu->addAction("创建根节点");
         connect(act3, &QAction::triggered, this, &IndexSystemWidget::slotCreateRootNode);
+    } else {
+        QAction *act2 = menu->addAction("清空");
+        connect(act2, &QAction::triggered, this, &IndexSystemWidget::slotClearAllNodes);
     }
 
-    QAction *act1 = menu->addAction("全选");
-    connect(act1, &QAction::triggered, this, &IndexSystemWidget::slotSelectAllNodes);
-
-    QAction *act2 = menu->addAction("清空");
-    connect(act2, &QAction::triggered, this, &IndexSystemWidget::slotClearAllNodes);
-
     menu->exec(event->globalPos());
 
     QWidget::contextMenuEvent(event);
@@ -57,13 +52,11 @@ void IndexSystemWidget::slotSelectAllNodes()
 
 void IndexSystemWidget::slotClearAllNodes()
 {
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
+    m_mindView->clear();
 }
 
 void IndexSystemWidget::slotCreateRootNode()
 {
-    qDebug() << __FUNCTION__ << __LINE__ << endl;
-
     CNodeData n = CNodeData(m_proj->id, m_type, 0);
     n.name      = m_proj->projectName;
     m_mindView->addNode(n);