void KFileItemListView::applyRolesToModel()
{
    if (!model()) {
        return;
    }

    Q_ASSERT(qobject_cast<KFileItemModel*>(model()));
    KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(model());

    // KFileItemModel does not distinct between "visible" and "invisible" roles.
    // Add all roles that are mandatory for having a working KFileItemListView:
    QSet<QByteArray> roles = visibleRoles().toSet();
    roles.insert("iconPixmap");
    roles.insert("iconName");
    roles.insert("text");
    roles.insert("isDir");
    roles.insert("isLink");
    if (supportsItemExpanding()) {
        roles.insert("isExpanded");
        roles.insert("isExpandable");
        roles.insert("expandedParentsCount");
    }

    // Assure that the role that is used for sorting will be determined
    roles.insert(fileItemModel->sortRole());

    fileItemModel->setRoles(roles);
    m_modelRolesUpdater->setRoles(roles);
}
bool KFileItemListWidgetInformant::itemIsLink(int index, const KItemListView* view) const
{
    Q_ASSERT(qobject_cast<KFileItemModel*>(view->model()));
    KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(view->model());

    const KFileItem item = fileItemModel->fileItem(index);
    return item.isLink();
}
void KFileItemListView::initializeItemListWidget(KItemListWidget* item)
{
    KStandardItemListView::initializeItemListWidget(item);

    // Make sure that the item has an icon.
    QHash<QByteArray, QVariant> data = item->data();
    if (!data.contains("iconName") && data["iconPixmap"].value<QPixmap>().isNull()) {
        Q_ASSERT(qobject_cast<KFileItemModel*>(model()));
        KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(model());

        const KFileItem fileItem = fileItemModel->fileItem(item->index());
        data.insert("iconName", fileItem.iconName());
        item->setData(data, QSet<QByteArray>() << "iconName");
    }
}