'Get the index of the previous/next category.
Args:
upwards: Get previous item, not next.
Return:
A QModelIndex.'

def _next_category_idx(self, upwards):

    idx = self.selectionModel().currentIndex()
    if (not idx.isValid()):
        return self._next_idx(upwards).sibling(0, 0)
    idx = idx.parent()
    direction = ((-1) if upwards else 1)
    while True:
        idx = idx.sibling((idx.row() + direction), 0)
        if ((not idx.isValid()) and upwards):
            return self.model().last_item().sibling(0, 0)
        elif ((not idx.isValid()) and (not upwards)):
            idx = self.model().first_item()
            self.scrollTo(idx.parent())
            return idx
        elif (idx.isValid() and idx.child(0, 0).isValid()):
            self.scrollTo(idx)
            return idx.child(0, 0)
