summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextdocumentfragment_p.h
blob: 0d130003bc885c55274e4ee0c782b6adb186ccd3 (plain)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
// Copyright (C) 2016 The Qt Company Ltd.// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only#ifndef QTEXTDOCUMENTFRAGMENT_P_H#define QTEXTDOCUMENTFRAGMENT_P_H//// W A R N I N G// -------------//// This file is not part of the Qt API. It exists purely as an// implementation detail. This header file may change from version to// version without notice, or even be removed.//// We mean it.//#include <QtGui/private/qtguiglobal_p.h>#include"QtGui/qtextdocument.h"#include"private/qtexthtmlparser_p.h"#include"private/qtextdocument_p.h"#include"QtGui/qtexttable.h"#include"QtCore/qatomic.h"#include"QtCore/qlist.h"#include"QtCore/qmap.h"#include"QtCore/qpointer.h"#include"QtCore/qvarlengtharray.h"#include"QtCore/qdatastream.h" QT_BEGIN_NAMESPACE class QTextDocumentFragmentPrivate;class QTextCopyHelper {public:QTextCopyHelper(const QTextCursor &_source,const QTextCursor &_destination,bool forceCharFormat =false,const QTextCharFormat &fmt =QTextCharFormat());voidcopy();private:voidappendFragments(int pos,int endPos);intappendFragment(int pos,int endPos,int objectIndex = -1);intconvertFormatIndex(const QTextFormat &oldFormat,int objectIndexToSet = -1);inlineintconvertFormatIndex(int oldFormatIndex,int objectIndexToSet = -1){returnconvertFormatIndex(src->formatCollection()->format(oldFormatIndex), objectIndexToSet); }inline QTextFormat convertFormat(const QTextFormat &fmt){return dst->formatCollection()->format(convertFormatIndex(fmt)); }int insertPos;bool forceCharFormat;int primaryCharFormatIndex; QTextCursor cursor; QTextDocumentPrivate *dst; QTextDocumentPrivate *src; QTextFormatCollection &formatCollection;const QString originalText; QMap<int,int> objectIndexMap;};class QTextDocumentFragmentPrivate {public:QTextDocumentFragmentPrivate(const QTextCursor &cursor =QTextCursor());inline~QTextDocumentFragmentPrivate() {delete doc; }voidinsert(QTextCursor &cursor)const; QAtomicInt ref; QTextDocument *doc; uint importedFromPlainText :1;private:Q_DISABLE_COPY_MOVE(QTextDocumentFragmentPrivate)};#ifndef QT_NO_TEXTHTMLPARSERclass QTextHtmlImporter :public QTextHtmlParser {struct Table;public:enum ImportMode { ImportToFragment, ImportToDocument };QTextHtmlImporter(QTextDocument *_doc,const QString &html, ImportMode mode,const QTextDocument *resourceProvider =nullptr);voidimport();private:boolcloseTag(); Table scanTable(int tableNodeIdx);enum ProcessNodeResult { ContinueWithNextNode, ContinueWithCurrentNode, ContinueWithNextSibling };voidappendBlock(const QTextBlockFormat &format, QTextCharFormat charFmt =QTextCharFormat());boolappendNodeText(); ProcessNodeResult processBlockNode(); ProcessNodeResult processSpecialNodes();struct List {inlineList() :listNode(0) {} QTextListFormat format;int listNode; QPointer<QTextList> list;};friend class QTypeInfo<List>; QList<List> lists;int indent;int headingLevel;// insert a named anchor the next time we emit a char format,// either in a block or in regular text QStringList namedAnchors;#ifdef Q_CC_SUNfriendstructQTextHtmlImporter::Table;#endifstruct TableCellIterator {inlineTableCellIterator(QTextTable *t =nullptr) :table(t),row(0),column(0) {}inline TableCellIterator &operator++() {if(atEnd())return*this;do{const QTextTableCell cell = table->cellAt(row, column);if(!cell.isValid())break; column += cell.columnSpan();if(column >= table->columns()) { column =0;++row;}}while(row < table->rows() && table->cellAt(row, column).row() != row);return*this;}inlineboolatEnd()const{return table ==nullptr|| row >= table->rows(); } QTextTableCell cell()const{return table->cellAt(row, column); } QTextTable *table;int row;int column;};friend class QTypeInfo<TableCellIterator>;friendstruct Table;struct Table {Table() :isTextFrame(false),rows(0),columns(0),currentRow(0),lastIndent(0) {} QPointer<QTextFrame> frame;bool isTextFrame;int rows;int columns;int currentRow;// ... for buggy html (see html_skipCell testcase) TableCellIterator currentCell;int lastIndent;};friend class QTypeInfo<Table>; QList<Table> tables;struct RowColSpanInfo {int row, col;int rowSpan, colSpan;};friend class QTypeInfo<RowColSpanInfo>;enum WhiteSpace { RemoveWhiteSpace, CollapseWhiteSpace, PreserveWhiteSpace }; WhiteSpace compressNextWhitespace; QTextDocument *doc; QTextCursor cursor;QTextHtmlParserNode::WhiteSpaceMode wsm; ImportMode importMode;bool hasBlock;bool forceBlockMerging;bool blockTagClosed;int currentNodeIdx;const QTextHtmlParserNode *currentNode;};Q_DECLARE_TYPEINFO(QTextHtmlImporter::List, Q_RELOCATABLE_TYPE);Q_DECLARE_TYPEINFO(QTextHtmlImporter::TableCellIterator, Q_PRIMITIVE_TYPE);Q_DECLARE_TYPEINFO(QTextHtmlImporter::Table, Q_RELOCATABLE_TYPE);Q_DECLARE_TYPEINFO(QTextHtmlImporter::RowColSpanInfo, Q_PRIMITIVE_TYPE); QT_END_NAMESPACE #endif// QT_NO_TEXTHTMLPARSER#endif// QTEXTDOCUMENTFRAGMENT_P_H
close