diff --git a/src/parttreewidget.cpp b/src/parttreewidget.cpp index 8578cb35..8ed80acb 100644 --- a/src/parttreewidget.cpp +++ b/src/parttreewidget.cpp @@ -1035,6 +1035,32 @@ void PartTreeWidget::deleteItemChildren(QTreeWidgetItem *item) } void PartTreeWidget::componentChildrenChanged(QUuid componentId) +{ + removeComponentDelayedTimer(componentId); + + QTimer *delayedTimer = new QTimer(this); + delayedTimer->setSingleShot(true); + delayedTimer->setInterval(200); + + connect(delayedTimer, &QTimer::timeout, this, [=]() { + removeComponentDelayedTimer(componentId); + reloadComponentChildren(componentId); + }); + + m_delayedComponentTimers.insert({componentId, delayedTimer}); + delayedTimer->start(); +} + +void PartTreeWidget::removeComponentDelayedTimer(const QUuid &componentId) +{ + auto findTimer = m_delayedComponentTimers.find(componentId); + if (findTimer != m_delayedComponentTimers.end()) { + delete findTimer->second; + m_delayedComponentTimers.erase(findTimer); + } +} + +void PartTreeWidget::reloadComponentChildren(const QUuid &componentId) { QTreeWidgetItem *parentItem = findComponentItem(componentId); if (nullptr == parentItem) { diff --git a/src/parttreewidget.h b/src/parttreewidget.h index facbaf8a..bd156f42 100644 --- a/src/parttreewidget.h +++ b/src/parttreewidget.h @@ -102,6 +102,8 @@ private: bool isComponentSelected(QUuid componentId); std::vector collectSelectedComponentIds(const QPoint &pos); void handleSingleClick(const QPoint &pos); + void reloadComponentChildren(const QUuid &componentId); + void removeComponentDelayedTimer(const QUuid &componentId); private: const Document *m_document = nullptr; QTreeWidgetItem *m_rootItem = nullptr; @@ -115,6 +117,7 @@ private: QBrush m_hightlightedPartBackground; QUuid m_shiftStartComponentId; std::set m_selectedComponentIds; + std::map m_delayedComponentTimers; }; #endif