QtBase  v6.3.1
qtextdocument.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 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 QTEXTDOCUMENT_H
41 #define QTEXTDOCUMENT_H
42 
43 #include <QtGui/qtguiglobal.h>
44 #include <QtCore/qobject.h>
45 #include <QtCore/qsize.h>
46 #include <QtCore/qrect.h>
47 #include <QtCore/qvariant.h>
48 #include <QtGui/qfont.h>
49 #include <QtCore/qurl.h>
50 #include <QtCore/qcontainerfwd.h>
51 Q_MOC_INCLUDE(<QtGui/qtextcursor.h>)
52 
54 
55 
57 class QTextListFormat;
58 class QRect;
59 class QPainter;
60 class QPagedPaintDevice;
62 class QPoint;
63 class QTextObject;
64 class QTextFormat;
65 class QTextFrame;
66 class QTextBlock;
67 class QVariant;
68 class QRectF;
69 class QTextOption;
70 class QTextCursor;
71 
72 namespace Qt
73 {
74  Q_GUI_EXPORT bool mightBeRichText(const QString&);
76 }
77 
78 class Q_GUI_EXPORT QAbstractUndoItem
79 {
80 public:
81  virtual ~QAbstractUndoItem() = 0;
82  virtual void undo() = 0;
83  virtual void redo() = 0;
84 };
85 
87 {
88 }
89 
91 
92 class Q_GUI_EXPORT QTextDocument : public QObject
93 {
94  Q_OBJECT
95 
96  Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
97  Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
98  Q_PROPERTY(QSizeF pageSize READ pageSize WRITE setPageSize)
99  Q_PROPERTY(QFont defaultFont READ defaultFont WRITE setDefaultFont)
100  Q_PROPERTY(bool useDesignMetrics READ useDesignMetrics WRITE setUseDesignMetrics)
101  Q_PROPERTY(QSizeF size READ size)
102  Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth)
103  Q_PROPERTY(int blockCount READ blockCount)
104  Q_PROPERTY(qreal indentWidth READ indentWidth WRITE setIndentWidth)
105 #ifndef QT_NO_CSSPARSER
106  Q_PROPERTY(QString defaultStyleSheet READ defaultStyleSheet WRITE setDefaultStyleSheet)
107 #endif
108  Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount)
109  Q_PROPERTY(qreal documentMargin READ documentMargin WRITE setDocumentMargin)
110  QDOC_PROPERTY(QTextOption defaultTextOption READ defaultTextOption WRITE setDefaultTextOption)
111  Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl NOTIFY baseUrlChanged)
112 
113 public:
114  explicit QTextDocument(QObject *parent = nullptr);
115  explicit QTextDocument(const QString &text, QObject *parent = nullptr);
116  ~QTextDocument();
117 
118  QTextDocument *clone(QObject *parent = nullptr) const;
119 
120  bool isEmpty() const;
121  virtual void clear();
122 
123  void setUndoRedoEnabled(bool enable);
124  bool isUndoRedoEnabled() const;
125 
126  bool isUndoAvailable() const;
127  bool isRedoAvailable() const;
128 
129  int availableUndoSteps() const;
130  int availableRedoSteps() const;
131 
132  int revision() const;
133 
134  void setDocumentLayout(QAbstractTextDocumentLayout *layout);
135  QAbstractTextDocumentLayout *documentLayout() const;
136 
140  CssMedia
141  };
142  void setMetaInformation(MetaInformation info, const QString &);
143  QString metaInformation(MetaInformation info) const;
144 
145 #ifndef QT_NO_TEXTHTMLPARSER
146  QString toHtml() const;
147  void setHtml(const QString &html);
148 #endif
149 
150 #if QT_CONFIG(textmarkdownwriter) || QT_CONFIG(textmarkdownreader)
151  enum MarkdownFeature {
152  MarkdownNoHTML = 0x0020 | 0x0040,
153  MarkdownDialectCommonMark = 0,
154  MarkdownDialectGitHub = 0x0004 | 0x0008 | 0x0400 | 0x0100 | 0x0200 | 0x0800 | 0x4000
155  };
156  Q_DECLARE_FLAGS(MarkdownFeatures, MarkdownFeature)
157  Q_FLAG(MarkdownFeatures)
158 #endif
159 
160 #if QT_CONFIG(textmarkdownwriter)
161  QString toMarkdown(MarkdownFeatures features = MarkdownDialectGitHub) const;
162 #endif
163 
164 #if QT_CONFIG(textmarkdownreader)
165  void setMarkdown(const QString &markdown, MarkdownFeatures features = MarkdownDialectGitHub);
166 #endif
167 
168  QString toRawText() const;
169  QString toPlainText() const;
170  void setPlainText(const QString &text);
171 
172  QChar characterAt(int pos) const;
173 
174  enum FindFlag
175  {
176  FindBackward = 0x00001,
177  FindCaseSensitively = 0x00002,
178  FindWholeWords = 0x00004
179  };
180  Q_DECLARE_FLAGS(FindFlags, FindFlag)
181 
182  QTextCursor find(const QString &subString, int from = 0, FindFlags options = FindFlags()) const;
183  QTextCursor find(const QString &subString, const QTextCursor &cursor, FindFlags options = FindFlags()) const;
184 
185 #if QT_CONFIG(regularexpression)
186  QTextCursor find(const QRegularExpression &expr, int from = 0, FindFlags options = FindFlags()) const;
187  QTextCursor find(const QRegularExpression &expr, const QTextCursor &cursor, FindFlags options = FindFlags()) const;
188 #endif
189 
190  QTextFrame *frameAt(int pos) const;
191  QTextFrame *rootFrame() const;
192 
193  QTextObject *object(int objectIndex) const;
194  QTextObject *objectForFormat(const QTextFormat &) const;
195 
196  QTextBlock findBlock(int pos) const;
197  QTextBlock findBlockByNumber(int blockNumber) const;
198  QTextBlock findBlockByLineNumber(int blockNumber) const;
199  QTextBlock begin() const;
200  QTextBlock end() const;
201 
202  QTextBlock firstBlock() const;
203  QTextBlock lastBlock() const;
204 
205  void setPageSize(const QSizeF &size);
206  QSizeF pageSize() const;
207 
208  void setDefaultFont(const QFont &font);
209  QFont defaultFont() const;
210 
211  void setSuperScriptBaseline(qreal baseline);
212  qreal superScriptBaseline() const;
213 
214  void setSubScriptBaseline(qreal baseline);
215  qreal subScriptBaseline() const;
216 
217  void setBaselineOffset(qreal baseline);
218  qreal baselineOffset() const;
219 
220  int pageCount() const;
221 
222  bool isModified() const;
223 
224 #ifndef QT_NO_PRINTER
225  void print(QPagedPaintDevice *printer) const;
226 #endif
227 
229  UnknownResource = 0,
230  HtmlResource = 1,
231  ImageResource = 2,
232  StyleSheetResource = 3,
233  MarkdownResource = 4,
234 
235  UserResource = 100
236  };
238 
239  QVariant resource(int type, const QUrl &name) const;
240  void addResource(int type, const QUrl &name, const QVariant &resource);
241 
243 
244  QTextDocument::ResourceProvider resourceProvider() const;
245  void setResourceProvider(const ResourceProvider &provider);
246 
247  static QTextDocument::ResourceProvider defaultResourceProvider();
248  static void setDefaultResourceProvider(const ResourceProvider &provider);
249 
250  QList<QTextFormat> allFormats() const;
251 
252  void markContentsDirty(int from, int length);
253 
254  void setUseDesignMetrics(bool b);
255  bool useDesignMetrics() const;
256 
257  void drawContents(QPainter *painter, const QRectF &rect = QRectF());
258 
259  void setTextWidth(qreal width);
260  qreal textWidth() const;
261 
262  qreal idealWidth() const;
263 
264  qreal indentWidth() const;
265  void setIndentWidth(qreal width);
266 
267  qreal documentMargin() const;
268  void setDocumentMargin(qreal margin);
269 
270  void adjustSize();
271  QSizeF size() const;
272 
273  int blockCount() const;
274  int lineCount() const;
275  int characterCount() const;
276 
277 #ifndef QT_NO_CSSPARSER
278  void setDefaultStyleSheet(const QString &sheet);
279  QString defaultStyleSheet() const;
280 #endif
281 
282  void undo(QTextCursor *cursor);
283  void redo(QTextCursor *cursor);
284 
285  enum Stacks {
286  UndoStack = 0x01,
287  RedoStack = 0x02,
288  UndoAndRedoStacks = UndoStack | RedoStack
289  };
290  void clearUndoRedoStacks(Stacks historyToClear = UndoAndRedoStacks);
291 
292  int maximumBlockCount() const;
293  void setMaximumBlockCount(int maximum);
294 
295  QTextOption defaultTextOption() const;
296  void setDefaultTextOption(const QTextOption &option);
297 
298  QUrl baseUrl() const;
299  void setBaseUrl(const QUrl &url);
300 
301  Qt::CursorMoveStyle defaultCursorMoveStyle() const;
302  void setDefaultCursorMoveStyle(Qt::CursorMoveStyle style);
303 
304 Q_SIGNALS:
305  void contentsChange(int from, int charsRemoved, int charsAdded);
307  void undoAvailable(bool);
308  void redoAvailable(bool);
310  void modificationChanged(bool m);
312  void blockCountChanged(int newBlockCount);
313  void baseUrlChanged(const QUrl &url);
315 
316 public Q_SLOTS:
317  void undo();
318  void redo();
319  void appendUndoItem(QAbstractUndoItem *);
320  void setModified(bool m = true);
321 
322 protected:
323  virtual QTextObject *createObject(const QTextFormat &f);
324  Q_INVOKABLE virtual QVariant loadResource(int type, const QUrl &name);
325 
327 private:
329  Q_DECLARE_PRIVATE(QTextDocument)
330  friend class QTextObjectPrivate;
331 };
332 
334 
336 
337 #endif // QTEXTDOCUMENT_H
Arabic default style
Definition: afstyles.h:94
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...
virtual ~QAbstractUndoItem()=0
Definition: qtextdocument.h:86
virtual void undo()=0
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:84
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QPagedPaintDevice class represents a paint device that supports multiple pages.
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
The QRegularExpression class provides pattern matching using regular expressions.
The QSizeF class defines the size of a two-dimensional object using floating point precision.
Definition: qsize.h:235
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QTextBlock class provides a container for text fragments in a QTextDocument. \inmodule QtGui.
Definition: qtextobject.h:193
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
void contentsChange(int from, int charsRemoved, int charsAdded)
void redoAvailable(bool)
void undoCommandAdded()
void modificationChanged(bool m)
void baseUrlChanged(const QUrl &url)
void undoAvailable(bool)
void cursorPositionChanged(const QTextCursor &cursor)
void contentsChanged()
void documentLayoutChanged()
std::function< QVariant(const QUrl &)> ResourceProvider
void blockCountChanged(int newBlockCount)
The QTextFormat class provides formatting information for a QTextDocument. \inmodule QtGui.
Definition: qtextformat.h:126
The QTextFrame class represents a frame in a QTextDocument. \inmodule QtGui.
Definition: qtextobject.h:117
The QTextListFormat class provides formatting information for lists in a QTextDocument....
Definition: qtextformat.h:757
The QTextObject class is a base class for different kinds of objects that can group parts of a QTextD...
Definition: qtextobject.h:61
The QTextOption class provides a description of general rich text properties. \inmodule QtGui.
Definition: qtextoption.h:54
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:130
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
b clear()
QCursor cursor
rect
[4]
backing_store_ptr info
[4]
Definition: jmemsys.h:161
Definition: qnamespace.h:55
Q_GUI_EXPORT QString convertFromPlainText(const QString &plain, WhiteSpaceMode mode=WhiteSpacePre)
WhiteSpaceMode
Definition: qnamespace.h:221
@ WhiteSpacePre
Definition: qnamespace.h:223
CursorMoveStyle
Definition: qnamespace.h:1684
Q_GUI_EXPORT bool mightBeRichText(const QString &)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition: qflags.h:210
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition: qflags.h:227
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
@ text
GLenum GLuint GLenum GLsizei length
Definition: qopengl.h:270
GLenum type
Definition: qopengl.h:270
GLboolean GLboolean GLboolean b
GLenum mode
const GLfloat * m
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLuint end
GLuint object
[3]
GLfloat GLfloat f
GLint GLsizei width
GLboolean enable
GLuint name
GLuint GLenum option
Definition: qopenglext.h:5929
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_PROPERTY(...)
Definition: qtmetamacros.h:92
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_FLAG(x)
Definition: qtmetamacros.h:105
#define Q_INVOKABLE
Definition: qtmetamacros.h:112
#define Q_SLOTS
Definition: qtmetamacros.h:80
#define Q_MOC_INCLUDE(...)
Definition: qtmetamacros.h:115
#define QDOC_PROPERTY(text)
Definition: qtmetamacros.h:98
#define Q_SIGNALS
Definition: qtmetamacros.h:81
QUrl url("http://www.example.com/List of holidays.xml")
[0]
QUrl baseUrl
QVBoxLayout * layout
QPainter painter(this)
[7]
stack undo()
content text html
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
QDomElement find(const QString &tagName, const QDomElement &e)
Definition: main.cpp:39