Fix component remove
parent
134078fc05
commit
6bab154cf5
|
@ -1534,14 +1534,15 @@ void SkeletonDocument::removeComponentRecursively(QUuid componentId)
|
|||
return;
|
||||
}
|
||||
|
||||
for (const auto &childId: component->second.childrenIds) {
|
||||
removeComponent(childId);
|
||||
}
|
||||
|
||||
if (!component->second.linkToPartId.isNull()) {
|
||||
removePartDontCareComponent(component->second.linkToPartId);
|
||||
}
|
||||
|
||||
auto childrenIds = component->second.childrenIds;
|
||||
for (const auto &childId: childrenIds) {
|
||||
removeComponentRecursively(childId);
|
||||
}
|
||||
|
||||
QUuid parentId = component->second.parentId;
|
||||
if (!parentId.isNull()) {
|
||||
auto parentComponent = componentMap.find(parentId);
|
||||
|
|
|
@ -375,6 +375,24 @@ void SkeletonPartTreeWidget::addComponentChildrenToItem(QUuid componentId, QTree
|
|||
}
|
||||
}
|
||||
|
||||
void SkeletonPartTreeWidget::deleteItemChildren(QTreeWidgetItem *item)
|
||||
{
|
||||
auto children = item->takeChildren();
|
||||
while (!children.isEmpty()) {
|
||||
auto first = children.takeFirst();
|
||||
auto componentId = QUuid(first->data(0, Qt::UserRole).toString());
|
||||
const SkeletonComponent *component = m_document->findComponent(componentId);
|
||||
if (nullptr != component) {
|
||||
m_componentItemMap.erase(componentId);
|
||||
if (!component->linkToPartId.isNull()) {
|
||||
m_partItemMap.erase(component->linkToPartId);
|
||||
}
|
||||
}
|
||||
deleteItemChildren(first);
|
||||
delete first;
|
||||
}
|
||||
}
|
||||
|
||||
void SkeletonPartTreeWidget::componentChildrenChanged(QUuid componentId)
|
||||
{
|
||||
QTreeWidgetItem *parentItem = findComponentItem(componentId);
|
||||
|
@ -382,7 +400,7 @@ void SkeletonPartTreeWidget::componentChildrenChanged(QUuid componentId)
|
|||
qDebug() << "Find component item failed:" << componentId;
|
||||
return;
|
||||
}
|
||||
qDeleteAll(parentItem->takeChildren());
|
||||
deleteItemChildren(parentItem);
|
||||
addComponentChildrenToItem(componentId, parentItem);
|
||||
|
||||
// Fix the last item show in the wrong place sometimes
|
||||
|
|
|
@ -67,6 +67,7 @@ protected:
|
|||
virtual void mousePressEvent(QMouseEvent *event);
|
||||
private:
|
||||
void addComponentChildrenToItem(QUuid componentId, QTreeWidgetItem *parentItem);
|
||||
void deleteItemChildren(QTreeWidgetItem *item);
|
||||
private:
|
||||
const SkeletonDocument *m_document = nullptr;
|
||||
std::map<QUuid, QTreeWidgetItem *> m_partItemMap;
|
||||
|
|
Loading…
Reference in New Issue