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

source code of qtdeclarative/src/qmlls/qtextblock.cpp