| 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 | |
| 27 | namespace Utils { |
| 28 | |
| 29 | class TextBlockUserData; |
| 30 | |
| 31 | class TextDocument |
| 32 | { |
| 33 | public: |
| 34 | TextDocument() = default; |
| 35 | explicit TextDocument(const QString &text); |
| 36 | |
| 37 | TextBlock findBlockByNumber(int blockNumber) const; |
| 38 | TextBlock findBlockByLineNumber(int lineNumber) const; |
| 39 | QChar characterAt(int pos) const; |
| 40 | int characterCount() const; |
| 41 | TextBlock begin() const; |
| 42 | TextBlock firstBlock() const; |
| 43 | TextBlock lastBlock() const; |
| 44 | |
| 45 | std::optional<int> version() const; |
| 46 | void setVersion(std::optional<int>); |
| 47 | |
| 48 | QString toPlainText() const; |
| 49 | void setPlainText(const QString &text); |
| 50 | |
| 51 | bool isModified() const; |
| 52 | void setModified(bool modified); |
| 53 | |
| 54 | void setUndoRedoEnabled(bool enable); |
| 55 | |
| 56 | void clear(); |
| 57 | |
| 58 | void setUserState(int blockNumber, int state); |
| 59 | int userState(int blockNumber) const; |
| 60 | QMutex *mutex() const; |
| 61 | |
| 62 | private: |
| 63 | struct Block |
| 64 | { |
| 65 | TextBlock textBlock; |
| 66 | int userState = -1; |
| 67 | }; |
| 68 | |
| 69 | QVector<Block> m_blocks; |
| 70 | |
| 71 | QString m_content; |
| 72 | bool m_modified = false; |
| 73 | std::optional<int> m_version; |
| 74 | mutable QMutex m_mutex; |
| 75 | }; |
| 76 | } // namespace Utils |
| 77 | |
| 78 | #endif // TEXTDOCUMENT_P_H |
| 79 | |