'Return all items with a level <= `maxlevel`'

def get_items(self, maxlevel):

    itemlist = []
    def add_to_itemlist(item, maxlevel, level=1):
        level += 1
        for index in range(item.childCount()):
            citem = item.child(index)
            itemlist.append(citem)
            if (level <= maxlevel):
                add_to_itemlist(citem, maxlevel, level)
    for tlitem in self.get_top_level_items():
        itemlist.append(tlitem)
        if (maxlevel > 0):
            add_to_itemlist(tlitem, maxlevel=maxlevel)
    return itemlist
