Qt 4.8
qtextdocumentfragment_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTEXTDOCUMENTFRAGMENT_P_H
43 #define QTEXTDOCUMENTFRAGMENT_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "QtGui/qtextdocument.h"
57 #include "private/qtexthtmlparser_p.h"
58 #include "private/qtextdocument_p.h"
59 #include "QtGui/qtexttable.h"
60 #include "QtCore/qatomic.h"
61 #include "QtCore/qlist.h"
62 #include "QtCore/qmap.h"
63 #include "QtCore/qpointer.h"
64 #include "QtCore/qvarlengtharray.h"
65 #include "QtCore/qdatastream.h"
66 
68 
70 
72 {
73 public:
74  QTextCopyHelper(const QTextCursor &_source, const QTextCursor &_destination, bool forceCharFormat = false, const QTextCharFormat &fmt = QTextCharFormat());
75 
76  void copy();
77 
78 private:
79  void appendFragments(int pos, int endPos);
80  int appendFragment(int pos, int endPos, int objectIndex = -1);
81  int convertFormatIndex(const QTextFormat &oldFormat, int objectIndexToSet = -1);
82  inline int convertFormatIndex(int oldFormatIndex, int objectIndexToSet = -1)
83  { return convertFormatIndex(src->formatCollection()->format(oldFormatIndex), objectIndexToSet); }
85  { return dst->formatCollection()->format(convertFormatIndex(fmt)); }
86 
87  int insertPos;
88 
91 
98 };
99 
101 {
102 public:
104  inline ~QTextDocumentFragmentPrivate() { delete doc; }
105 
106  void insert(QTextCursor &cursor) const;
107 
110 
112 private:
114 };
115 
116 #ifndef QT_NO_TEXTHTMLPARSER
117 
119 {
120  struct Table;
121 public:
122  enum ImportMode {
124  ImportToDocument
125  };
126 
127  QTextHtmlImporter(QTextDocument *_doc, const QString &html,
128  ImportMode mode,
129  const QTextDocument *resourceProvider = 0);
130 
131  void import();
132 
133 private:
134  bool closeTag();
135 
136  Table scanTable(int tableNodeIdx);
137 
138  enum ProcessNodeResult { ContinueWithNextNode, ContinueWithCurrentNode, ContinueWithNextSibling };
139 
140  void appendBlock(const QTextBlockFormat &format, QTextCharFormat charFmt = QTextCharFormat());
141  bool appendNodeText();
142 
143  ProcessNodeResult processBlockNode();
144  ProcessNodeResult processSpecialNodes();
145 
146  struct List
147  {
148  inline List() : listNode(0) {}
150  int listNode;
152  };
154  int indent;
155 
156  // insert a named anchor the next time we emit a char format,
157  // either in a block or in regular text
159 
160 #ifdef Q_CC_SUN
161  friend struct QTextHtmlImporter::Table;
162 #endif
164  {
165  inline TableCellIterator(QTextTable *t = 0) : table(t), row(0), column(0) {}
166 
168  if (atEnd())
169  return *this;
170  do {
171  const QTextTableCell cell = table->cellAt(row, column);
172  if (!cell.isValid())
173  break;
174  column += cell.columnSpan();
175  if (column >= table->columns()) {
176  column = 0;
177  ++row;
178  }
179  } while (row < table->rows() && table->cellAt(row, column).row() != row);
180 
181  return *this;
182  }
183 
184  inline bool atEnd() const { return table == 0 || row >= table->rows(); }
185 
186  QTextTableCell cell() const { return table->cellAt(row, column); }
187 
189  int row;
190  int column;
191  };
192 
193  friend struct Table;
194  struct Table
195  {
196  Table() : isTextFrame(false), rows(0), columns(0), currentRow(0), lastIndent(0) {}
199  int rows;
200  int columns;
201  int currentRow; // ... for buggy html (see html_skipCell testcase)
204  };
206 
208  {
209  int row, col;
210  int rowSpan, colSpan;
211  };
212 
214  {
217  PreserveWhiteSpace
218  };
219 
221 
226  bool hasBlock;
231 };
232 
234 #endif // QT_NO_TEXTHTMLPARSER
235 
236 #endif // QTEXTDOCUMENTFRAGMENT_P_H
QMap< int, int > objectIndexMap
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
The QTextListFormat class provides formatting information for lists in a QTextDocument.
Definition: qtextformat.h:642
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QTextFormatCollection & formatCollection
void appendFragments(int pos, int endPos)
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Definition: qatomic.h:55
QTextDocumentPrivate * dst
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
The QString class provides a Unicode character string.
Definition: qstring.h:83
QTextFormat format(int idx) const
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
const QString originalText
QTextHtmlParserNode::WhiteSpaceMode wsm
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
int convertFormatIndex(int oldFormatIndex, int objectIndexToSet=-1)
QTextFormatCollection * formatCollection()
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QTextCopyHelper(const QTextCursor &_source, const QTextCursor &_destination, bool forceCharFormat=false, const QTextCharFormat &fmt=QTextCharFormat())
unsigned int uint
Definition: qglobal.h:996
int convertFormatIndex(const QTextFormat &oldFormat, int objectIndexToSet=-1)
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
The QTextTableCell class represents the properties of a cell in a QTextTable.
Definition: qtexttable.h:59
int appendFragment(int pos, int endPos, int objectIndex=-1)
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
bool isValid() const
Returns true if this is a valid table cell; otherwise returns false.
Definition: qtexttable.h:77
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
const QTextHtmlParserNode * currentNode
int columnSpan() const
Returns the number of columns this cell spans.
Definition: qtexttable.cpp:228
QTextFormat convertFormat(const QTextFormat &fmt)
QPointer< QTextFrame > frame
QTextDocumentPrivate * src