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

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