def METHOD_NAME(self, parent=QModelIndex()):
    """Override QAbstractItemModel::rowCount."""
    if not parent.isValid():
        # top-level
        return len(self._categories)
    cat = self._cat_from_idx(parent)
    if not cat or parent.column() != 0:
        # item or nonzero category column (only first col has children)
        return 0
    else:
        # category
        return cat.METHOD_NAME()