本文整理汇总了C++中ktexteditor::Document::highlightingMode方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::highlightingMode方法的具体用法?C++ Document::highlightingMode怎么用?C++ Document::highlightingMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ktexteditor::Document
的用法示例。
在下文中一共展示了Document::highlightingMode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getItemHighlightData
QVariant ClangCodeCompletionModel::getItemHighlightData(const QModelIndex& index, const int role) const
{
switch (role)
{
case KTextEditor::CodeCompletionModel::SetMatchContext:
case KTextEditor::CodeCompletionModel::MatchQuality:
return QVariant(QVariant::Invalid);
case KTextEditor::CodeCompletionModel::ScopeIndex:
return -1;
case KTextEditor::CodeCompletionModel::HighlightingMethod:
// We want custom highlighting for return value, name and params
switch (index.column())
{
case KTextEditor::CodeCompletionModel::Name:
case KTextEditor::CodeCompletionModel::Prefix:
case KTextEditor::CodeCompletionModel::Arguments:
#if 0
kDebug(DEBUG_AREA) << "OK: HighlightingMethod(" << role << ") called for" << index;
#endif
return KTextEditor::CodeCompletionModel::CustomHighlighting;
default:
#if 0
kDebug(DEBUG_AREA) << "HighlightingMethod(" << role << ") DEFAULT called for " << index;
#endif
return QVariant(QVariant::Invalid);
}
break;
case KTextEditor::CodeCompletionModel::CustomHighlight:
// Highlight completion snippet using hidden document of the plugin instance
switch (index.column())
{
case KTextEditor::CodeCompletionModel::Name:
case KTextEditor::CodeCompletionModel::Prefix:
case KTextEditor::CodeCompletionModel::Arguments:
{
#if 0
kDebug(DEBUG_AREA) << "OK: CustomHighlight(" << role << ") called for" << index;
#endif
// Request item for text to highlight
auto text = m_groups[index.internalId()]
.second.m_completions[index.row()]
.data(index, Qt::DisplayRole, m_plugin->config().usePrefixColumn())
.toString()
;
// Do not waste time if nothing to highlight
if (text.isEmpty())
return QVariant();
// Ask the last visited document about current highlighting mode
KTextEditor::Document* doc = m_current_view->document();
auto mode = doc->highlightingMode();
// Colorise a snippet
auto attrs = m_plugin->highlightSnippet(text, mode);
if (!attrs.isEmpty())
{
// Transform obtained attribute blocks into a sequence
// of variant triplets.
QList<QVariant> attributes;
for (const auto& a : attrs)
attributes
<< a.start
<< (a.start + a.length)
<< KTextEditor::Attribute(*a.attribute)
;
return attributes;
}
// NOTE Fallback to default case...
}
default:
#if 0
kDebug(DEBUG_AREA) << "CustomHighlight(" << role << ") DEFAULT called for" << index;
#endif
break; // Return nothing
}
break; // Return nothing
}
return QVariant();
}