def METHOD_NAME(self, item=None):
    """Removes all selected items from the specified item or the root item."""
    if item is None:
        item = self.invisibleRootItem()
    itemsToRemove = []
    for i in range(item.childCount()):
        child = item.child(i)
        if child.isSelected():
            itemsToRemove.append(child)
        else:
            self.METHOD_NAME(child)
    for child in itemsToRemove:
        for descendant in self.items(child):
            self._cleanup(descendant)
        item.removeChild(child)
        self._cleanup(child)