Generates a tree iterator that will traverse the items of this tree
        in either a depth-first or breadth-first fashion.
        
        :param      mode | <XTreeWidget.TraverseMode>
                    recurse | <bool>
        
        :return     <generator>

def traverseItems(self,
                      mode=TraverseMode.DepthFirst,
                      parent=None):
        """
        Generates a tree iterator that will traverse the items of this tree
        in either a depth-first or breadth-first fashion.
        
        :param      mode | <XTreeWidget.TraverseMode>
                    recurse | <bool>
        
        :return     <generator>
        """
        try:
            if parent:
                count = parent.childCount()
                func = parent.child
            else:
                count = self.topLevelItemCount()
                func = self.topLevelItem
        except RuntimeError:
            # can be raised when iterating on a deleted tree widget.
            return
        
        next = []
        for i in range(count):
            try:
                item = func(i)
            except RuntimeError:
                # can be raised when iterating on a deleted tree widget
                return
            else:
                yield item
                if mode == XTreeWidget.TraverseMode.DepthFirst:
                    for child in self.traverseItems(mode, item):
                        yield child
                else:
                    next.append(item)
        
        for item in next:
            for child in self.traverseItems(mode, item):
                yield child