+void AbstractTreeItem::removeChildLater(AbstractTreeItem *child) {
+ Q_ASSERT(child);
+ QCoreApplication::postEvent(this, new RemoveChildLaterEvent(child));
+}
+
+void AbstractTreeItem::customEvent(QEvent *event) {
+ if(event->type() != QEvent::User)
+ return;
+
+ event->accept();
+
+ RemoveChildLaterEvent *removeEvent = static_cast<RemoveChildLaterEvent *>(event);
+ int childRow = _childItems.indexOf(removeEvent->child());
+ if(childRow == -1)
+ return;
+
+ // since we are called asynchronously we have to recheck if the item in question still has no childs
+ if(removeEvent->child()->childCount())
+ return;
+
+ removeChild(childRow);
+}
+