QString ClangCodeCompletionItem::renderPrefix() const
{
    auto prefix = renderPlaceholders(m_before);
    if (prefix.isEmpty())
    {
        switch (m_kind)
        {
            case CXCursor_TypedefDecl:      prefix = QLatin1String{"typedef"};        break;
            case CXCursor_ClassDecl:        prefix = QLatin1String{"class"};          break;
            case CXCursor_ClassTemplate:    prefix = QLatin1String{"template class"}; break;
            case CXCursor_StructDecl:       prefix = QLatin1String{"struct"};         break;
            case CXCursor_EnumDecl:         prefix = QLatin1String{"enum"};           break;
            case CXCursor_Namespace:        prefix = QLatin1String{"namespace"};      break;
            case CXCursor_UnionDecl:        prefix = QLatin1String{"union"};          break;
            case CXCursor_MacroDefinition:  prefix = QLatin1String{"macro"};          break;
            default: break;
        }
    }
    return prefix;
}
/**
 * Produce a data siutable for view
 */
QVariant ClangCodeCompletionItem::data(
    const QModelIndex& index
  , const int role
  , const bool use_prefix_column
  ) const
{
    assert("Sanity check" && index.isValid());
    //
    auto result = QVariant{};
    switch (role)
    {
#if 0
        // WARNING Assigning match quality doesn't looks (literally) a good idea!
        // It's really look ugly...
        case KTextEditor::CodeCompletionModel::MatchQuality:
            result = int(100u - m_priority) * 10;
            break;
#endif
        case KTextEditor::CodeCompletionModel::IsExpandable:
            result = !m_comment.isEmpty();
            break;
        case KTextEditor::CodeCompletionModel::ExpandingWidget:
        {
            auto* label = new QLabel{m_comment};
            label->setWordWrap(true);
            label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
            label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
            label->resize(label->minimumSizeHint());
            result.setValue<QWidget*>(label);
            break;
        }
        case KTextEditor::CodeCompletionModel::CompletionRole:
            result = completionProperty();
            break;
        case Qt::DecorationRole:
            if (!use_prefix_column && index.column() == KTextEditor::CodeCompletionModel::Icon)
                result = icon();
            break;
        case Qt::DisplayRole:
            switch (index.column())
            {
                case KTextEditor::CodeCompletionModel::Prefix:
                    if (use_prefix_column)
                        result = renderPrefix();
                    break;
                case KTextEditor::CodeCompletionModel::Name:
                    if (use_prefix_column)
                        result = m_text;
                    else
                        result = QString{renderPrefix() + " " + m_text};
                    break;
                case KTextEditor::CodeCompletionModel::Postfix:
                    if (m_deprecated)
                        result = DEPRECATED_STR;
                    break;
                case KTextEditor::CodeCompletionModel::Arguments:
                    result = renderPlaceholders(m_after);
                    break;
                // NOTE This would just merge `scope` text w/ name and finally
                // everything would look ugly... Anyway we have groups to join
                // completion items by parent/scope and it looks better than this feature...
                case KTextEditor::CodeCompletionModel::Scope:
                    break;
                default:
                    break;
            }
            break;
        default:
#if 0
            kDebug(DEBUG_AREA) << "Role" << role << "requested for" << index;
#endif
            break;
    }
    return result;
}
/**
 * Produce a data siutable for view
 */
QVariant ClangCodeCompletionItem::data(
    const QModelIndex& index
  , const int role
  , const bool use_prefix_column
  ) const
{
    assert("Sanity check" && index.isValid());
    //
    auto result = QVariant{};
    switch (role)
    {
#if 0
        // WARNING Assigning match quality doesn't looks (literally) a good idea!
        // It's really look ugly...
        case KTextEditor::CodeCompletionModel::MatchQuality:
            result = int(100u - m_priority) * 10;
            break;
#endif
        case KTextEditor::CodeCompletionModel::CompletionRole:
            result = completionProperty();
            break;
        case Qt::DecorationRole:
            if (!use_prefix_column && index.column() == KTextEditor::CodeCompletionModel::Icon)
                result = icon();
            break;
        case Qt::DisplayRole:
            switch (index.column())
            {
                case KTextEditor::CodeCompletionModel::Prefix:
                    if (use_prefix_column)
                        result = renderPrefix();
                    break;
                case KTextEditor::CodeCompletionModel::Name:
                    if (use_prefix_column)
                        result = m_text;
                    else
                        result = QString(renderPrefix() + " " + m_text);
                    break;
                case KTextEditor::CodeCompletionModel::Postfix:
                    if (m_deprecated)
                        result = DEPRECATED_STR;
                    break;
                case KTextEditor::CodeCompletionModel::Arguments:
                    result = renderPlaceholders(m_after);
                    break;
                // NOTE This would just merge `scope` text w/ name and finally
                // everything would look ugly... Anyway we have groups to join
                // completion items by parent/scope and it looks better than this feature...
                case KTextEditor::CodeCompletionModel::Scope:
                    break;
                default:
                    break;
            }
            break;
        default:
#if 0
            kDebug(DEBUG_AREA) << "Role" << role << "requested for" << index;
#endif
            break;
    }
    return result;
}