Optimize parts tree
Delay a little bit to reload the children of component to avoid the UI freeze issue.master
parent
8db7266158
commit
58e01ca349
|
@ -1035,6 +1035,32 @@ void PartTreeWidget::deleteItemChildren(QTreeWidgetItem *item)
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartTreeWidget::componentChildrenChanged(QUuid componentId)
|
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);
|
QTreeWidgetItem *parentItem = findComponentItem(componentId);
|
||||||
if (nullptr == parentItem) {
|
if (nullptr == parentItem) {
|
||||||
|
|
|
@ -102,6 +102,8 @@ private:
|
||||||
bool isComponentSelected(QUuid componentId);
|
bool isComponentSelected(QUuid componentId);
|
||||||
std::vector<QUuid> collectSelectedComponentIds(const QPoint &pos);
|
std::vector<QUuid> collectSelectedComponentIds(const QPoint &pos);
|
||||||
void handleSingleClick(const QPoint &pos);
|
void handleSingleClick(const QPoint &pos);
|
||||||
|
void reloadComponentChildren(const QUuid &componentId);
|
||||||
|
void removeComponentDelayedTimer(const QUuid &componentId);
|
||||||
private:
|
private:
|
||||||
const Document *m_document = nullptr;
|
const Document *m_document = nullptr;
|
||||||
QTreeWidgetItem *m_rootItem = nullptr;
|
QTreeWidgetItem *m_rootItem = nullptr;
|
||||||
|
@ -115,6 +117,7 @@ private:
|
||||||
QBrush m_hightlightedPartBackground;
|
QBrush m_hightlightedPartBackground;
|
||||||
QUuid m_shiftStartComponentId;
|
QUuid m_shiftStartComponentId;
|
||||||
std::set<QUuid> m_selectedComponentIds;
|
std::set<QUuid> m_selectedComponentIds;
|
||||||
|
std::map<QUuid, QTimer *> m_delayedComponentTimers;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue