| 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 | #include "qtextblock_p.h" |
| 5 | #include "qtextdocument_p.h" |
| 6 | |
| 7 | #include <QtCore/qstring.h> |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | namespace Utils { |
| 12 | |
| 13 | bool TextBlock::isValid() const |
| 14 | { |
| 15 | return m_document; |
| 16 | } |
| 17 | |
| 18 | void TextBlock::setBlockNumber(int blockNumber) |
| 19 | { |
| 20 | m_blockNumber = blockNumber; |
| 21 | } |
| 22 | |
| 23 | int TextBlock::blockNumber() const |
| 24 | { |
| 25 | return m_blockNumber; |
| 26 | } |
| 27 | |
| 28 | void TextBlock::setPosition(int position) |
| 29 | { |
| 30 | m_position = position; |
| 31 | } |
| 32 | |
| 33 | int TextBlock::position() const |
| 34 | { |
| 35 | return m_position; |
| 36 | } |
| 37 | |
| 38 | void TextBlock::setLength(int length) |
| 39 | { |
| 40 | m_length = length; |
| 41 | } |
| 42 | |
| 43 | int TextBlock::length() const |
| 44 | { |
| 45 | return m_length; |
| 46 | } |
| 47 | |
| 48 | TextBlock TextBlock::next() const |
| 49 | { |
| 50 | return m_document->findBlockByNumber(blockNumber: m_blockNumber + 1); |
| 51 | } |
| 52 | |
| 53 | TextBlock TextBlock::previous() const |
| 54 | { |
| 55 | return m_document->findBlockByNumber(blockNumber: m_blockNumber - 1); |
| 56 | } |
| 57 | |
| 58 | int TextBlock::userState() const |
| 59 | { |
| 60 | return m_document->userState(blockNumber: m_blockNumber); |
| 61 | } |
| 62 | |
| 63 | void TextBlock::setUserState(int state) |
| 64 | { |
| 65 | m_document->setUserState(blockNumber: m_blockNumber, state); |
| 66 | } |
| 67 | |
| 68 | void TextBlock::setDocument(TextDocument *document) |
| 69 | { |
| 70 | m_document = document; |
| 71 | } |
| 72 | |
| 73 | TextDocument *TextBlock::document() const |
| 74 | { |
| 75 | return m_document; |
| 76 | } |
| 77 | |
| 78 | QString TextBlock::text() const |
| 79 | { |
| 80 | return document()->toPlainText().mid(position: position(), n: length()); |
| 81 | } |
| 82 | |
| 83 | int TextBlock::revision() const |
| 84 | { |
| 85 | return m_revision; |
| 86 | } |
| 87 | |
| 88 | void TextBlock::setRevision(int rev) |
| 89 | { |
| 90 | m_revision = rev; |
| 91 | } |
| 92 | |
| 93 | bool operator==(const TextBlock &t1, const TextBlock &t2) |
| 94 | { |
| 95 | return t1.document() == t2.document() && t1.blockNumber() == t2.blockNumber(); |
| 96 | } |
| 97 | |
| 98 | bool operator!=(const TextBlock &t1, const TextBlock &t2) |
| 99 | { |
| 100 | return !(t1 == t2); |
| 101 | } |
| 102 | |
| 103 | } // namespace Utils |
| 104 | |
| 105 | QT_END_NAMESPACE |
| 106 |
