1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QTEXTDOCUMENT_P_H
5#define QTEXTDOCUMENT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qtextblock_p.h"
19
20#include <QtCore/qchar.h>
21#include <QtCore/qvector.h>
22#include <QtCore/qscopedpointer.h>
23#include <QtCore/qmutex.h>
24
25#include <optional>
26
27QT_BEGIN_NAMESPACE
28
29namespace Utils {
30
31class TextBlockUserData;
32
33class TextDocument
34{
35public:
36 TextDocument() = default;
37 explicit TextDocument(const QString &text);
38
39 TextBlock findBlockByNumber(int blockNumber) const;
40 TextBlock findBlockByLineNumber(int lineNumber) const;
41 QChar characterAt(int pos) const;
42 int characterCount() const;
43 TextBlock begin() const;
44 TextBlock firstBlock() const;
45 TextBlock lastBlock() const;
46
47 std::optional<int> version() const;
48 void setVersion(std::optional<int>);
49
50 QString toPlainText() const;
51 void setPlainText(const QString &text);
52
53 bool isModified() const;
54 void setModified(bool modified);
55
56 void setUndoRedoEnabled(bool enable);
57
58 void clear();
59
60 void setUserState(int blockNumber, int state);
61 int userState(int blockNumber) const;
62 QMutex *mutex() const;
63
64private:
65 struct Block
66 {
67 TextBlock textBlock;
68 int userState = -1;
69 };
70
71 QVector<Block> m_blocks;
72
73 QString m_content;
74 bool m_modified = false;
75 std::optional<int> m_version;
76 mutable QMutex m_mutex;
77};
78} // namespace Utils
79
80QT_END_NAMESPACE
81
82#endif // TEXTDOCUMENT_P_H
83

source code of qtdeclarative/src/qmlls/qtextdocument_p.h