I want to subclass QtCore.QSortFilterProxyModel, and I found that it has two class methods that are very similar in function.
rowCount() and hasChildren()
I can use rowCount()==0 to determine whether there are children. Why do I need a separate class method hasChildren()?
How are their roles different? Is hasChildren() necessary?
rowCount() is not similar to hasChildren() since the first indicates the number of rows and the second if there are children. As you pointed out just when you compare rowCount with zero it might seem that they are equivalent. For example, in the case that the model does not have columns(columnCount() == 0) but has rows (rowCount() > 0), then will it have children? Well no, that's why in various models the QModelIndex is verified to be valid and that the number of columns or rows is greater than zero.
So if you want to verify that a QModelIndex has children it is better to use hasChildren() as well as it is more readable.
What is the difference between rowCount() and hasChildren()?