QtBase  v6.3.1
qtextobject.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QTEXTOBJECT_H
41 #define QTEXTOBJECT_H
42 
43 #include <QtGui/qtguiglobal.h>
44 #include <QtCore/qobject.h>
45 #include <QtGui/qtextformat.h>
46 #include <QtGui/qtextlayout.h>
47 #include <QtGui/qglyphrun.h>
48 
50 
51 
52 class QTextObjectPrivate;
53 class QTextDocument;
55 class QTextCursor;
56 class QTextBlock;
57 class QTextFragment;
58 class QTextList;
59 
60 class Q_GUI_EXPORT QTextObject : public QObject
61 {
62  Q_OBJECT
63 
64 protected:
65  explicit QTextObject(QTextDocument *doc);
66  ~QTextObject();
67 
68  void setFormat(const QTextFormat &format);
69 
70 public:
71  QTextFormat format() const;
72  int formatIndex() const;
73 
74  QTextDocument *document() const;
75 
76  int objectIndex() const;
77 
78 protected:
80 
81 private:
82  Q_DECLARE_PRIVATE(QTextObject)
84  friend class QTextDocumentPrivate;
85 };
86 
88 class Q_GUI_EXPORT QTextBlockGroup : public QTextObject
89 {
90  Q_OBJECT
91 
92 protected:
93  explicit QTextBlockGroup(QTextDocument *doc);
94  ~QTextBlockGroup();
95 
96  virtual void blockInserted(const QTextBlock &block);
97  virtual void blockRemoved(const QTextBlock &block);
98  virtual void blockFormatChanged(const QTextBlock &block);
99 
100  QList<QTextBlock> blockList() const;
101 
102 protected:
104 private:
105  Q_DECLARE_PRIVATE(QTextBlockGroup)
107  friend class QTextDocumentPrivate;
108 };
109 
110 class Q_GUI_EXPORT QTextFrameLayoutData {
111 public:
112  virtual ~QTextFrameLayoutData();
113 };
114 
115 class QTextFramePrivate;
116 class Q_GUI_EXPORT QTextFrame : public QTextObject
117 {
118  Q_OBJECT
119 
120 public:
121  explicit QTextFrame(QTextDocument *doc);
122  ~QTextFrame();
123 
124  inline void setFrameFormat(const QTextFrameFormat &format);
126 
127  QTextCursor firstCursorPosition() const;
128  QTextCursor lastCursorPosition() const;
129  int firstPosition() const;
130  int lastPosition() const;
131 
132  QTextFrameLayoutData *layoutData() const;
133  void setLayoutData(QTextFrameLayoutData *data);
134 
135  QList<QTextFrame *> childFrames() const;
136  QTextFrame *parentFrame() const;
137 
138  class iterator {
139  QTextFrame *f = nullptr;
140  int b = 0;
141  int e = 0;
142  QTextFrame *cf = nullptr;
143  int cb = 0;
144 
145  friend class QTextFrame;
146  friend class QTextTableCell;
148  inline iterator(QTextFrame *frame, int block, int begin, int end)
149  : f(frame), b(begin), e(end), cb(block)
150  {}
151  public:
152  constexpr iterator() noexcept = default;
153  QTextFrame *parentFrame() const { return f; }
154 
155  QTextFrame *currentFrame() const { return cf; }
156  Q_GUI_EXPORT QTextBlock currentBlock() const;
157 
158  bool atEnd() const { return !cf && cb == e; }
159 
160  inline bool operator==(const iterator &o) const { return f == o.f && cf == o.cf && cb == o.cb; }
161  inline bool operator!=(const iterator &o) const { return f != o.f || cf != o.cf || cb != o.cb; }
162  Q_GUI_EXPORT iterator &operator++();
163  inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; }
164  Q_GUI_EXPORT iterator &operator--();
165  inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; }
166  };
167 
168  friend class iterator;
169  // more Qt
171 
172  iterator begin() const;
173  iterator end() const;
174 
175 protected:
177 private:
178  friend class QTextDocumentPrivate;
179  Q_DECLARE_PRIVATE(QTextFrame)
181 };
183 
184 inline void QTextFrame::setFrameFormat(const QTextFrameFormat &aformat)
185 { QTextObject::setFormat(aformat); }
186 
187 class Q_GUI_EXPORT QTextBlockUserData {
188 public:
189  virtual ~QTextBlockUserData();
190 };
191 
192 class Q_GUI_EXPORT QTextBlock
193 {
194  friend class QSyntaxHighlighter;
195 public:
196  inline QTextBlock(QTextDocumentPrivate *priv, int b) : p(priv), n(b) {}
197  inline QTextBlock() : p(nullptr), n(0) {}
198  inline QTextBlock(const QTextBlock &o) : p(o.p), n(o.n) {}
199  inline QTextBlock &operator=(const QTextBlock &o) { p = o.p; n = o.n; return *this; }
200 
201  bool isValid() const;
202 
203  inline bool operator==(const QTextBlock &o) const { return p == o.p && n == o.n; }
204  inline bool operator!=(const QTextBlock &o) const { return p != o.p || n != o.n; }
205  inline bool operator<(const QTextBlock &o) const { return position() < o.position(); }
206 
207  int position() const;
208  int length() const;
209  bool contains(int position) const;
210 
211  QTextLayout *layout() const;
212  void clearLayout();
213  QTextBlockFormat blockFormat() const;
214  int blockFormatIndex() const;
215  QTextCharFormat charFormat() const;
216  int charFormatIndex() const;
217 
218  Qt::LayoutDirection textDirection() const;
219 
220  QString text() const;
221 
222  QList<QTextLayout::FormatRange> textFormats() const;
223 
224  const QTextDocument *document() const;
225 
226  QTextList *textList() const;
227 
228  QTextBlockUserData *userData() const;
229  void setUserData(QTextBlockUserData *data);
230 
231  int userState() const;
232  void setUserState(int state);
233 
234  int revision() const;
235  void setRevision(int rev);
236 
237  bool isVisible() const;
238  void setVisible(bool visible);
239 
240  int blockNumber() const;
241  int firstLineNumber() const;
242 
243  void setLineCount(int count);
244  int lineCount() const;
245 
246  class iterator {
247  const QTextDocumentPrivate *p = nullptr;
248  int b = 0;
249  int e = 0;
250  int n = 0;
251  friend class QTextBlock;
252  iterator(const QTextDocumentPrivate *priv, int begin, int end, int f)
253  : p(priv), b(begin), e(end), n(f) {}
254  public:
255  constexpr iterator() = default;
256 
257  Q_GUI_EXPORT QTextFragment fragment() const;
258 
259  bool atEnd() const { return n == e; }
260 
261  inline bool operator==(const iterator &o) const { return p == o.p && n == o.n; }
262  inline bool operator!=(const iterator &o) const { return p != o.p || n != o.n; }
263  Q_GUI_EXPORT iterator &operator++();
264  inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; }
265  Q_GUI_EXPORT iterator &operator--();
266  inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; }
267  };
268 
269  // more Qt
271 
272  iterator begin() const;
273  iterator end() const;
274 
275  QTextBlock next() const;
276  QTextBlock previous() const;
277 
278  inline int fragmentIndex() const { return n; }
279 
280 private:
282  int n;
283  friend class QTextDocumentPrivate;
284  friend class QTextLayout;
285 };
286 
289 
290 
291 class Q_GUI_EXPORT QTextFragment
292 {
293 public:
294  inline QTextFragment(const QTextDocumentPrivate *priv, int f, int fe) : p(priv), n(f), ne(fe) {}
295  inline QTextFragment() : p(nullptr), n(0), ne(0) {}
296  inline QTextFragment(const QTextFragment &o) : p(o.p), n(o.n), ne(o.ne) {}
297  inline QTextFragment &operator=(const QTextFragment &o) { p = o.p; n = o.n; ne = o.ne; return *this; }
298 
299  inline bool isValid() const { return p && n; }
300 
301  inline bool operator==(const QTextFragment &o) const { return p == o.p && n == o.n; }
302  inline bool operator!=(const QTextFragment &o) const { return p != o.p || n != o.n; }
303  inline bool operator<(const QTextFragment &o) const { return position() < o.position(); }
304 
305  int position() const;
306  int length() const;
307  bool contains(int position) const;
308 
309  QTextCharFormat charFormat() const;
310  int charFormatIndex() const;
311  QString text() const;
312 
313 #if !defined(QT_NO_RAWFONT)
314  QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
315 #endif
316 
317 private:
318  const QTextDocumentPrivate *p;
319  int n;
320  int ne;
321 };
322 
324 
326 
327 #endif // QTEXTOBJECT_H
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QSyntaxHighlighter class allows you to define syntax highlighting rules, and in addition you can ...
The QTextBlock::iterator class provides an iterator for reading the contents of a QTextBlock....
Definition: qtextobject.h:246
bool atEnd() const
Definition: qtextobject.h:259
iterator operator++(int)
Definition: qtextobject.h:264
bool operator!=(const iterator &o) const
Definition: qtextobject.h:262
bool operator==(const iterator &o) const
Definition: qtextobject.h:261
constexpr iterator()=default
iterator operator--(int)
Definition: qtextobject.h:266
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument....
Definition: qtextformat.h:640
The QTextBlockGroup class provides a container for text blocks within a QTextDocument....
Definition: qtextobject.h:89
The QTextBlock class provides a container for text fragments in a QTextDocument. \inmodule QtGui.
Definition: qtextobject.h:193
int fragmentIndex() const
Definition: qtextobject.h:278
iterator Iterator
Definition: qtextobject.h:270
QTextBlock(const QTextBlock &o)
Definition: qtextobject.h:198
bool operator<(const QTextBlock &o) const
Definition: qtextobject.h:205
bool operator==(const QTextBlock &o) const
Definition: qtextobject.h:203
bool operator!=(const QTextBlock &o) const
Definition: qtextobject.h:204
QTextBlock & operator=(const QTextBlock &o)
Definition: qtextobject.h:199
QTextBlock(QTextDocumentPrivate *priv, int b)
Definition: qtextobject.h:196
QTextBlock previous() const
The QTextBlockUserData class is used to associate custom data with blocks of text....
Definition: qtextobject.h:187
The QTextCharFormat class provides formatting information for characters in a QTextDocument....
Definition: qtextformat.h:416
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:67
The QTextDocument class holds formatted text.
Definition: qtextdocument.h:93
The QTextFormat class provides formatting information for a QTextDocument. \inmodule QtGui.
Definition: qtextformat.h:126
QTextFrameFormat toFrameFormat() const
The QTextFragment class holds a piece of text in a QTextDocument with a single QTextCharFormat....
Definition: qtextobject.h:292
bool operator==(const QTextFragment &o) const
Definition: qtextobject.h:301
bool isValid() const
Definition: qtextobject.h:299
QTextFragment(const QTextDocumentPrivate *priv, int f, int fe)
Definition: qtextobject.h:294
bool operator!=(const QTextFragment &o) const
Definition: qtextobject.h:302
bool operator<(const QTextFragment &o) const
Definition: qtextobject.h:303
QTextFragment(const QTextFragment &o)
Definition: qtextobject.h:296
QTextFragment & operator=(const QTextFragment &o)
Definition: qtextobject.h:297
The iterator class provides an iterator for reading the contents of a QTextFrame.
Definition: qtextobject.h:138
QTextFrame * currentFrame() const
Definition: qtextobject.h:155
bool atEnd() const
Definition: qtextobject.h:158
bool operator==(const iterator &o) const
Definition: qtextobject.h:160
constexpr iterator() noexcept=default
iterator operator--(int)
Definition: qtextobject.h:165
iterator operator++(int)
Definition: qtextobject.h:163
bool operator!=(const iterator &o) const
Definition: qtextobject.h:161
The QTextFrameFormat class provides formatting information for frames in a QTextDocument....
Definition: qtextformat.h:859
The QTextFrame class represents a frame in a QTextDocument. \inmodule QtGui.
Definition: qtextobject.h:117
void setFrameFormat(const QTextFrameFormat &format)
Definition: qtextobject.h:184
iterator Iterator
Definition: qtextobject.h:170
QTextFrameFormat frameFormat() const
Definition: qtextobject.h:125
The QTextLayout class is used to lay out and render text. \inmodule QtGui.
Definition: qtextlayout.h:106
The QTextList class provides a decorated list of items in a QTextDocument. \inmodule QtGui.
Definition: qtextlist.h:54
The QTextObject class is a base class for different kinds of objects that can group parts of a QTextD...
Definition: qtextobject.h:61
void setFormat(const QTextFormat &format)
QTextFormat format() const
The QTextTableCell class represents the properties of a cell in a QTextTable. \inmodule QtGui.
Definition: qtexttable.h:55
widget setFormat(format)
QDomDocument document
[0]
double e
set contains("Julia")
else opt state
[0]
JOCTET JCOEFPTR block
Definition: jsimd.h:109
short next
Definition: keywords.cpp:454
typename C::iterator iterator
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
LayoutDirection
Definition: qnamespace.h:1462
default
Definition: devices.py:76
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
@ text
GLenum GLuint GLenum GLsizei length
Definition: qopengl.h:270
GLboolean GLboolean GLboolean b
GLuint GLuint end
GLenum GLenum GLsizei count
GLfloat GLfloat f
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat n
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
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)
Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_RELOCATABLE_TYPE)
#define Q_OBJECT
Definition: qtmetamacros.h:158
@ Q_RELOCATABLE_TYPE
Definition: qtypeinfo.h:156
QObject::connect nullptr
QVBoxLayout * layout
edit isVisible()
QFrame frame
[0]