1 Star 0 Fork 0

旷野芦苇殇/texteditor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
semantichighlighter.h 3.23 KB
一键复制 编辑 原始数据 按行查看 历史
旷野芦苇殇 提交于 2024-08-02 17:06 +08:00 . 初始化
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once
#include "texteditor_global.h"
#include "fontsettings.h"
#include <QHash>
#include <QFuture>
#include <QTextCharFormat>
#include <functional>
#include <utility>
QT_BEGIN_NAMESPACE
class QTextBlock;
QT_END_NAMESPACE
namespace TextEditor {
class SyntaxHighlighter;
class TEXTEDITOR_EXPORT HighlightingResult
{
public:
int line = 0; // 1-based
int column = 0; // 1-based
int length = 0;
TextStyles textStyles;
int kind = 0; /// The various highlighters can define their own kind of results.
bool useTextSyles = false;
bool isValid() const
{ return line != 0; }
bool isInvalid() const
{ return line == 0; }
HighlightingResult() = default;
HighlightingResult(int line, int column, int length, int kind)
: line(line), column(column), length(length), kind(kind), useTextSyles(false)
{}
HighlightingResult(int line, int column, int length, TextStyles textStyles)
: line(line), column(column), length(length), textStyles(textStyles), useTextSyles(true)
{}
bool operator==(const HighlightingResult& other) const
{
return line == other.line
&& column == other.column
&& length == other.length
&& kind == other.kind;
}
bool operator!=(const HighlightingResult& other) const { return !(*this == other); }
};
using HighlightingResults = QList<HighlightingResult>;
namespace SemanticHighlighter {
using Splitter = std::function<const QList<std::pair<HighlightingResult, QTextBlock>>
(const HighlightingResult &, const QTextBlock &)>;
// Applies the future results [from, to) and applies the extra formats
// indicated by Result::kind and kindToFormat to the correct location using
// SyntaxHighlighter::setExtraAdditionalFormats.
// It is incremental in the sense that it clears the extra additional formats
// from all lines that have no results between the (from-1).line result and
// the (to-1).line result.
// Requires that results of the Future are ordered by line.
void TEXTEDITOR_EXPORT incrementalApplyExtraAdditionalFormats(
SyntaxHighlighter *highlighter,
const QFuture<HighlightingResult> &future,
int from, int to,
const QHash<int, QTextCharFormat> &kindToFormat,
const Splitter &splitter = {});
// Clears all extra highlights and applies the extra formats
// indicated by Result::kind and kindToFormat to the correct location using
// SyntaxHighlighter::setExtraFormats. In contrast to
// incrementalApplyExtraAdditionalFormats the results do not have to be ordered by line.
void TEXTEDITOR_EXPORT setExtraAdditionalFormats(
SyntaxHighlighter *highlighter,
const HighlightingResults &results,
const QHash<int, QTextCharFormat> &kindToFormat);
// Cleans the extra additional formats after the last result of the Future
// until the end of the document.
// Requires that results of the Future are ordered by line.
void TEXTEDITOR_EXPORT clearExtraAdditionalFormatsUntilEnd(
SyntaxHighlighter *highlighter,
const QFuture<HighlightingResult> &future);
} // namespace SemanticHighlighter
} // namespace TextEditor
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fengzhu2007/texteditor.git
git@gitee.com:fengzhu2007/texteditor.git
fengzhu2007
texteditor
texteditor
main

搜索帮助