qtextdocument.sip 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. // qtextdocument.sip generated by MetaSIP
  2. //
  3. // This file is part of the QtGui Python extension module.
  4. //
  5. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  6. //
  7. // This file is part of PyQt6.
  8. //
  9. // This file may be used under the terms of the GNU General Public License
  10. // version 3.0 as published by the Free Software Foundation and appearing in
  11. // the file LICENSE included in the packaging of this file. Please review the
  12. // following information to ensure the GNU General Public License version 3.0
  13. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  14. //
  15. // If you do not wish to use this file under the terms of the GPL version 3.0
  16. // then you may purchase a commercial license. For more information contact
  17. // info@riverbankcomputing.com.
  18. //
  19. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. namespace Qt
  22. {
  23. %TypeHeaderCode
  24. #include <qtextdocument.h>
  25. %End
  26. %If (Qt_6_7_0 -)
  27. bool mightBeRichText(QAnyStringView);
  28. %End
  29. %If (- Qt_6_7_0)
  30. bool mightBeRichText(const QString &);
  31. %End
  32. QString convertFromPlainText(const QString &plain, Qt::WhiteSpaceMode mode = Qt::WhiteSpacePre);
  33. };
  34. class QTextDocument : public QObject
  35. {
  36. %TypeHeaderCode
  37. #include <qtextdocument.h>
  38. %End
  39. public:
  40. explicit QTextDocument(QObject *parent /TransferThis/ = 0);
  41. QTextDocument(const QString &text, QObject *parent /TransferThis/ = 0);
  42. virtual ~QTextDocument();
  43. QTextDocument *clone(QObject *parent /TransferThis/ = 0) const /Factory/;
  44. bool isEmpty() const;
  45. virtual void clear();
  46. void setUndoRedoEnabled(bool enable);
  47. bool isUndoRedoEnabled() const;
  48. bool isUndoAvailable() const;
  49. bool isRedoAvailable() const;
  50. void setDocumentLayout(QAbstractTextDocumentLayout *layout /Transfer/);
  51. QAbstractTextDocumentLayout *documentLayout() const;
  52. enum MetaInformation
  53. {
  54. DocumentTitle,
  55. DocumentUrl,
  56. %If (Qt_6_3_0 -)
  57. CssMedia,
  58. %End
  59. %If (Qt_6_8_0 -)
  60. FrontMatter,
  61. %End
  62. };
  63. void setMetaInformation(QTextDocument::MetaInformation info, const QString &);
  64. QString metaInformation(QTextDocument::MetaInformation info) const;
  65. QString toHtml() const;
  66. void setHtml(const QString &html);
  67. QString toPlainText() const;
  68. void setPlainText(const QString &text);
  69. enum FindFlag /BaseType=Flag/
  70. {
  71. FindBackward,
  72. FindCaseSensitively,
  73. FindWholeWords,
  74. };
  75. typedef QFlags<QTextDocument::FindFlag> FindFlags;
  76. QTextCursor find(const QRegularExpression &expr, const QTextCursor &cursor, QTextDocument::FindFlags options = QTextDocument::FindFlags()) const;
  77. QTextCursor find(const QRegularExpression &expr, int position = 0, QTextDocument::FindFlags options = QTextDocument::FindFlags()) const;
  78. QTextCursor find(const QString &subString, const QTextCursor &cursor, QTextDocument::FindFlags options = QTextDocument::FindFlags()) const;
  79. QTextCursor find(const QString &subString, int position = 0, QTextDocument::FindFlags options = QTextDocument::FindFlags()) const;
  80. QTextFrame *rootFrame() const;
  81. QTextObject *object(int objectIndex) const;
  82. QTextObject *objectForFormat(const QTextFormat &) const;
  83. QTextBlock findBlock(int pos) const;
  84. QTextBlock begin() const;
  85. QTextBlock end() const;
  86. void setPageSize(const QSizeF &size);
  87. QSizeF pageSize() const;
  88. void setDefaultFont(const QFont &font);
  89. QFont defaultFont() const;
  90. int pageCount() const;
  91. bool isModified() const;
  92. %If (PyQt_Printer)
  93. void print(QPagedPaintDevice *printer) const;
  94. %End
  95. enum ResourceType /BaseType=IntEnum/
  96. {
  97. UnknownResource,
  98. HtmlResource,
  99. ImageResource,
  100. StyleSheetResource,
  101. MarkdownResource,
  102. UserResource,
  103. };
  104. QVariant resource(int type, const QUrl &name) const;
  105. void addResource(int type, const QUrl &name, const QVariant &resource);
  106. QList<QTextFormat> allFormats() const;
  107. void markContentsDirty(int from, int length);
  108. void setUseDesignMetrics(bool b);
  109. bool useDesignMetrics() const;
  110. signals:
  111. void blockCountChanged(int newBlockCount);
  112. void contentsChange(int from, int charsRemoves, int charsAdded);
  113. void contentsChanged();
  114. void cursorPositionChanged(const QTextCursor &cursor);
  115. void modificationChanged(bool m);
  116. void redoAvailable(bool);
  117. void undoAvailable(bool);
  118. public slots:
  119. void undo();
  120. void redo();
  121. void setModified(bool on = true);
  122. protected:
  123. virtual QTextObject *createObject(const QTextFormat &f) /Factory/;
  124. virtual QVariant loadResource(int type, const QUrl &name);
  125. public:
  126. void drawContents(QPainter *p, const QRectF &rect = QRectF());
  127. void setTextWidth(qreal width);
  128. qreal textWidth() const;
  129. qreal idealWidth() const;
  130. void adjustSize();
  131. QSizeF size() const;
  132. int blockCount() const;
  133. void setDefaultStyleSheet(const QString &sheet);
  134. QString defaultStyleSheet() const;
  135. void undo(QTextCursor *cursor);
  136. void redo(QTextCursor *cursor);
  137. int maximumBlockCount() const;
  138. void setMaximumBlockCount(int maximum);
  139. QTextOption defaultTextOption() const;
  140. void setDefaultTextOption(const QTextOption &option);
  141. int revision() const;
  142. QTextBlock findBlockByNumber(int blockNumber) const;
  143. QTextBlock findBlockByLineNumber(int blockNumber) const;
  144. QTextBlock firstBlock() const;
  145. QTextBlock lastBlock() const;
  146. qreal indentWidth() const;
  147. void setIndentWidth(qreal width);
  148. signals:
  149. void undoCommandAdded();
  150. void documentLayoutChanged();
  151. public:
  152. QChar characterAt(int pos) const;
  153. qreal documentMargin() const;
  154. void setDocumentMargin(qreal margin);
  155. int lineCount() const;
  156. int characterCount() const;
  157. int availableUndoSteps() const;
  158. int availableRedoSteps() const;
  159. enum Stacks
  160. {
  161. UndoStack,
  162. RedoStack,
  163. UndoAndRedoStacks,
  164. };
  165. void clearUndoRedoStacks(QTextDocument::Stacks stacks = QTextDocument::UndoAndRedoStacks);
  166. Qt::CursorMoveStyle defaultCursorMoveStyle() const;
  167. void setDefaultCursorMoveStyle(Qt::CursorMoveStyle style);
  168. QUrl baseUrl() const;
  169. void setBaseUrl(const QUrl &url);
  170. signals:
  171. void baseUrlChanged(const QUrl &url);
  172. public:
  173. QString toRawText() const;
  174. enum MarkdownFeature /BaseType=Flag/
  175. {
  176. MarkdownNoHTML,
  177. MarkdownDialectCommonMark,
  178. MarkdownDialectGitHub,
  179. };
  180. typedef QFlags<QTextDocument::MarkdownFeature> MarkdownFeatures;
  181. QString toMarkdown(QTextDocument::MarkdownFeatures features = QTextDocument::MarkdownDialectGitHub) const;
  182. void setMarkdown(const QString &markdown, QTextDocument::MarkdownFeatures features = QTextDocument::MarkdownDialectGitHub);
  183. void setSuperScriptBaseline(qreal baseline);
  184. qreal superScriptBaseline() const;
  185. void setSubScriptBaseline(qreal baseline);
  186. qreal subScriptBaseline() const;
  187. void setBaselineOffset(qreal baseline);
  188. qreal baselineOffset() const;
  189. %If (Qt_6_1_0 -)
  190. SIP_PYCALLABLE resourceProvider() const /TypeHint="Callable[[QUrl], QVariant]"/;
  191. %MethodCode
  192. if (sipCpp->resourceProvider())
  193. sipRes = sipGetUserObject((sipSimpleWrapper *)sipSelf);
  194. else
  195. sipRes = SIP_NULLPTR;
  196. if (!sipRes)
  197. sipRes = Py_None;
  198. Py_INCREF(sipRes);
  199. %End
  200. %End
  201. %If (Qt_6_1_0 -)
  202. void setResourceProvider(SIP_PYCALLABLE provider /TypeHint="Callable[[QUrl], QVariant]"/);
  203. %MethodCode
  204. // Remove any existing callable.
  205. Py_XDECREF(sipGetUserObject((sipSimpleWrapper *)sipSelf));
  206. if (a0 == Py_None)
  207. {
  208. sipSetUserObject((sipSimpleWrapper *)sipSelf, SIP_NULLPTR);
  209. sipCpp->setResourceProvider(SIP_NULLPTR);
  210. }
  211. else
  212. {
  213. // Save the callable so that resourceProvider() can return it.
  214. Py_INCREF(a0);
  215. sipSetUserObject((sipSimpleWrapper *)sipSelf, a0);
  216. Py_BEGIN_ALLOW_THREADS
  217. sipCpp->setResourceProvider([a0] (const QUrl &arg) {
  218. QUrl *arg_heap = new QUrl(arg);
  219. QVariant qv;
  220. int is_err = 1;
  221. SIP_BLOCK_THREADS
  222. PyObject *arg_obj = sipConvertFromNewType(arg_heap, sipType_QUrl, NULL);
  223. if (arg_obj)
  224. {
  225. PyObject *res_obj = PyObject_CallFunctionObjArgs(a0, arg_obj, NULL);
  226. Py_DECREF(arg_obj);
  227. if (res_obj)
  228. {
  229. is_err = 0;
  230. QVariant *res = reinterpret_cast<QVariant *>(
  231. sipConvertToType(res_obj, sipType_QVariant, NULL, 0,
  232. NULL, &is_err));
  233. if (!is_err)
  234. {
  235. qv = *res;
  236. delete res;
  237. }
  238. }
  239. }
  240. else
  241. {
  242. delete arg_heap;
  243. }
  244. if (is_err)
  245. {
  246. pyqt6_qtgui_err_print();
  247. }
  248. SIP_UNBLOCK_THREADS
  249. return qv;
  250. });
  251. Py_END_ALLOW_THREADS
  252. }
  253. %End
  254. %End
  255. %If (Qt_6_1_0 -)
  256. static SIP_PYCALLABLE defaultResourceProvider() /TypeHint="Callable[[QUrl], QVariant]"/;
  257. %MethodCode
  258. if (QTextDocument::defaultResourceProvider())
  259. sipRes = (PyObject *)sipGetTypeUserData((sipWrapperType *)sipTypeAsPyTypeObject(sipType_QTextDocument));
  260. else
  261. sipRes = SIP_NULLPTR;
  262. if (!sipRes)
  263. sipRes = Py_None;
  264. Py_INCREF(sipRes);
  265. %End
  266. %End
  267. %If (Qt_6_1_0 -)
  268. static void setDefaultResourceProvider(SIP_PYCALLABLE provider /TypeHint="Callable[[QUrl], QVariant]"/);
  269. %MethodCode
  270. sipWrapperType *wt = (sipWrapperType *)sipTypeAsPyTypeObject(sipType_QTextDocument);
  271. // Remove any existing callable.
  272. Py_XDECREF((PyObject *)sipGetTypeUserData(wt));
  273. if (a0 == Py_None)
  274. {
  275. sipSetTypeUserData(wt, SIP_NULLPTR);
  276. QTextDocument::setDefaultResourceProvider(SIP_NULLPTR);
  277. }
  278. else
  279. {
  280. // Save the callable so that defaultResourceProvider() can return it.
  281. Py_INCREF(a0);
  282. sipSetTypeUserData(wt, a0);
  283. Py_BEGIN_ALLOW_THREADS
  284. QTextDocument::setDefaultResourceProvider([a0] (const QUrl &arg) {
  285. QUrl *arg_heap = new QUrl(arg);
  286. QVariant qv;
  287. int is_err = 1;
  288. SIP_BLOCK_THREADS
  289. PyObject *arg_obj = sipConvertFromNewType(arg_heap, sipType_QUrl, NULL);
  290. if (arg_obj)
  291. {
  292. PyObject *res_obj = PyObject_CallFunctionObjArgs(a0, arg_obj, NULL);
  293. Py_DECREF(arg_obj);
  294. if (res_obj)
  295. {
  296. is_err = 0;
  297. QVariant *res = reinterpret_cast<QVariant *>(
  298. sipConvertToType(res_obj, sipType_QVariant, NULL, 0,
  299. NULL, &is_err));
  300. if (!is_err)
  301. {
  302. qv = *res;
  303. delete res;
  304. }
  305. }
  306. }
  307. else
  308. {
  309. delete arg_heap;
  310. }
  311. if (is_err)
  312. {
  313. pyqt6_qtgui_err_print();
  314. }
  315. SIP_UNBLOCK_THREADS
  316. return qv;
  317. });
  318. Py_END_ALLOW_THREADS
  319. }
  320. %End
  321. %End
  322. %If (Qt_6_4_0 -)
  323. void setLayoutEnabled(bool b);
  324. %End
  325. %If (Qt_6_4_0 -)
  326. bool isLayoutEnabled() const;
  327. %End
  328. };