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