Skip to content

Commit fcc3329

Browse files
author
Sergey Agafonov
committed
Удаление пустой группы
1 parent 7e9053f commit fcc3329

4 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/groupitem.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ void GroupItem::removeNode(NodeItem *node)
191191

192192
m_nodeList.removeOne(node);
193193
updateSize();
194+
195+
if(m_nodeList.isEmpty())
196+
emit becameEmpty(this);
194197
}
195198

196199
void GroupItem::clearNodes()

src/groupitem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class GroupItem : public QGraphicsObject
4242

4343
signals:
4444
void selected(bool state);
45+
void becameEmpty(GroupItem *group);
4546

4647
public slots:
4748
bool isHovered(const QPointF &point);

src/nodeview.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ void NodeView::addGroup(GroupItem *group)
431431
group->setPos(m_scenePos);
432432
m_scene->addItem(group);
433433
m_groupList.append(group);
434+
connect(group, &GroupItem::becameEmpty, this, &NodeView::removeGroup);
434435
}
435436

436437
GroupItem *NodeView::createGroup(QList<NodeItem *> list)
@@ -458,6 +459,15 @@ GroupItem *NodeView::getItemGroup(NodeItem *node)
458459
return result;
459460
}
460461

462+
void NodeView::removeGroup(GroupItem *group)
463+
{
464+
if (!m_groupList.contains(group)) return;
465+
466+
group->clearNodes();
467+
m_groupList.removeOne(group);
468+
m_scene->removeItem(group);
469+
}
470+
461471
bool NodeView::createConnection(PortItem *portOut, PortItem *portIn)
462472
{
463473
bool result = false;

src/nodeview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public slots:
6868
void addGroup(GroupItem *group);
6969
GroupItem *createGroup(QList<NodeItem*> list);
7070
GroupItem *getItemGroup(NodeItem* node);
71+
void removeGroup(GroupItem *group);
7172

7273
bool createConnection(PortItem *portOut, PortItem *portIn);
7374
void removePortConnections(PortItem *port);

0 commit comments

Comments
 (0)