Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtextobject.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QTEXTOBJECT_H
5#define QTEXTOBJECT_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qobject.h>
9#include <QtGui/qtextformat.h>
10#include <QtGui/qtextlayout.h>
11#include <QtGui/qglyphrun.h>
12
14
15
17class QTextDocument;
19class QTextCursor;
20class QTextBlock;
21class QTextFragment;
22class QTextList;
23
24class Q_GUI_EXPORT QTextObject : public QObject
25{
27
28protected:
29 explicit QTextObject(QTextDocument *doc);
31
32 void setFormat(const QTextFormat &format);
33
34public:
35 QTextFormat format() const;
36 int formatIndex() const;
37
38 QTextDocument *document() const;
39
40 int objectIndex() const;
41
42protected:
44
45private:
46 Q_DECLARE_PRIVATE(QTextObject)
47 Q_DISABLE_COPY(QTextObject)
49};
50
52class Q_GUI_EXPORT QTextBlockGroup : public QTextObject
53{
55
56protected:
57 explicit QTextBlockGroup(QTextDocument *doc);
59
60 virtual void blockInserted(const QTextBlock &block);
61 virtual void blockRemoved(const QTextBlock &block);
62 virtual void blockFormatChanged(const QTextBlock &block);
63
64 QList<QTextBlock> blockList() const;
65
66protected:
68private:
69 Q_DECLARE_PRIVATE(QTextBlockGroup)
70 Q_DISABLE_COPY(QTextBlockGroup)
72};
73
74class Q_GUI_EXPORT QTextFrameLayoutData {
75public:
76 virtual ~QTextFrameLayoutData();
77};
78
80class Q_GUI_EXPORT QTextFrame : public QTextObject
81{
83
84public:
85 explicit QTextFrame(QTextDocument *doc);
87
88 inline void setFrameFormat(const QTextFrameFormat &format);
90
91 QTextCursor firstCursorPosition() const;
92 QTextCursor lastCursorPosition() const;
93 int firstPosition() const;
94 int lastPosition() const;
95
96 QTextFrameLayoutData *layoutData() const;
97 void setLayoutData(QTextFrameLayoutData *data);
98
99 QList<QTextFrame *> childFrames() const;
100 QTextFrame *parentFrame() const;
101
102 class iterator {
103 QTextFrame *f = nullptr;
104 int b = 0;
105 int e = 0;
106 QTextFrame *cf = nullptr;
107 int cb = 0;
108
109 friend class QTextFrame;
110 friend class QTextTableCell;
112 inline iterator(QTextFrame *frame, int block, int begin, int end)
113 : f(frame), b(begin), e(end), cb(block)
114 {}
115 public:
116 constexpr iterator() noexcept = default;
117 QTextFrame *parentFrame() const { return f; }
118
119 QTextFrame *currentFrame() const { return cf; }
120 Q_GUI_EXPORT QTextBlock currentBlock() const;
121
122 bool atEnd() const { return !cf && cb == e; }
123
124 inline bool operator==(const iterator &o) const { return f == o.f && cf == o.cf && cb == o.cb; }
125 inline bool operator!=(const iterator &o) const { return f != o.f || cf != o.cf || cb != o.cb; }
126 Q_GUI_EXPORT iterator &operator++();
127 inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; }
128 Q_GUI_EXPORT iterator &operator--();
129 inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; }
130 };
131
132 friend class iterator;
133 // more Qt
135
136 iterator begin() const;
137 iterator end() const;
138
139protected:
141private:
143 Q_DECLARE_PRIVATE(QTextFrame)
144 Q_DISABLE_COPY(QTextFrame)
145};
147
149{ QTextObject::setFormat(aformat); }
150
151class Q_GUI_EXPORT QTextBlockUserData {
152public:
153 virtual ~QTextBlockUserData();
154};
155
156class Q_GUI_EXPORT QTextBlock
157{
158 friend class QSyntaxHighlighter;
159public:
161 inline QTextBlock() : p(nullptr), n(0) {}
162 inline QTextBlock(const QTextBlock &o) : p(o.p), n(o.n) {}
163 inline QTextBlock &operator=(const QTextBlock &o) { p = o.p; n = o.n; return *this; }
164
165 bool isValid() const;
166
167 inline bool operator==(const QTextBlock &o) const { return p == o.p && n == o.n; }
168 inline bool operator!=(const QTextBlock &o) const { return p != o.p || n != o.n; }
169 inline bool operator<(const QTextBlock &o) const { return position() < o.position(); }
170
171 int position() const;
172 int length() const;
173 bool contains(int position) const;
174
175 QTextLayout *layout() const;
176 void clearLayout();
177 QTextBlockFormat blockFormat() const;
178 int blockFormatIndex() const;
179 QTextCharFormat charFormat() const;
180 int charFormatIndex() const;
181
182 Qt::LayoutDirection textDirection() const;
183
184 QString text() const;
185
186 QList<QTextLayout::FormatRange> textFormats() const;
187
188 const QTextDocument *document() const;
189
190 QTextList *textList() const;
191
192 QTextBlockUserData *userData() const;
193 void setUserData(QTextBlockUserData *data);
194
195 int userState() const;
196 void setUserState(int state);
197
198 int revision() const;
199 void setRevision(int rev);
200
201 bool isVisible() const;
202 void setVisible(bool visible);
203
204 int blockNumber() const;
205 int firstLineNumber() const;
206
207 void setLineCount(int count);
208 int lineCount() const;
209
210 class iterator {
211 const QTextDocumentPrivate *p = nullptr;
212 int b = 0;
213 int e = 0;
214 int n = 0;
215 friend class QTextBlock;
216 iterator(const QTextDocumentPrivate *priv, int begin, int end, int f)
217 : p(priv), b(begin), e(end), n(f) {}
218 public:
219 constexpr iterator() = default;
220
221 Q_GUI_EXPORT QTextFragment fragment() const;
222
223 bool atEnd() const { return n == e; }
224
225 inline bool operator==(const iterator &o) const { return p == o.p && n == o.n; }
226 inline bool operator!=(const iterator &o) const { return p != o.p || n != o.n; }
227 Q_GUI_EXPORT iterator &operator++();
228 inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; }
229 Q_GUI_EXPORT iterator &operator--();
230 inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; }
231 };
232
233 // more Qt
235
236 iterator begin() const;
237 iterator end() const;
238
239 QTextBlock next() const;
240 QTextBlock previous() const;
241
242 inline int fragmentIndex() const { return n; }
243
244private:
246 int n;
248 friend class QTextLayout;
249};
250
253
254
255class Q_GUI_EXPORT QTextFragment
256{
257public:
258 inline QTextFragment(const QTextDocumentPrivate *priv, int f, int fe) : p(priv), n(f), ne(fe) {}
259 inline QTextFragment() : p(nullptr), n(0), ne(0) {}
260 inline QTextFragment(const QTextFragment &o) : p(o.p), n(o.n), ne(o.ne) {}
261 inline QTextFragment &operator=(const QTextFragment &o) { p = o.p; n = o.n; ne = o.ne; return *this; }
262
263 inline bool isValid() const { return p && n; }
264
265 inline bool operator==(const QTextFragment &o) const { return p == o.p && n == o.n; }
266 inline bool operator!=(const QTextFragment &o) const { return p != o.p || n != o.n; }
267 inline bool operator<(const QTextFragment &o) const { return position() < o.position(); }
268
269 int position() const;
270 int length() const;
271 bool contains(int position) const;
272
273 QTextCharFormat charFormat() const;
274 int charFormatIndex() const;
275 QString text() const;
276
277#if !defined(QT_NO_RAWFONT)
278 QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
279#endif
280
281private:
282 const QTextDocumentPrivate *p;
283 int n;
284 int ne;
285};
286
288
290
291#endif // QTEXTOBJECT_H
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\reentrant \inmodule QtGui
\reentrant
Definition qtextobject.h:53
bool atEnd() const
Returns true if the current item is the last item in the text block.
iterator operator++(int)
The postfix ++ operator ({i++}) advances the iterator to the next item in the text block and returns ...
bool operator!=(const iterator &o) const
Returns true if this iterator is different from the other iterator; otherwise returns false.
bool operator==(const iterator &o) const
Returns true if this iterator is the same as the other iterator; otherwise returns false.
constexpr iterator()=default
Constructs an iterator for this text block.
iterator operator--(int)
The postfix ā€“ operator ({iā€“}) makes the preceding item current and returns an iterator to the old cur...
\reentrant
int fragmentIndex() const
iterator Iterator
Qt-style synonym for QTextBlock::iterator.
QTextBlock(const QTextBlock &o)
Copies the other text block's attributes to this text block.
bool operator<(const QTextBlock &o) const
Returns true if this text block occurs before the other text block in the document.
bool operator==(const QTextBlock &o) const
Returns true if this text block is the same as the other text block.
bool operator!=(const QTextBlock &o) const
Returns true if this text block is different from the other text block.
QTextBlock & operator=(const QTextBlock &o)
Assigns the other text block to this text block.
QTextBlock(QTextDocumentPrivate *priv, int b)
\reentrant \inmodule QtGui
Definition qtextcursor.h:30
\reentrant \inmodule QtGui
\reentrant
Definition qtextformat.h:90
QTextFrameFormat toFrameFormat() const
Returns this format as a frame format.
\reentrant
bool operator==(const QTextFragment &o) const
Returns true if this text fragment is the same (at the same position) as the other text fragment; oth...
bool isValid() const
Returns true if this is a valid text fragment (i.e.
QTextFragment(const QTextDocumentPrivate *priv, int f, int fe)
QTextFragment()
Creates a new empty text fragment.
bool operator!=(const QTextFragment &o) const
Returns true if this text fragment is different (at a different position) from the other text fragmen...
bool operator<(const QTextFragment &o) const
Returns true if this text fragment appears earlier in the document than the other text fragment; othe...
QTextFragment(const QTextFragment &o)
Copies the content (text and format) of the other text fragment to this text fragment.
QTextFragment & operator=(const QTextFragment &o)
Assigns the content (text and format) of the other text fragment to this text fragment.
QTextFrame * currentFrame() const
Returns the current frame pointed to by the iterator, or \nullptr if the iterator currently points to...
bool atEnd() const
Returns true if the current item is the last item in the text frame.
bool operator==(const iterator &o) const
Returns true if the iterator is the same as the other iterator; otherwise returns false.
constexpr iterator() noexcept=default
Constructs an invalid iterator.
iterator operator--(int)
The postfix {ā€“} operator ({iā€“}) makes the preceding item in the current frame, and returns an iterato...
iterator operator++(int)
The postfix {++} operator ({i++}) advances the iterator to the next item in the text frame,...
bool operator!=(const iterator &o) const
Returns true if the iterator is different from the other iterator; otherwise returns false.
\reentrant
Definition qtextobject.h:81
void setFrameFormat(const QTextFrameFormat &format)
Sets the frame's format.
iterator Iterator
Qt-style synonym for QTextFrame::iterator.
QTextFrameFormat frameFormat() const
Returns the frame's format.
Definition qtextobject.h:89
\reentrant
Definition qtextlayout.h:70
\reentrant
Definition qtextlist.h:18
\reentrant
Definition qtextobject.h:25
void setFormat(const QTextFormat &format)
Sets the text object's format.
QTextFormat format() const
Returns the text object's format.
\reentrant
Definition qtexttable.h:19
widget setFormat(format)
QString text
else opt state
[0]
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
LayoutDirection
static const QMetaObjectPrivate * priv(const uint *data)
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLboolean GLboolean GLboolean b
GLuint GLuint end
GLenum GLuint GLenum GLsizei length
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLfloat n
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat p
[1]
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
#define Q_OBJECT
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:158
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
QObject::connect nullptr
QVBoxLayout * layout
edit isVisible()
QFrame frame
[0]