When switching to "Sort by Type", really do sort by type

Review Request #111004 - Created June 13, 2013 and submitted

Frank Reininghaus
310705, 312014
Emmanuel looked into this issue already in https://git.reviewboard.kde.org/r/109471/, but with this patch, the issue was for some reason not fixed on my system.

But I think I have found the root cause of the bug now. When switching to "Sort by Type", KFileItemModel::onSortRoleChanged() resorts the items, but it doesn't work because the "type" role isn't known yet. It only gets added later to the model when KFileItemListView::slotSortRoleChanged() calls applyRolesToModel(), which calls

KFileItemModel::setRoles(const QSet<QByteArray>& roles)

This function does set the "type" role (via retrieveData() - note that item.isMimeTypeKnown() is true because KFileItemModelRolesUpdater has determined the mime type in the mean time), but it does not trigger a resorting.

Fixed by adding the new role in KFileItemModel::onSortRoleChanged(), *before* the resorting is triggered.
Works for me, old unit tests pass (I had to modify one of them slightly though), added a new test.
Emmanuel Pescosta
Commit Hook
Frank Reininghaus
Review request changed

Status: Closed (submitted)