Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 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 | #include "qtexttable.h" | - |
43 | #include "qtextcursor.h" | - |
44 | #include "qtextformat.h" | - |
45 | #include <qdebug.h> | - |
46 | #include "qtexttable_p.h" | - |
47 | #include "qvarlengtharray.h" | - |
48 | #include "private/qfunctions_p.h" | - |
49 | | - |
50 | #include <algorithm> | - |
51 | #include <stdlib.h> | - |
52 | | - |
53 | QT_BEGIN_NAMESPACE | - |
54 | | - |
55 | /*! | - |
56 | \class QTextTableCell | - |
57 | \reentrant | - |
58 | | - |
59 | \brief The QTextTableCell class represents the properties of a | - |
60 | cell in a QTextTable. | - |
61 | \inmodule QtGui | - |
62 | | - |
63 | \ingroup richtext-processing | - |
64 | | - |
65 | Table cells are pieces of document structure that belong to a table. | - |
66 | The table orders cells into particular rows and columns; cells can | - |
67 | also span multiple columns and rows. | - |
68 | | - |
69 | Cells are usually created when a table is inserted into a document with | - |
70 | QTextCursor::insertTable(), but they are also created and destroyed when | - |
71 | a table is resized. | - |
72 | | - |
73 | Cells contain information about their location in a table; you can | - |
74 | obtain the row() and column() numbers of a cell, and its rowSpan() | - |
75 | and columnSpan(). | - |
76 | | - |
77 | The format() of a cell describes the default character format of its | - |
78 | contents. The firstCursorPosition() and lastCursorPosition() functions | - |
79 | are used to obtain the extent of the cell in the document. | - |
80 | | - |
81 | \sa QTextTable, QTextTableFormat | - |
82 | */ | - |
83 | | - |
84 | /*! | - |
85 | \fn QTextTableCell::QTextTableCell() | - |
86 | | - |
87 | Constructs an invalid table cell. | - |
88 | | - |
89 | \sa isValid() | - |
90 | */ | - |
91 | | - |
92 | /*! | - |
93 | \fn QTextTableCell::QTextTableCell(const QTextTableCell &other) | - |
94 | | - |
95 | Copy constructor. Creates a new QTextTableCell object based on the | - |
96 | \a other cell. | - |
97 | */ | - |
98 | | - |
99 | /*! | - |
100 | \fn QTextTableCell& QTextTableCell::operator=(const QTextTableCell &other) | - |
101 | | - |
102 | Assigns the \a other table cell to this table cell. | - |
103 | */ | - |
104 | | - |
105 | /*! | - |
106 | \since 4.2 | - |
107 | | - |
108 | Sets the cell's character format to \a format. This can for example be used to change | - |
109 | the background color of the entire cell: | - |
110 | | - |
111 | QTextTableCell cell = table->cellAt(2, 3); | - |
112 | QTextCharFormat format = cell.format(); | - |
113 | format.setBackground(Qt::blue); | - |
114 | cell.setFormat(format); | - |
115 | | - |
116 | Note that the cell's row or column span cannot be changed through this function. You have | - |
117 | to use QTextTable::mergeCells and QTextTable::splitCell instead. | - |
118 | | - |
119 | \sa format() | - |
120 | */ | - |
121 | void QTextTableCell::setFormat(const QTextCharFormat &format) | - |
122 | { | - |
123 | QTextCharFormat fmt = format; executed (the execution status of this line is deduced): QTextCharFormat fmt = format; | - |
124 | fmt.clearProperty(QTextFormat::ObjectIndex); executed (the execution status of this line is deduced): fmt.clearProperty(QTextFormat::ObjectIndex); | - |
125 | fmt.setObjectType(QTextFormat::TableCellObject); executed (the execution status of this line is deduced): fmt.setObjectType(QTextFormat::TableCellObject); | - |
126 | QTextDocumentPrivate *p = table->docHandle(); executed (the execution status of this line is deduced): QTextDocumentPrivate *p = table->docHandle(); | - |
127 | QTextDocumentPrivate::FragmentIterator frag(&p->fragmentMap(), fragment); executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator frag(&p->fragmentMap(), fragment); | - |
128 | | - |
129 | QTextFormatCollection *c = p->formatCollection(); executed (the execution status of this line is deduced): QTextFormatCollection *c = p->formatCollection(); | - |
130 | QTextCharFormat oldFormat = c->charFormat(frag->format); executed (the execution status of this line is deduced): QTextCharFormat oldFormat = c->charFormat(frag->format); | - |
131 | fmt.setTableCellRowSpan(oldFormat.tableCellRowSpan()); executed (the execution status of this line is deduced): fmt.setTableCellRowSpan(oldFormat.tableCellRowSpan()); | - |
132 | fmt.setTableCellColumnSpan(oldFormat.tableCellColumnSpan()); executed (the execution status of this line is deduced): fmt.setTableCellColumnSpan(oldFormat.tableCellColumnSpan()); | - |
133 | | - |
134 | p->setCharFormat(frag.position(), 1, fmt, QTextDocumentPrivate::SetFormatAndPreserveObjectIndices); executed (the execution status of this line is deduced): p->setCharFormat(frag.position(), 1, fmt, QTextDocumentPrivate::SetFormatAndPreserveObjectIndices); | - |
135 | } executed: } Execution Count:162 | 162 |
136 | | - |
137 | /*! | - |
138 | Returns the cell's character format. | - |
139 | */ | - |
140 | QTextCharFormat QTextTableCell::format() const | - |
141 | { | - |
142 | QTextDocumentPrivate *p = table->docHandle(); executed (the execution status of this line is deduced): QTextDocumentPrivate *p = table->docHandle(); | - |
143 | QTextFormatCollection *c = p->formatCollection(); executed (the execution status of this line is deduced): QTextFormatCollection *c = p->formatCollection(); | - |
144 | | - |
145 | QTextCharFormat fmt = c->charFormat(tableCellFormatIndex()); executed (the execution status of this line is deduced): QTextCharFormat fmt = c->charFormat(tableCellFormatIndex()); | - |
146 | fmt.setObjectType(QTextFormat::TableCellObject); executed (the execution status of this line is deduced): fmt.setObjectType(QTextFormat::TableCellObject); | - |
147 | return fmt; executed: return fmt; Execution Count:6354 | 6354 |
148 | } | - |
149 | | - |
150 | /*! | - |
151 | \since 4.5 | - |
152 | | - |
153 | Returns the index of the tableCell's format in the document's internal list of formats. | - |
154 | | - |
155 | \sa QTextDocument::allFormats() | - |
156 | */ | - |
157 | int QTextTableCell::tableCellFormatIndex() const | - |
158 | { | - |
159 | QTextDocumentPrivate *p = table->docHandle(); executed (the execution status of this line is deduced): QTextDocumentPrivate *p = table->docHandle(); | - |
160 | return QTextDocumentPrivate::FragmentIterator(&p->fragmentMap(), fragment)->format; executed: return QTextDocumentPrivate::FragmentIterator(&p->fragmentMap(), fragment)->format; Execution Count:6354 | 6354 |
161 | } | - |
162 | | - |
163 | /*! | - |
164 | Returns the number of the row in the table that contains this cell. | - |
165 | | - |
166 | \sa column() | - |
167 | */ | - |
168 | int QTextTableCell::row() const | - |
169 | { | - |
170 | const QTextTablePrivate *tp = table->d_func(); executed (the execution status of this line is deduced): const QTextTablePrivate *tp = table->d_func(); | - |
171 | if (tp->dirty) partially evaluated: tp->dirty no Evaluation Count:0 | yes Evaluation Count:2324 |
| 0-2324 |
172 | tp->update(); never executed: tp->update(); | 0 |
173 | | - |
174 | int idx = tp->findCellIndex(fragment); executed (the execution status of this line is deduced): int idx = tp->findCellIndex(fragment); | - |
175 | if (idx == -1) partially evaluated: idx == -1 no Evaluation Count:0 | yes Evaluation Count:2324 |
| 0-2324 |
176 | return idx; never executed: return idx; | 0 |
177 | return tp->cellIndices.at(idx) / tp->nCols; executed: return tp->cellIndices.at(idx) / tp->nCols; Execution Count:2324 | 2324 |
178 | } | - |
179 | | - |
180 | /*! | - |
181 | Returns the number of the column in the table that contains this cell. | - |
182 | | - |
183 | \sa row() | - |
184 | */ | - |
185 | int QTextTableCell::column() const | - |
186 | { | - |
187 | const QTextTablePrivate *tp = table->d_func(); executed (the execution status of this line is deduced): const QTextTablePrivate *tp = table->d_func(); | - |
188 | if (tp->dirty) partially evaluated: tp->dirty no Evaluation Count:0 | yes Evaluation Count:1915 |
| 0-1915 |
189 | tp->update(); never executed: tp->update(); | 0 |
190 | | - |
191 | int idx = tp->findCellIndex(fragment); executed (the execution status of this line is deduced): int idx = tp->findCellIndex(fragment); | - |
192 | if (idx == -1) partially evaluated: idx == -1 no Evaluation Count:0 | yes Evaluation Count:1915 |
| 0-1915 |
193 | return idx; never executed: return idx; | 0 |
194 | return tp->cellIndices.at(idx) % tp->nCols; executed: return tp->cellIndices.at(idx) % tp->nCols; Execution Count:1915 | 1915 |
195 | } | - |
196 | | - |
197 | /*! | - |
198 | Returns the number of rows this cell spans. The default is 1. | - |
199 | | - |
200 | \sa columnSpan() | - |
201 | */ | - |
202 | int QTextTableCell::rowSpan() const | - |
203 | { | - |
204 | return format().tableCellRowSpan(); executed: return format().tableCellRowSpan(); Execution Count:1722 | 1722 |
205 | } | - |
206 | | - |
207 | /*! | - |
208 | Returns the number of columns this cell spans. The default is 1. | - |
209 | | - |
210 | \sa rowSpan() | - |
211 | */ | - |
212 | int QTextTableCell::columnSpan() const | - |
213 | { | - |
214 | return format().tableCellColumnSpan(); executed: return format().tableCellColumnSpan(); Execution Count:2204 | 2204 |
215 | } | - |
216 | | - |
217 | /*! | - |
218 | \fn bool QTextTableCell::isValid() const | - |
219 | | - |
220 | Returns true if this is a valid table cell; otherwise returns | - |
221 | false. | - |
222 | */ | - |
223 | | - |
224 | | - |
225 | /*! | - |
226 | Returns the first valid cursor position in this cell. | - |
227 | | - |
228 | \sa lastCursorPosition() | - |
229 | */ | - |
230 | QTextCursor QTextTableCell::firstCursorPosition() const | - |
231 | { | - |
232 | return QTextCursor(table->d_func()->pieceTable, firstPosition()); executed: return QTextCursor(table->d_func()->pieceTable, firstPosition()); Execution Count:317 | 317 |
233 | } | - |
234 | | - |
235 | /*! | - |
236 | Returns the last valid cursor position in this cell. | - |
237 | | - |
238 | \sa firstCursorPosition() | - |
239 | */ | - |
240 | QTextCursor QTextTableCell::lastCursorPosition() const | - |
241 | { | - |
242 | return QTextCursor(table->d_func()->pieceTable, lastPosition()); executed: return QTextCursor(table->d_func()->pieceTable, lastPosition()); Execution Count:12 | 12 |
243 | } | - |
244 | | - |
245 | | - |
246 | /*! | - |
247 | \internal | - |
248 | | - |
249 | Returns the first valid position in the document occupied by this cell. | - |
250 | */ | - |
251 | int QTextTableCell::firstPosition() const | - |
252 | { | - |
253 | QTextDocumentPrivate *p = table->docHandle(); executed (the execution status of this line is deduced): QTextDocumentPrivate *p = table->docHandle(); | - |
254 | return p->fragmentMap().position(fragment) + 1; executed: return p->fragmentMap().position(fragment) + 1; Execution Count:2212 | 2212 |
255 | } | - |
256 | | - |
257 | /*! | - |
258 | \internal | - |
259 | | - |
260 | Returns the last valid position in the document occupied by this cell. | - |
261 | */ | - |
262 | int QTextTableCell::lastPosition() const | - |
263 | { | - |
264 | QTextDocumentPrivate *p = table->docHandle(); executed (the execution status of this line is deduced): QTextDocumentPrivate *p = table->docHandle(); | - |
265 | const QTextTablePrivate *td = table->d_func(); executed (the execution status of this line is deduced): const QTextTablePrivate *td = table->d_func(); | - |
266 | int index = table->d_func()->findCellIndex(fragment); executed (the execution status of this line is deduced): int index = table->d_func()->findCellIndex(fragment); | - |
267 | int f; executed (the execution status of this line is deduced): int f; | - |
268 | if (index != -1) partially evaluated: index != -1 yes Evaluation Count:1436 | no Evaluation Count:0 |
| 0-1436 |
269 | f = td->cells.value(index + 1, td->fragment_end); executed: f = td->cells.value(index + 1, td->fragment_end); Execution Count:1436 | 1436 |
270 | else | - |
271 | f = td->fragment_end; never executed: f = td->fragment_end; | 0 |
272 | return p->fragmentMap().position(f); executed: return p->fragmentMap().position(f); Execution Count:1436 | 1436 |
273 | } | - |
274 | | - |
275 | | - |
276 | /*! | - |
277 | Returns a frame iterator pointing to the beginning of the table's cell. | - |
278 | | - |
279 | \sa end() | - |
280 | */ | - |
281 | QTextFrame::iterator QTextTableCell::begin() const | - |
282 | { | - |
283 | QTextDocumentPrivate *p = table->docHandle(); executed (the execution status of this line is deduced): QTextDocumentPrivate *p = table->docHandle(); | - |
284 | int b = p->blockMap().findNode(firstPosition()); executed (the execution status of this line is deduced): int b = p->blockMap().findNode(firstPosition()); | - |
285 | int e = p->blockMap().findNode(lastPosition()+1); executed (the execution status of this line is deduced): int e = p->blockMap().findNode(lastPosition()+1); | - |
286 | return QTextFrame::iterator(const_cast<QTextTable *>(table), b, b, e); executed: return QTextFrame::iterator(const_cast<QTextTable *>(table), b, b, e); Execution Count:1293 | 1293 |
287 | } | - |
288 | | - |
289 | /*! | - |
290 | Returns a frame iterator pointing to the end of the table's cell. | - |
291 | | - |
292 | \sa begin() | - |
293 | */ | - |
294 | QTextFrame::iterator QTextTableCell::end() const | - |
295 | { | - |
296 | QTextDocumentPrivate *p = table->docHandle(); never executed (the execution status of this line is deduced): QTextDocumentPrivate *p = table->docHandle(); | - |
297 | int b = p->blockMap().findNode(firstPosition()); never executed (the execution status of this line is deduced): int b = p->blockMap().findNode(firstPosition()); | - |
298 | int e = p->blockMap().findNode(lastPosition()+1); never executed (the execution status of this line is deduced): int e = p->blockMap().findNode(lastPosition()+1); | - |
299 | return QTextFrame::iterator(const_cast<QTextTable *>(table), e, b, e); never executed: return QTextFrame::iterator(const_cast<QTextTable *>(table), e, b, e); | 0 |
300 | } | - |
301 | | - |
302 | | - |
303 | /*! | - |
304 | \fn QTextCursor QTextTableCell::operator==(const QTextTableCell &other) const | - |
305 | | - |
306 | Returns true if this cell object and the \a other cell object | - |
307 | describe the same cell; otherwise returns false. | - |
308 | */ | - |
309 | | - |
310 | /*! | - |
311 | \fn QTextCursor QTextTableCell::operator!=(const QTextTableCell &other) const | - |
312 | | - |
313 | Returns true if this cell object and the \a other cell object | - |
314 | describe different cells; otherwise returns false. | - |
315 | */ | - |
316 | | - |
317 | /*! | - |
318 | \fn QTextTableCell::~QTextTableCell() | - |
319 | | - |
320 | Destroys the table cell. | - |
321 | */ | - |
322 | | - |
323 | QTextTablePrivate::~QTextTablePrivate() | - |
324 | { | - |
325 | if (grid) evaluated: grid yes Evaluation Count:182 | yes Evaluation Count:58 |
| 58-182 |
326 | free(grid); executed: free(grid); Execution Count:182 | 182 |
327 | } executed: } Execution Count:240 | 240 |
328 | | - |
329 | | - |
330 | QTextTable *QTextTablePrivate::createTable(QTextDocumentPrivate *pieceTable, int pos, int rows, int cols, const QTextTableFormat &tableFormat) | - |
331 | { | - |
332 | QTextTableFormat fmt = tableFormat; executed (the execution status of this line is deduced): QTextTableFormat fmt = tableFormat; | - |
333 | fmt.setColumns(cols); executed (the execution status of this line is deduced): fmt.setColumns(cols); | - |
334 | QTextTable *table = qobject_cast<QTextTable *>(pieceTable->createObject(fmt)); executed (the execution status of this line is deduced): QTextTable *table = qobject_cast<QTextTable *>(pieceTable->createObject(fmt)); | - |
335 | Q_ASSERT(table); executed (the execution status of this line is deduced): qt_noop(); | - |
336 | | - |
337 | pieceTable->beginEditBlock(); executed (the execution status of this line is deduced): pieceTable->beginEditBlock(); | - |
338 | | - |
339 | // qDebug("---> createTable: rows=%d, cols=%d at %d", rows, cols, pos); | - |
340 | // add block after table | - |
341 | QTextCharFormat charFmt; executed (the execution status of this line is deduced): QTextCharFormat charFmt; | - |
342 | charFmt.setObjectIndex(table->objectIndex()); executed (the execution status of this line is deduced): charFmt.setObjectIndex(table->objectIndex()); | - |
343 | charFmt.setObjectType(QTextFormat::TableCellObject); executed (the execution status of this line is deduced): charFmt.setObjectType(QTextFormat::TableCellObject); | - |
344 | | - |
345 | | - |
346 | int charIdx = pieceTable->formatCollection()->indexForFormat(charFmt); executed (the execution status of this line is deduced): int charIdx = pieceTable->formatCollection()->indexForFormat(charFmt); | - |
347 | int cellIdx = pieceTable->formatCollection()->indexForFormat(QTextBlockFormat()); executed (the execution status of this line is deduced): int cellIdx = pieceTable->formatCollection()->indexForFormat(QTextBlockFormat()); | - |
348 | | - |
349 | QTextTablePrivate *d = table->d_func(); executed (the execution status of this line is deduced): QTextTablePrivate *d = table->d_func(); | - |
350 | d->blockFragmentUpdates = true; executed (the execution status of this line is deduced): d->blockFragmentUpdates = true; | - |
351 | | - |
352 | d->fragment_start = pieceTable->insertBlock(QTextBeginningOfFrame, pos, cellIdx, charIdx); executed (the execution status of this line is deduced): d->fragment_start = pieceTable->insertBlock(QChar(0xfdd0), pos, cellIdx, charIdx); | - |
353 | d->cells.append(d->fragment_start); executed (the execution status of this line is deduced): d->cells.append(d->fragment_start); | - |
354 | ++pos; executed (the execution status of this line is deduced): ++pos; | - |
355 | | - |
356 | for (int i = 1; i < rows*cols; ++i) { evaluated: i < rows*cols yes Evaluation Count:677 | yes Evaluation Count:151 |
| 151-677 |
357 | d->cells.append(pieceTable->insertBlock(QTextBeginningOfFrame, pos, cellIdx, charIdx)); executed (the execution status of this line is deduced): d->cells.append(pieceTable->insertBlock(QChar(0xfdd0), pos, cellIdx, charIdx)); | - |
358 | // qDebug(" addCell at %d", pos); | - |
359 | ++pos; executed (the execution status of this line is deduced): ++pos; | - |
360 | } executed: } Execution Count:677 | 677 |
361 | | - |
362 | d->fragment_end = pieceTable->insertBlock(QTextEndOfFrame, pos, cellIdx, charIdx); executed (the execution status of this line is deduced): d->fragment_end = pieceTable->insertBlock(QChar(0xfdd1), pos, cellIdx, charIdx); | - |
363 | // qDebug(" addEOR at %d", pos); | - |
364 | ++pos; executed (the execution status of this line is deduced): ++pos; | - |
365 | | - |
366 | d->blockFragmentUpdates = false; executed (the execution status of this line is deduced): d->blockFragmentUpdates = false; | - |
367 | d->dirty = true; executed (the execution status of this line is deduced): d->dirty = true; | - |
368 | | - |
369 | pieceTable->endEditBlock(); executed (the execution status of this line is deduced): pieceTable->endEditBlock(); | - |
370 | | - |
371 | return table; executed: return table; Execution Count:151 | 151 |
372 | } | - |
373 | | - |
374 | struct QFragmentFindHelper | - |
375 | { | - |
376 | inline QFragmentFindHelper(int _pos, const QTextDocumentPrivate::FragmentMap &map) | - |
377 | : pos(_pos), fragmentMap(map) {} executed: } Execution Count:6998 | 6998 |
378 | uint pos; | - |
379 | const QTextDocumentPrivate::FragmentMap &fragmentMap; | - |
380 | }; | - |
381 | | - |
382 | Q_STATIC_GLOBAL_INLINE_OPERATOR bool operator<(int fragment, const QFragmentFindHelper &helper) | - |
383 | { | - |
384 | return helper.fragmentMap.position(fragment) < helper.pos; executed: return helper.fragmentMap.position(fragment) < helper.pos; Execution Count:27307 | 27307 |
385 | } | - |
386 | | - |
387 | Q_STATIC_GLOBAL_INLINE_OPERATOR bool operator<(const QFragmentFindHelper &helper, int fragment) | - |
388 | { | - |
389 | return helper.pos < helper.fragmentMap.position(fragment); executed: return helper.pos < helper.fragmentMap.position(fragment); Execution Count:5873 | 5873 |
390 | } | - |
391 | | - |
392 | int QTextTablePrivate::findCellIndex(int fragment) const | - |
393 | { | - |
394 | QFragmentFindHelper helper(pieceTable->fragmentMap().position(fragment), executed (the execution status of this line is deduced): QFragmentFindHelper helper(pieceTable->fragmentMap().position(fragment), | - |
395 | pieceTable->fragmentMap()); executed (the execution status of this line is deduced): pieceTable->fragmentMap()); | - |
396 | QList<int>::ConstIterator it = qBinaryFind(cells.begin(), cells.end(), helper); executed (the execution status of this line is deduced): QList<int>::ConstIterator it = qBinaryFind(cells.begin(), cells.end(), helper); | - |
397 | if (it == cells.end()) partially evaluated: it == cells.end() no Evaluation Count:0 | yes Evaluation Count:5778 |
| 0-5778 |
398 | return -1; never executed: return -1; | 0 |
399 | return it - cells.begin(); executed: return it - cells.begin(); Execution Count:5778 | 5778 |
400 | } | - |
401 | | - |
402 | void QTextTablePrivate::fragmentAdded(QChar type, uint fragment) | - |
403 | { | - |
404 | dirty = true; executed (the execution status of this line is deduced): dirty = true; | - |
405 | if (blockFragmentUpdates) evaluated: blockFragmentUpdates yes Evaluation Count:979 | yes Evaluation Count:434 |
| 434-979 |
406 | return; executed: return; Execution Count:979 | 979 |
407 | if (type == QTextBeginningOfFrame) { evaluated: type == QChar(0xfdd0) yes Evaluation Count:344 | yes Evaluation Count:90 |
| 90-344 |
408 | Q_ASSERT(cells.indexOf(fragment) == -1); executed (the execution status of this line is deduced): qt_noop(); | - |
409 | const uint pos = pieceTable->fragmentMap().position(fragment); executed (the execution status of this line is deduced): const uint pos = pieceTable->fragmentMap().position(fragment); | - |
410 | QFragmentFindHelper helper(pos, pieceTable->fragmentMap()); executed (the execution status of this line is deduced): QFragmentFindHelper helper(pos, pieceTable->fragmentMap()); | - |
411 | QList<int>::Iterator it = std::lower_bound(cells.begin(), cells.end(), helper); executed (the execution status of this line is deduced): QList<int>::Iterator it = std::lower_bound(cells.begin(), cells.end(), helper); | - |
412 | cells.insert(it, fragment); executed (the execution status of this line is deduced): cells.insert(it, fragment); | - |
413 | if (!fragment_start || pos < pieceTable->fragmentMap().position(fragment_start)) evaluated: !fragment_start yes Evaluation Count:89 | yes Evaluation Count:255 |
evaluated: pos < pieceTable->fragmentMap().position(fragment_start) yes Evaluation Count:11 | yes Evaluation Count:244 |
| 11-255 |
414 | fragment_start = fragment; executed: fragment_start = fragment; Execution Count:100 | 100 |
415 | return; executed: return; Execution Count:344 | 344 |
416 | } | - |
417 | QTextFramePrivate::fragmentAdded(type, fragment); executed (the execution status of this line is deduced): QTextFramePrivate::fragmentAdded(type, fragment); | - |
418 | } executed: } Execution Count:90 | 90 |
419 | | - |
420 | void QTextTablePrivate::fragmentRemoved(QChar type, uint fragment) | - |
421 | { | - |
422 | dirty = true; executed (the execution status of this line is deduced): dirty = true; | - |
423 | if (blockFragmentUpdates) evaluated: blockFragmentUpdates yes Evaluation Count:106 | yes Evaluation Count:119 |
| 106-119 |
424 | return; executed: return; Execution Count:106 | 106 |
425 | if (type == QTextBeginningOfFrame) { evaluated: type == QChar(0xfdd0) yes Evaluation Count:114 | yes Evaluation Count:5 |
| 5-114 |
426 | Q_ASSERT(cells.indexOf(fragment) != -1); executed (the execution status of this line is deduced): qt_noop(); | - |
427 | cells.removeAll(fragment); executed (the execution status of this line is deduced): cells.removeAll(fragment); | - |
428 | if (fragment_start == fragment && cells.size()) { evaluated: fragment_start == fragment yes Evaluation Count:42 | yes Evaluation Count:72 |
evaluated: cells.size() yes Evaluation Count:38 | yes Evaluation Count:4 |
| 4-72 |
429 | fragment_start = cells.at(0); executed (the execution status of this line is deduced): fragment_start = cells.at(0); | - |
430 | } executed: } Execution Count:38 | 38 |
431 | if (fragment_start != fragment) evaluated: fragment_start != fragment yes Evaluation Count:110 | yes Evaluation Count:4 |
| 4-110 |
432 | return; executed: return; Execution Count:110 | 110 |
433 | } executed: } Execution Count:4 | 4 |
434 | QTextFramePrivate::fragmentRemoved(type, fragment); executed (the execution status of this line is deduced): QTextFramePrivate::fragmentRemoved(type, fragment); | - |
435 | } executed: } Execution Count:9 | 9 |
436 | | - |
437 | /*! | - |
438 | /fn void QTextTablePrivate::update() const | - |
439 | | - |
440 | This function is usually called when the table is "dirty". | - |
441 | It seems to update all kind of table information. | - |
442 | | - |
443 | */ | - |
444 | void QTextTablePrivate::update() const | - |
445 | { | - |
446 | Q_Q(const QTextTable); executed (the execution status of this line is deduced): const QTextTable * const q = q_func(); | - |
447 | nCols = q->format().columns(); executed (the execution status of this line is deduced): nCols = q->format().columns(); | - |
448 | nRows = (cells.size() + nCols-1)/nCols; executed (the execution status of this line is deduced): nRows = (cells.size() + nCols-1)/nCols; | - |
449 | // qDebug(">>>> QTextTablePrivate::update, nRows=%d, nCols=%d", nRows, nCols); | - |
450 | | - |
451 | grid = q_check_ptr((int *)realloc(grid, nRows*nCols*sizeof(int))); executed (the execution status of this line is deduced): grid = q_check_ptr((int *)realloc(grid, nRows*nCols*sizeof(int))); | - |
452 | memset(grid, 0, nRows*nCols*sizeof(int)); executed (the execution status of this line is deduced): memset(grid, 0, nRows*nCols*sizeof(int)); | - |
453 | | - |
454 | QTextDocumentPrivate *p = pieceTable; executed (the execution status of this line is deduced): QTextDocumentPrivate *p = pieceTable; | - |
455 | QTextFormatCollection *c = p->formatCollection(); executed (the execution status of this line is deduced): QTextFormatCollection *c = p->formatCollection(); | - |
456 | | - |
457 | cellIndices.resize(cells.size()); executed (the execution status of this line is deduced): cellIndices.resize(cells.size()); | - |
458 | | - |
459 | int cell = 0; executed (the execution status of this line is deduced): int cell = 0; | - |
460 | for (int i = 0; i < cells.size(); ++i) { evaluated: i < cells.size() yes Evaluation Count:1431 | yes Evaluation Count:243 |
| 243-1431 |
461 | int fragment = cells.at(i); executed (the execution status of this line is deduced): int fragment = cells.at(i); | - |
462 | QTextCharFormat fmt = c->charFormat(QTextDocumentPrivate::FragmentIterator(&p->fragmentMap(), fragment)->format); executed (the execution status of this line is deduced): QTextCharFormat fmt = c->charFormat(QTextDocumentPrivate::FragmentIterator(&p->fragmentMap(), fragment)->format); | - |
463 | int rowspan = fmt.tableCellRowSpan(); executed (the execution status of this line is deduced): int rowspan = fmt.tableCellRowSpan(); | - |
464 | int colspan = fmt.tableCellColumnSpan(); executed (the execution status of this line is deduced): int colspan = fmt.tableCellColumnSpan(); | - |
465 | | - |
466 | // skip taken cells | - |
467 | while (cell < nRows*nCols && grid[cell]) evaluated: cell < nRows*nCols yes Evaluation Count:2673 | yes Evaluation Count:5 |
evaluated: grid[cell] yes Evaluation Count:1247 | yes Evaluation Count:1426 |
| 5-2673 |
468 | ++cell; executed: ++cell; Execution Count:1247 | 1247 |
469 | | - |
470 | int r = cell/nCols; executed (the execution status of this line is deduced): int r = cell/nCols; | - |
471 | int c = cell%nCols; executed (the execution status of this line is deduced): int c = cell%nCols; | - |
472 | cellIndices[i] = cell; executed (the execution status of this line is deduced): cellIndices[i] = cell; | - |
473 | | - |
474 | if (r + rowspan > nRows) { evaluated: r + rowspan > nRows yes Evaluation Count:9 | yes Evaluation Count:1422 |
| 9-1422 |
475 | grid = q_check_ptr((int *)realloc(grid, sizeof(int)*(r + rowspan)*nCols)); executed (the execution status of this line is deduced): grid = q_check_ptr((int *)realloc(grid, sizeof(int)*(r + rowspan)*nCols)); | - |
476 | memset(grid + (nRows*nCols), 0, sizeof(int)*(r+rowspan-nRows)*nCols); executed (the execution status of this line is deduced): memset(grid + (nRows*nCols), 0, sizeof(int)*(r+rowspan-nRows)*nCols); | - |
477 | nRows = r + rowspan; executed (the execution status of this line is deduced): nRows = r + rowspan; | - |
478 | } executed: } Execution Count:9 | 9 |
479 | | - |
480 | Q_ASSERT(c + colspan <= nCols); executed (the execution status of this line is deduced): qt_noop(); | - |
481 | for (int ii = 0; ii < rowspan; ++ii) { evaluated: ii < rowspan yes Evaluation Count:1462 | yes Evaluation Count:1431 |
| 1431-1462 |
482 | for (int jj = 0; jj < colspan; ++jj) { evaluated: jj < colspan yes Evaluation Count:1513 | yes Evaluation Count:1462 |
| 1462-1513 |
483 | Q_ASSERT(grid[(r+ii)*nCols + c+jj] == 0); executed (the execution status of this line is deduced): qt_noop(); | - |
484 | grid[(r+ii)*nCols + c+jj] = fragment; executed (the execution status of this line is deduced): grid[(r+ii)*nCols + c+jj] = fragment; | - |
485 | // qDebug(" setting cell %d span=%d/%d at %d/%d", fragment, rowspan, colspan, r+ii, c+jj); | - |
486 | } executed: } Execution Count:1513 | 1513 |
487 | } executed: } Execution Count:1462 | 1462 |
488 | } executed: } Execution Count:1431 | 1431 |
489 | // qDebug("<<<< end: nRows=%d, nCols=%d", nRows, nCols); | - |
490 | | - |
491 | dirty = false; executed (the execution status of this line is deduced): dirty = false; | - |
492 | } executed: } Execution Count:243 | 243 |
493 | | - |
494 | | - |
495 | | - |
496 | | - |
497 | | - |
498 | /*! | - |
499 | \class QTextTable | - |
500 | \reentrant | - |
501 | | - |
502 | \brief The QTextTable class represents a table in a QTextDocument. | - |
503 | \inmodule QtGui | - |
504 | | - |
505 | \ingroup richtext-processing | - |
506 | | - |
507 | A table is a group of cells ordered into rows and columns. Each table | - |
508 | contains at least one row and one column. Each cell contains a block, and | - |
509 | is surrounded by a frame. | - |
510 | | - |
511 | Tables are usually created and inserted into a document with the | - |
512 | QTextCursor::insertTable() function. | - |
513 | For example, we can insert a table with three rows and two columns at the | - |
514 | current cursor position in an editor using the following lines of code: | - |
515 | | - |
516 | \snippet textdocument-tables/mainwindow.cpp 1 | - |
517 | \codeline | - |
518 | \snippet textdocument-tables/mainwindow.cpp 3 | - |
519 | | - |
520 | The table format is either defined when the table is created or changed | - |
521 | later with setFormat(). | - |
522 | | - |
523 | The table currently being edited by the cursor is found with | - |
524 | QTextCursor::currentTable(). This allows its format or dimensions to be | - |
525 | changed after it has been inserted into a document. | - |
526 | | - |
527 | A table's size can be changed with resize(), or by using | - |
528 | insertRows(), insertColumns(), removeRows(), or removeColumns(). | - |
529 | Use cellAt() to retrieve table cells. | - |
530 | | - |
531 | The starting and ending positions of table rows can be found by moving | - |
532 | a cursor within a table, and using the rowStart() and rowEnd() functions | - |
533 | to obtain cursors at the start and end of each row. | - |
534 | | - |
535 | Rows and columns within a QTextTable can be merged and split using | - |
536 | the mergeCells() and splitCell() functions. However, only cells that span multiple | - |
537 | rows or columns can be split. (Merging or splitting does not increase or decrease | - |
538 | the number of rows and columns.) | - |
539 | | - |
540 | Note that if you have merged multiple columns and rows into one cell, you will not | - |
541 | be able to split the merged cell into new cells spanning over more than one row | - |
542 | or column. To be able to split cells spanning over several rows and columns you | - |
543 | need to do this over several iterations. | - |
544 | | - |
545 | \table 80% | - |
546 | \row | - |
547 | \li \inlineimage texttable-split.png Original Table | - |
548 | \li Suppose we have a 2x3 table of names and addresses. To merge both | - |
549 | columns in the first row we invoke mergeCells() with \a row = 0, | - |
550 | \a column = 0, \a numRows = 1 and \a numColumns = 2. | - |
551 | \snippet textdocument-texttable/main.cpp 0 | - |
552 | | - |
553 | \row | - |
554 | \li \inlineimage texttable-merge.png | - |
555 | \li This gives us the following table. To split the first row of the table | - |
556 | back into two cells, we invoke the splitCell() function with \a numRows | - |
557 | and \a numCols = 1. | - |
558 | \snippet textdocument-texttable/main.cpp 1 | - |
559 | | - |
560 | \row | - |
561 | \li \inlineimage texttable-split.png Split Table | - |
562 | \li This results in the original table. | - |
563 | \endtable | - |
564 | | - |
565 | \sa QTextTableFormat | - |
566 | */ | - |
567 | | - |
568 | /*! \internal | - |
569 | */ | - |
570 | QTextTable::QTextTable(QTextDocument *doc) | - |
571 | : QTextFrame(*new QTextTablePrivate(doc), doc) | - |
572 | { | - |
573 | } executed: } Execution Count:240 | 240 |
574 | | - |
575 | /*! \internal | - |
576 | | - |
577 | Destroys the table. | - |
578 | */ | - |
579 | QTextTable::~QTextTable() | - |
580 | { | - |
581 | } | - |
582 | | - |
583 | | - |
584 | /*! | - |
585 | \fn QTextTableCell QTextTable::cellAt(int row, int column) const | - |
586 | | - |
587 | Returns the table cell at the given \a row and \a column in the table. | - |
588 | | - |
589 | \sa columns(), rows() | - |
590 | */ | - |
591 | QTextTableCell QTextTable::cellAt(int row, int col) const | - |
592 | { | - |
593 | Q_D(const QTextTable); executed (the execution status of this line is deduced): const QTextTablePrivate * const d = d_func(); | - |
594 | if (d->dirty) evaluated: d->dirty yes Evaluation Count:60 | yes Evaluation Count:3443 |
| 60-3443 |
595 | d->update(); executed: d->update(); Execution Count:60 | 60 |
596 | | - |
597 | if (row < 0 || row >= d->nRows || col < 0 || col >= d->nCols) evaluated: row < 0 yes Evaluation Count:60 | yes Evaluation Count:3443 |
evaluated: row >= d->nRows yes Evaluation Count:57 | yes Evaluation Count:3386 |
evaluated: col < 0 yes Evaluation Count:42 | yes Evaluation Count:3344 |
evaluated: col >= d->nCols yes Evaluation Count:48 | yes Evaluation Count:3296 |
| 42-3443 |
598 | return QTextTableCell(); executed: return QTextTableCell(); Execution Count:207 | 207 |
599 | | - |
600 | return QTextTableCell(this, d->grid[row*d->nCols + col]); executed: return QTextTableCell(this, d->grid[row*d->nCols + col]); Execution Count:3296 | 3296 |
601 | } | - |
602 | | - |
603 | /*! | - |
604 | \overload | - |
605 | | - |
606 | Returns the table cell that contains the character at the given \a position | - |
607 | in the document. | - |
608 | */ | - |
609 | QTextTableCell QTextTable::cellAt(int position) const | - |
610 | { | - |
611 | Q_D(const QTextTable); executed (the execution status of this line is deduced): const QTextTablePrivate * const d = d_func(); | - |
612 | if (d->dirty) evaluated: d->dirty yes Evaluation Count:1 | yes Evaluation Count:782 |
| 1-782 |
613 | d->update(); executed: d->update(); Execution Count:1 | 1 |
614 | | - |
615 | uint pos = (uint)position; executed (the execution status of this line is deduced): uint pos = (uint)position; | - |
616 | const QTextDocumentPrivate::FragmentMap &map = d->pieceTable->fragmentMap(); executed (the execution status of this line is deduced): const QTextDocumentPrivate::FragmentMap &map = d->pieceTable->fragmentMap(); | - |
617 | if (position < 0 || map.position(d->fragment_start) >= pos || map.position(d->fragment_end) < pos) partially evaluated: position < 0 no Evaluation Count:0 | yes Evaluation Count:783 |
evaluated: map.position(d->fragment_start) >= pos yes Evaluation Count:1 | yes Evaluation Count:782 |
evaluated: map.position(d->fragment_end) < pos yes Evaluation Count:1 | yes Evaluation Count:781 |
| 0-783 |
618 | return QTextTableCell(); executed: return QTextTableCell(); Execution Count:2 | 2 |
619 | | - |
620 | QFragmentFindHelper helper(position, map); executed (the execution status of this line is deduced): QFragmentFindHelper helper(position, map); | - |
621 | QList<int>::ConstIterator it = std::lower_bound(d->cells.begin(), d->cells.end(), helper); executed (the execution status of this line is deduced): QList<int>::ConstIterator it = std::lower_bound(d->cells.begin(), d->cells.end(), helper); | - |
622 | if (it != d->cells.begin()) partially evaluated: it != d->cells.begin() yes Evaluation Count:781 | no Evaluation Count:0 |
| 0-781 |
623 | --it; executed: --it; Execution Count:781 | 781 |
624 | | - |
625 | return QTextTableCell(this, *it); executed: return QTextTableCell(this, *it); Execution Count:781 | 781 |
626 | } | - |
627 | | - |
628 | /*! | - |
629 | \fn QTextTableCell QTextTable::cellAt(const QTextCursor &cursor) const | - |
630 | | - |
631 | \overload | - |
632 | | - |
633 | Returns the table cell containing the given \a cursor. | - |
634 | */ | - |
635 | QTextTableCell QTextTable::cellAt(const QTextCursor &c) const | - |
636 | { | - |
637 | return cellAt(c.position()); executed: return cellAt(c.position()); Execution Count:10 | 10 |
638 | } | - |
639 | | - |
640 | /*! | - |
641 | \fn void QTextTable::resize(int rows, int columns) | - |
642 | | - |
643 | Resizes the table to contain the required number of \a rows and \a columns. | - |
644 | | - |
645 | \sa insertRows(), insertColumns(), removeRows(), removeColumns() | - |
646 | */ | - |
647 | void QTextTable::resize(int rows, int cols) | - |
648 | { | - |
649 | Q_D(QTextTable); executed (the execution status of this line is deduced): QTextTablePrivate * const d = d_func(); | - |
650 | if (d->dirty) partially evaluated: d->dirty no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
651 | d->update(); never executed: d->update(); | 0 |
652 | | - |
653 | int nRows = this->rows(); executed (the execution status of this line is deduced): int nRows = this->rows(); | - |
654 | int nCols = this->columns(); executed (the execution status of this line is deduced): int nCols = this->columns(); | - |
655 | | - |
656 | if (rows == nRows && cols == nCols) partially evaluated: rows == nRows no Evaluation Count:0 | yes Evaluation Count:2 |
never evaluated: cols == nCols | 0-2 |
657 | return; | 0 |
658 | | - |
659 | d->pieceTable->beginEditBlock(); executed (the execution status of this line is deduced): d->pieceTable->beginEditBlock(); | - |
660 | | - |
661 | if (nCols < cols) evaluated: nCols < cols yes Evaluation Count:1 | yes Evaluation Count:1 |
| 1 |
662 | insertColumns(nCols, cols - nCols); executed: insertColumns(nCols, cols - nCols); Execution Count:1 | 1 |
663 | else if (nCols > cols) partially evaluated: nCols > cols yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
664 | removeColumns(cols, nCols - cols); executed: removeColumns(cols, nCols - cols); Execution Count:1 | 1 |
665 | | - |
666 | if (nRows < rows) evaluated: nRows < rows yes Evaluation Count:1 | yes Evaluation Count:1 |
| 1 |
667 | insertRows(nRows, rows-nRows); executed: insertRows(nRows, rows-nRows); Execution Count:1 | 1 |
668 | else if (nRows > rows) partially evaluated: nRows > rows yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
669 | removeRows(rows, nRows-rows); executed: removeRows(rows, nRows-rows); Execution Count:1 | 1 |
670 | | - |
671 | d->pieceTable->endEditBlock(); executed (the execution status of this line is deduced): d->pieceTable->endEditBlock(); | - |
672 | } executed: } Execution Count:2 | 2 |
673 | | - |
674 | /*! | - |
675 | \fn void QTextTable::insertRows(int index, int rows) | - |
676 | | - |
677 | Inserts a number of \a rows before the row with the specified \a index. | - |
678 | | - |
679 | \sa resize(), insertColumns(), removeRows(), removeColumns(), appendRows(), appendColumns() | - |
680 | */ | - |
681 | void QTextTable::insertRows(int pos, int num) | - |
682 | { | - |
683 | Q_D(QTextTable); executed (the execution status of this line is deduced): QTextTablePrivate * const d = d_func(); | - |
684 | if (num <= 0) partially evaluated: num <= 0 no Evaluation Count:0 | yes Evaluation Count:12 |
| 0-12 |
685 | return; | 0 |
686 | | - |
687 | if (d->dirty) evaluated: d->dirty yes Evaluation Count:1 | yes Evaluation Count:11 |
| 1-11 |
688 | d->update(); executed: d->update(); Execution Count:1 | 1 |
689 | | - |
690 | if (pos > d->nRows || pos < 0) partially evaluated: pos > d->nRows no Evaluation Count:0 | yes Evaluation Count:12 |
evaluated: pos < 0 yes Evaluation Count:1 | yes Evaluation Count:11 |
| 0-12 |
691 | pos = d->nRows; executed: pos = d->nRows; Execution Count:1 | 1 |
692 | | - |
693 | // qDebug() << "-------- insertRows" << pos << num; | - |
694 | QTextDocumentPrivate *p = d->pieceTable; executed (the execution status of this line is deduced): QTextDocumentPrivate *p = d->pieceTable; | - |
695 | QTextFormatCollection *c = p->formatCollection(); executed (the execution status of this line is deduced): QTextFormatCollection *c = p->formatCollection(); | - |
696 | p->beginEditBlock(); executed (the execution status of this line is deduced): p->beginEditBlock(); | - |
697 | | - |
698 | int extended = 0; executed (the execution status of this line is deduced): int extended = 0; | - |
699 | int insert_before = 0; executed (the execution status of this line is deduced): int insert_before = 0; | - |
700 | if (pos > 0 && pos < d->nRows) { evaluated: pos > 0 yes Evaluation Count:10 | yes Evaluation Count:2 |
evaluated: pos < d->nRows yes Evaluation Count:2 | yes Evaluation Count:8 |
| 2-10 |
701 | for (int i = 0; i < d->nCols; ++i) { evaluated: i < d->nCols yes Evaluation Count:4 | yes Evaluation Count:2 |
| 2-4 |
702 | int cell = d->grid[pos*d->nCols + i]; executed (the execution status of this line is deduced): int cell = d->grid[pos*d->nCols + i]; | - |
703 | if (cell == d->grid[(pos-1)*d->nCols+i]) { partially evaluated: cell == d->grid[(pos-1)*d->nCols+i] no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
704 | // cell spans the insertion place, extend it | - |
705 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); never executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); | - |
706 | QTextCharFormat fmt = c->charFormat(it->format); never executed (the execution status of this line is deduced): QTextCharFormat fmt = c->charFormat(it->format); | - |
707 | fmt.setTableCellRowSpan(fmt.tableCellRowSpan() + num); never executed (the execution status of this line is deduced): fmt.setTableCellRowSpan(fmt.tableCellRowSpan() + num); | - |
708 | p->setCharFormat(it.position(), 1, fmt); never executed (the execution status of this line is deduced): p->setCharFormat(it.position(), 1, fmt); | - |
709 | extended++; never executed (the execution status of this line is deduced): extended++; | - |
710 | } else if (!insert_before) { never executed: } evaluated: !insert_before yes Evaluation Count:2 | yes Evaluation Count:2 |
| 0-2 |
711 | insert_before = cell; executed (the execution status of this line is deduced): insert_before = cell; | - |
712 | } executed: } Execution Count:2 | 2 |
713 | } | - |
714 | } else { executed: } Execution Count:2 | 2 |
715 | insert_before = (pos == 0 ? d->grid[0] : d->fragment_end); evaluated: pos == 0 yes Evaluation Count:2 | yes Evaluation Count:8 |
| 2-8 |
716 | } executed: } Execution Count:10 | 10 |
717 | if (extended < d->nCols) { partially evaluated: extended < d->nCols yes Evaluation Count:12 | no Evaluation Count:0 |
| 0-12 |
718 | Q_ASSERT(insert_before); executed (the execution status of this line is deduced): qt_noop(); | - |
719 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), insert_before); executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), insert_before); | - |
720 | QTextCharFormat fmt = c->charFormat(it->format); executed (the execution status of this line is deduced): QTextCharFormat fmt = c->charFormat(it->format); | - |
721 | fmt.setTableCellRowSpan(1); executed (the execution status of this line is deduced): fmt.setTableCellRowSpan(1); | - |
722 | fmt.setTableCellColumnSpan(1); executed (the execution status of this line is deduced): fmt.setTableCellColumnSpan(1); | - |
723 | Q_ASSERT(fmt.objectIndex() == objectIndex()); executed (the execution status of this line is deduced): qt_noop(); | - |
724 | int pos = it.position(); executed (the execution status of this line is deduced): int pos = it.position(); | - |
725 | int cfmt = p->formatCollection()->indexForFormat(fmt); executed (the execution status of this line is deduced): int cfmt = p->formatCollection()->indexForFormat(fmt); | - |
726 | int bfmt = p->formatCollection()->indexForFormat(QTextBlockFormat()); executed (the execution status of this line is deduced): int bfmt = p->formatCollection()->indexForFormat(QTextBlockFormat()); | - |
727 | // qDebug("inserting %d cells, nCols=%d extended=%d", num*(d->nCols-extended), d->nCols, extended); | - |
728 | for (int i = 0; i < num*(d->nCols-extended); ++i) evaluated: i < num*(d->nCols-extended) yes Evaluation Count:41 | yes Evaluation Count:12 |
| 12-41 |
729 | p->insertBlock(QTextBeginningOfFrame, pos, bfmt, cfmt, QTextUndoCommand::MoveCursor); executed: p->insertBlock(QChar(0xfdd0), pos, bfmt, cfmt, QTextUndoCommand::MoveCursor); Execution Count:41 | 41 |
730 | } executed: } Execution Count:12 | 12 |
731 | | - |
732 | // qDebug() << "-------- end insertRows" << pos << num; | - |
733 | p->endEditBlock(); executed (the execution status of this line is deduced): p->endEditBlock(); | - |
734 | } executed: } Execution Count:12 | 12 |
735 | | - |
736 | /*! | - |
737 | \fn void QTextTable::insertColumns(int index, int columns) | - |
738 | | - |
739 | Inserts a number of \a columns before the column with the specified \a index. | - |
740 | | - |
741 | \sa insertRows(), resize(), removeRows(), removeColumns(), appendRows(), appendColumns() | - |
742 | */ | - |
743 | void QTextTable::insertColumns(int pos, int num) | - |
744 | { | - |
745 | Q_D(QTextTable); executed (the execution status of this line is deduced): QTextTablePrivate * const d = d_func(); | - |
746 | if (num <= 0) partially evaluated: num <= 0 no Evaluation Count:0 | yes Evaluation Count:16 |
| 0-16 |
747 | return; | 0 |
748 | | - |
749 | if (d->dirty) evaluated: d->dirty yes Evaluation Count:1 | yes Evaluation Count:15 |
| 1-15 |
750 | d->update(); executed: d->update(); Execution Count:1 | 1 |
751 | | - |
752 | if (pos > d->nCols || pos < 0) partially evaluated: pos > d->nCols no Evaluation Count:0 | yes Evaluation Count:16 |
partially evaluated: pos < 0 no Evaluation Count:0 | yes Evaluation Count:16 |
| 0-16 |
753 | pos = d->nCols; never executed: pos = d->nCols; | 0 |
754 | | - |
755 | // qDebug() << "-------- insertCols" << pos << num; | - |
756 | QTextDocumentPrivate *p = d->pieceTable; executed (the execution status of this line is deduced): QTextDocumentPrivate *p = d->pieceTable; | - |
757 | QTextFormatCollection *c = p->formatCollection(); executed (the execution status of this line is deduced): QTextFormatCollection *c = p->formatCollection(); | - |
758 | p->beginEditBlock(); executed (the execution status of this line is deduced): p->beginEditBlock(); | - |
759 | | - |
760 | QList<int> extendedSpans; executed (the execution status of this line is deduced): QList<int> extendedSpans; | - |
761 | for (int i = 0; i < d->nRows; ++i) { evaluated: i < d->nRows yes Evaluation Count:46 | yes Evaluation Count:16 |
| 16-46 |
762 | int cell; executed (the execution status of this line is deduced): int cell; | - |
763 | if (i == d->nRows - 1 && pos == d->nCols) { evaluated: i == d->nRows - 1 yes Evaluation Count:16 | yes Evaluation Count:30 |
evaluated: pos == d->nCols yes Evaluation Count:5 | yes Evaluation Count:11 |
| 5-30 |
764 | cell = d->fragment_end; executed (the execution status of this line is deduced): cell = d->fragment_end; | - |
765 | } else { executed: } Execution Count:5 | 5 |
766 | int logicalGridIndexBeforePosition = pos > 0 evaluated: pos > 0 yes Evaluation Count:39 | yes Evaluation Count:2 |
| 2-39 |
767 | ? d->findCellIndex(d->grid[i*d->nCols + pos - 1]) executed (the execution status of this line is deduced): ? d->findCellIndex(d->grid[i*d->nCols + pos - 1]) | - |
768 | : -1; executed (the execution status of this line is deduced): : -1; | - |
769 | | - |
770 | // Search for the logical insertion point by skipping past cells which are not the first | - |
771 | // cell in a rowspan. This means any cell for which the logical grid index is | - |
772 | // less than the logical cell index of the cell before the insertion. | - |
773 | int logicalGridIndex; executed (the execution status of this line is deduced): int logicalGridIndex; | - |
774 | int gridArrayOffset = i*d->nCols + pos; executed (the execution status of this line is deduced): int gridArrayOffset = i*d->nCols + pos; | - |
775 | do { | - |
776 | cell = d->grid[gridArrayOffset]; executed (the execution status of this line is deduced): cell = d->grid[gridArrayOffset]; | - |
777 | logicalGridIndex = d->findCellIndex(cell); executed (the execution status of this line is deduced): logicalGridIndex = d->findCellIndex(cell); | - |
778 | gridArrayOffset++; executed (the execution status of this line is deduced): gridArrayOffset++; | - |
779 | } while (logicalGridIndex < logicalGridIndexBeforePosition executed: } Execution Count:64 evaluated: logicalGridIndex < logicalGridIndexBeforePosition yes Evaluation Count:26 | yes Evaluation Count:38 |
| 26-64 |
780 | && gridArrayOffset < d->nRows*d->nCols); evaluated: gridArrayOffset < d->nRows*d->nCols yes Evaluation Count:23 | yes Evaluation Count:3 |
| 3-23 |
781 | | - |
782 | if (logicalGridIndex < logicalGridIndexBeforePosition evaluated: logicalGridIndex < logicalGridIndexBeforePosition yes Evaluation Count:3 | yes Evaluation Count:38 |
| 3-38 |
783 | && gridArrayOffset == d->nRows*d->nCols) partially evaluated: gridArrayOffset == d->nRows*d->nCols yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
784 | cell = d->fragment_end; executed: cell = d->fragment_end; Execution Count:3 | 3 |
785 | } executed: } Execution Count:41 | 41 |
786 | | - |
787 | if (pos > 0 && pos < d->nCols && cell == d->grid[i*d->nCols + pos - 1]) { evaluated: pos > 0 yes Evaluation Count:44 | yes Evaluation Count:2 |
evaluated: pos < d->nCols yes Evaluation Count:31 | yes Evaluation Count:13 |
evaluated: cell == d->grid[i*d->nCols + pos - 1] yes Evaluation Count:2 | yes Evaluation Count:29 |
| 2-44 |
788 | // cell spans the insertion place, extend it | - |
789 | if (!extendedSpans.contains(cell)) { partially evaluated: !extendedSpans.contains(cell) yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
790 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); | - |
791 | QTextCharFormat fmt = c->charFormat(it->format); executed (the execution status of this line is deduced): QTextCharFormat fmt = c->charFormat(it->format); | - |
792 | fmt.setTableCellColumnSpan(fmt.tableCellColumnSpan() + num); executed (the execution status of this line is deduced): fmt.setTableCellColumnSpan(fmt.tableCellColumnSpan() + num); | - |
793 | p->setCharFormat(it.position(), 1, fmt); executed (the execution status of this line is deduced): p->setCharFormat(it.position(), 1, fmt); | - |
794 | d->dirty = true; executed (the execution status of this line is deduced): d->dirty = true; | - |
795 | extendedSpans << cell; executed (the execution status of this line is deduced): extendedSpans << cell; | - |
796 | } executed: } Execution Count:2 | 2 |
797 | } else { executed: } Execution Count:2 | 2 |
798 | /* If the next cell is spanned from the row above, we need to find the right position | - |
799 | to insert to */ | - |
800 | if (i > 0 && pos < d->nCols && cell == d->grid[(i-1) * d->nCols + pos]) { evaluated: i > 0 yes Evaluation Count:29 | yes Evaluation Count:15 |
evaluated: pos < d->nCols yes Evaluation Count:21 | yes Evaluation Count:8 |
partially evaluated: cell == d->grid[(i-1) * d->nCols + pos] no Evaluation Count:0 | yes Evaluation Count:21 |
| 0-29 |
801 | int gridIndex = i*d->nCols + pos; never executed (the execution status of this line is deduced): int gridIndex = i*d->nCols + pos; | - |
802 | const int gridEnd = d->nRows * d->nCols - 1; never executed (the execution status of this line is deduced): const int gridEnd = d->nRows * d->nCols - 1; | - |
803 | while (gridIndex < gridEnd && cell == d->grid[gridIndex]) { never evaluated: gridIndex < gridEnd never evaluated: cell == d->grid[gridIndex] | 0 |
804 | ++gridIndex; never executed (the execution status of this line is deduced): ++gridIndex; | - |
805 | } | 0 |
806 | if (gridIndex == gridEnd) never evaluated: gridIndex == gridEnd | 0 |
807 | cell = d->fragment_end; never executed: cell = d->fragment_end; | 0 |
808 | else | - |
809 | cell = d->grid[gridIndex]; never executed: cell = d->grid[gridIndex]; | 0 |
810 | } | - |
811 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); | - |
812 | QTextCharFormat fmt = c->charFormat(it->format); executed (the execution status of this line is deduced): QTextCharFormat fmt = c->charFormat(it->format); | - |
813 | fmt.setTableCellRowSpan(1); executed (the execution status of this line is deduced): fmt.setTableCellRowSpan(1); | - |
814 | fmt.setTableCellColumnSpan(1); executed (the execution status of this line is deduced): fmt.setTableCellColumnSpan(1); | - |
815 | Q_ASSERT(fmt.objectIndex() == objectIndex()); executed (the execution status of this line is deduced): qt_noop(); | - |
816 | int position = it.position(); executed (the execution status of this line is deduced): int position = it.position(); | - |
817 | int cfmt = p->formatCollection()->indexForFormat(fmt); executed (the execution status of this line is deduced): int cfmt = p->formatCollection()->indexForFormat(fmt); | - |
818 | int bfmt = p->formatCollection()->indexForFormat(QTextBlockFormat()); executed (the execution status of this line is deduced): int bfmt = p->formatCollection()->indexForFormat(QTextBlockFormat()); | - |
819 | for (int i = 0; i < num; ++i) evaluated: i < num yes Evaluation Count:54 | yes Evaluation Count:44 |
| 44-54 |
820 | p->insertBlock(QTextBeginningOfFrame, position, bfmt, cfmt, QTextUndoCommand::MoveCursor); executed: p->insertBlock(QChar(0xfdd0), position, bfmt, cfmt, QTextUndoCommand::MoveCursor); Execution Count:54 | 54 |
821 | } executed: } Execution Count:44 | 44 |
822 | } | - |
823 | | - |
824 | QTextTableFormat tfmt = format(); executed (the execution status of this line is deduced): QTextTableFormat tfmt = format(); | - |
825 | tfmt.setColumns(tfmt.columns()+num); executed (the execution status of this line is deduced): tfmt.setColumns(tfmt.columns()+num); | - |
826 | QVector<QTextLength> columnWidths = tfmt.columnWidthConstraints(); executed (the execution status of this line is deduced): QVector<QTextLength> columnWidths = tfmt.columnWidthConstraints(); | - |
827 | if (! columnWidths.isEmpty()) { partially evaluated: ! columnWidths.isEmpty() no Evaluation Count:0 | yes Evaluation Count:16 |
| 0-16 |
828 | for (int i = num; i > 0; --i) | 0 |
829 | columnWidths.insert(pos, columnWidths[qMax(0, pos-1)]); never executed: columnWidths.insert(pos, columnWidths[qMax(0, pos-1)]); | 0 |
830 | } | 0 |
831 | tfmt.setColumnWidthConstraints (columnWidths); executed (the execution status of this line is deduced): tfmt.setColumnWidthConstraints (columnWidths); | - |
832 | QTextObject::setFormat(tfmt); executed (the execution status of this line is deduced): QTextObject::setFormat(tfmt); | - |
833 | | - |
834 | // qDebug() << "-------- end insertCols" << pos << num; | - |
835 | p->endEditBlock(); executed (the execution status of this line is deduced): p->endEditBlock(); | - |
836 | } executed: } Execution Count:16 | 16 |
837 | | - |
838 | /*! | - |
839 | \since 4.5 | - |
840 | Appends \a count rows at the bottom of the table. | - |
841 | | - |
842 | \sa insertColumns(), insertRows(), resize(), removeRows(), removeColumns(), appendColumns() | - |
843 | */ | - |
844 | void QTextTable::appendRows(int count) | - |
845 | { | - |
846 | insertRows(rows(), count); executed (the execution status of this line is deduced): insertRows(rows(), count); | - |
847 | } executed: } Execution Count:3 | 3 |
848 | | - |
849 | /*! | - |
850 | \since 4.5 | - |
851 | Appends \a count columns at the right side of the table. | - |
852 | | - |
853 | \sa insertColumns(), insertRows(), resize(), removeRows(), removeColumns(), appendRows() | - |
854 | */ | - |
855 | void QTextTable::appendColumns(int count) | - |
856 | { | - |
857 | insertColumns(columns(), count); executed (the execution status of this line is deduced): insertColumns(columns(), count); | - |
858 | } executed: } Execution Count:2 | 2 |
859 | | - |
860 | /*! | - |
861 | \fn void QTextTable::removeRows(int index, int rows) | - |
862 | | - |
863 | Removes a number of \a rows starting with the row at the specified \a index. | - |
864 | | - |
865 | \sa insertRows(), insertColumns(), resize(), removeColumns(), appendRows(), appendColumns() | - |
866 | */ | - |
867 | void QTextTable::removeRows(int pos, int num) | - |
868 | { | - |
869 | Q_D(QTextTable); executed (the execution status of this line is deduced): QTextTablePrivate * const d = d_func(); | - |
870 | // qDebug() << "-------- removeRows" << pos << num; | - |
871 | | - |
872 | if (num <= 0 || pos < 0) partially evaluated: num <= 0 no Evaluation Count:0 | yes Evaluation Count:13 |
partially evaluated: pos < 0 no Evaluation Count:0 | yes Evaluation Count:13 |
| 0-13 |
873 | return; | 0 |
874 | if (d->dirty) evaluated: d->dirty yes Evaluation Count:2 | yes Evaluation Count:11 |
| 2-11 |
875 | d->update(); executed: d->update(); Execution Count:2 | 2 |
876 | if (pos >= d->nRows) partially evaluated: pos >= d->nRows no Evaluation Count:0 | yes Evaluation Count:13 |
| 0-13 |
877 | return; | 0 |
878 | if (pos+num > d->nRows) partially evaluated: pos+num > d->nRows no Evaluation Count:0 | yes Evaluation Count:13 |
| 0-13 |
879 | num = d->nRows - pos; never executed: num = d->nRows - pos; | 0 |
880 | | - |
881 | QTextDocumentPrivate *p = d->pieceTable; executed (the execution status of this line is deduced): QTextDocumentPrivate *p = d->pieceTable; | - |
882 | QTextFormatCollection *collection = p->formatCollection(); executed (the execution status of this line is deduced): QTextFormatCollection *collection = p->formatCollection(); | - |
883 | p->beginEditBlock(); executed (the execution status of this line is deduced): p->beginEditBlock(); | - |
884 | | - |
885 | // delete whole table? | - |
886 | if (pos == 0 && num == d->nRows) { evaluated: pos == 0 yes Evaluation Count:3 | yes Evaluation Count:10 |
evaluated: num == d->nRows yes Evaluation Count:1 | yes Evaluation Count:2 |
| 1-10 |
887 | const int pos = p->fragmentMap().position(d->fragment_start); executed (the execution status of this line is deduced): const int pos = p->fragmentMap().position(d->fragment_start); | - |
888 | p->remove(pos, p->fragmentMap().position(d->fragment_end) - pos + 1); executed (the execution status of this line is deduced): p->remove(pos, p->fragmentMap().position(d->fragment_end) - pos + 1); | - |
889 | p->endEditBlock(); executed (the execution status of this line is deduced): p->endEditBlock(); | - |
890 | return; executed: return; Execution Count:1 | 1 |
891 | } | - |
892 | | - |
893 | p->aboutToRemoveCell(cellAt(pos, 0).firstPosition(), cellAt(pos + num - 1, d->nCols - 1).lastPosition()); executed (the execution status of this line is deduced): p->aboutToRemoveCell(cellAt(pos, 0).firstPosition(), cellAt(pos + num - 1, d->nCols - 1).lastPosition()); | - |
894 | | - |
895 | QList<int> touchedCells; executed (the execution status of this line is deduced): QList<int> touchedCells; | - |
896 | for (int r = pos; r < pos + num; ++r) { evaluated: r < pos + num yes Evaluation Count:13 | yes Evaluation Count:12 |
| 12-13 |
897 | for (int c = 0; c < d->nCols; ++c) { evaluated: c < d->nCols yes Evaluation Count:40 | yes Evaluation Count:13 |
| 13-40 |
898 | int cell = d->grid[r*d->nCols + c]; executed (the execution status of this line is deduced): int cell = d->grid[r*d->nCols + c]; | - |
899 | if (touchedCells.contains(cell)) evaluated: touchedCells.contains(cell) yes Evaluation Count:1 | yes Evaluation Count:39 |
| 1-39 |
900 | continue; executed: continue; Execution Count:1 | 1 |
901 | touchedCells << cell; executed (the execution status of this line is deduced): touchedCells << cell; | - |
902 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); | - |
903 | QTextCharFormat fmt = collection->charFormat(it->format); executed (the execution status of this line is deduced): QTextCharFormat fmt = collection->charFormat(it->format); | - |
904 | int span = fmt.tableCellRowSpan(); executed (the execution status of this line is deduced): int span = fmt.tableCellRowSpan(); | - |
905 | if (span > 1) { partially evaluated: span > 1 no Evaluation Count:0 | yes Evaluation Count:39 |
| 0-39 |
906 | fmt.setTableCellRowSpan(span - 1); never executed (the execution status of this line is deduced): fmt.setTableCellRowSpan(span - 1); | - |
907 | p->setCharFormat(it.position(), 1, fmt); never executed (the execution status of this line is deduced): p->setCharFormat(it.position(), 1, fmt); | - |
908 | } else { | 0 |
909 | // remove cell | - |
910 | int index = d->cells.indexOf(cell) + 1; executed (the execution status of this line is deduced): int index = d->cells.indexOf(cell) + 1; | - |
911 | int f_end = index < d->cells.size() ? d->cells.at(index) : d->fragment_end; evaluated: index < d->cells.size() yes Evaluation Count:35 | yes Evaluation Count:4 |
| 4-35 |
912 | p->remove(it.position(), p->fragmentMap().position(f_end) - it.position()); executed (the execution status of this line is deduced): p->remove(it.position(), p->fragmentMap().position(f_end) - it.position()); | - |
913 | } executed: } Execution Count:39 | 39 |
914 | } | - |
915 | } executed: } Execution Count:13 | 13 |
916 | | - |
917 | p->endEditBlock(); executed (the execution status of this line is deduced): p->endEditBlock(); | - |
918 | // qDebug() << "-------- end removeRows" << pos << num; | - |
919 | } executed: } Execution Count:12 | 12 |
920 | | - |
921 | /*! | - |
922 | \fn void QTextTable::removeColumns(int index, int columns) | - |
923 | | - |
924 | Removes a number of \a columns starting with the column at the specified | - |
925 | \a index. | - |
926 | | - |
927 | \sa insertRows(), insertColumns(), removeRows(), resize(), appendRows(), appendColumns() | - |
928 | */ | - |
929 | void QTextTable::removeColumns(int pos, int num) | - |
930 | { | - |
931 | Q_D(QTextTable); executed (the execution status of this line is deduced): QTextTablePrivate * const d = d_func(); | - |
932 | // qDebug() << "-------- removeCols" << pos << num; | - |
933 | | - |
934 | if (num <= 0 || pos < 0) partially evaluated: num <= 0 no Evaluation Count:0 | yes Evaluation Count:14 |
partially evaluated: pos < 0 no Evaluation Count:0 | yes Evaluation Count:14 |
| 0-14 |
935 | return; | 0 |
936 | if (d->dirty) evaluated: d->dirty yes Evaluation Count:1 | yes Evaluation Count:13 |
| 1-13 |
937 | d->update(); executed: d->update(); Execution Count:1 | 1 |
938 | if (pos >= d->nCols) partially evaluated: pos >= d->nCols no Evaluation Count:0 | yes Evaluation Count:14 |
| 0-14 |
939 | return; | 0 |
940 | if (pos + num > d->nCols) partially evaluated: pos + num > d->nCols no Evaluation Count:0 | yes Evaluation Count:14 |
| 0-14 |
941 | pos = d->nCols - num; never executed: pos = d->nCols - num; | 0 |
942 | | - |
943 | QTextDocumentPrivate *p = d->pieceTable; executed (the execution status of this line is deduced): QTextDocumentPrivate *p = d->pieceTable; | - |
944 | QTextFormatCollection *collection = p->formatCollection(); executed (the execution status of this line is deduced): QTextFormatCollection *collection = p->formatCollection(); | - |
945 | p->beginEditBlock(); executed (the execution status of this line is deduced): p->beginEditBlock(); | - |
946 | | - |
947 | // delete whole table? | - |
948 | if (pos == 0 && num == d->nCols) { evaluated: pos == 0 yes Evaluation Count:5 | yes Evaluation Count:9 |
evaluated: num == d->nCols yes Evaluation Count:1 | yes Evaluation Count:4 |
| 1-9 |
949 | const int pos = p->fragmentMap().position(d->fragment_start); executed (the execution status of this line is deduced): const int pos = p->fragmentMap().position(d->fragment_start); | - |
950 | p->remove(pos, p->fragmentMap().position(d->fragment_end) - pos + 1); executed (the execution status of this line is deduced): p->remove(pos, p->fragmentMap().position(d->fragment_end) - pos + 1); | - |
951 | p->endEditBlock(); executed (the execution status of this line is deduced): p->endEditBlock(); | - |
952 | return; executed: return; Execution Count:1 | 1 |
953 | } | - |
954 | | - |
955 | p->aboutToRemoveCell(cellAt(0, pos).firstPosition(), cellAt(d->nRows - 1, pos + num - 1).lastPosition()); executed (the execution status of this line is deduced): p->aboutToRemoveCell(cellAt(0, pos).firstPosition(), cellAt(d->nRows - 1, pos + num - 1).lastPosition()); | - |
956 | | - |
957 | QList<int> touchedCells; executed (the execution status of this line is deduced): QList<int> touchedCells; | - |
958 | for (int r = 0; r < d->nRows; ++r) { evaluated: r < d->nRows yes Evaluation Count:34 | yes Evaluation Count:13 |
| 13-34 |
959 | for (int c = pos; c < pos + num; ++c) { evaluated: c < pos + num yes Evaluation Count:44 | yes Evaluation Count:34 |
| 34-44 |
960 | int cell = d->grid[r*d->nCols + c]; executed (the execution status of this line is deduced): int cell = d->grid[r*d->nCols + c]; | - |
961 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); | - |
962 | QTextCharFormat fmt = collection->charFormat(it->format); executed (the execution status of this line is deduced): QTextCharFormat fmt = collection->charFormat(it->format); | - |
963 | int span = fmt.tableCellColumnSpan(); executed (the execution status of this line is deduced): int span = fmt.tableCellColumnSpan(); | - |
964 | if (touchedCells.contains(cell) && span <= 1) evaluated: touchedCells.contains(cell) yes Evaluation Count:3 | yes Evaluation Count:41 |
evaluated: span <= 1 yes Evaluation Count:1 | yes Evaluation Count:2 |
| 1-41 |
965 | continue; executed: continue; Execution Count:1 | 1 |
966 | touchedCells << cell; executed (the execution status of this line is deduced): touchedCells << cell; | - |
967 | | - |
968 | if (span > 1) { evaluated: span > 1 yes Evaluation Count:4 | yes Evaluation Count:39 |
| 4-39 |
969 | fmt.setTableCellColumnSpan(span - 1); executed (the execution status of this line is deduced): fmt.setTableCellColumnSpan(span - 1); | - |
970 | p->setCharFormat(it.position(), 1, fmt); executed (the execution status of this line is deduced): p->setCharFormat(it.position(), 1, fmt); | - |
971 | } else { executed: } Execution Count:4 | 4 |
972 | // remove cell | - |
973 | int index = d->cells.indexOf(cell) + 1; executed (the execution status of this line is deduced): int index = d->cells.indexOf(cell) + 1; | - |
974 | int f_end = index < d->cells.size() ? d->cells.at(index) : d->fragment_end; evaluated: index < d->cells.size() yes Evaluation Count:36 | yes Evaluation Count:3 |
| 3-36 |
975 | p->remove(it.position(), p->fragmentMap().position(f_end) - it.position()); executed (the execution status of this line is deduced): p->remove(it.position(), p->fragmentMap().position(f_end) - it.position()); | - |
976 | } executed: } Execution Count:39 | 39 |
977 | } | - |
978 | } executed: } Execution Count:34 | 34 |
979 | | - |
980 | QTextTableFormat tfmt = format(); executed (the execution status of this line is deduced): QTextTableFormat tfmt = format(); | - |
981 | tfmt.setColumns(tfmt.columns()-num); executed (the execution status of this line is deduced): tfmt.setColumns(tfmt.columns()-num); | - |
982 | QVector<QTextLength> columnWidths = tfmt.columnWidthConstraints(); executed (the execution status of this line is deduced): QVector<QTextLength> columnWidths = tfmt.columnWidthConstraints(); | - |
983 | if (columnWidths.count() > pos) { partially evaluated: columnWidths.count() > pos no Evaluation Count:0 | yes Evaluation Count:13 |
| 0-13 |
984 | columnWidths.remove(pos, num); never executed (the execution status of this line is deduced): columnWidths.remove(pos, num); | - |
985 | tfmt.setColumnWidthConstraints (columnWidths); never executed (the execution status of this line is deduced): tfmt.setColumnWidthConstraints (columnWidths); | - |
986 | } | 0 |
987 | QTextObject::setFormat(tfmt); executed (the execution status of this line is deduced): QTextObject::setFormat(tfmt); | - |
988 | | - |
989 | p->endEditBlock(); executed (the execution status of this line is deduced): p->endEditBlock(); | - |
990 | // qDebug() << "-------- end removeCols" << pos << num; | - |
991 | } executed: } Execution Count:13 | 13 |
992 | | - |
993 | /*! | - |
994 | \since 4.1 | - |
995 | | - |
996 | Merges the cell at the specified \a row and \a column with the adjacent cells | - |
997 | into one cell. The new cell will span \a numRows rows and \a numCols columns. | - |
998 | If \a numRows or \a numCols is less than the current number of rows or columns | - |
999 | the cell spans then this method does nothing. | - |
1000 | | - |
1001 | \sa splitCell() | - |
1002 | */ | - |
1003 | void QTextTable::mergeCells(int row, int column, int numRows, int numCols) | - |
1004 | { | - |
1005 | Q_D(QTextTable); executed (the execution status of this line is deduced): QTextTablePrivate * const d = d_func(); | - |
1006 | | - |
1007 | if (d->dirty) evaluated: d->dirty yes Evaluation Count:20 | yes Evaluation Count:36 |
| 20-36 |
1008 | d->update(); executed: d->update(); Execution Count:20 | 20 |
1009 | | - |
1010 | QTextDocumentPrivate *p = d->pieceTable; executed (the execution status of this line is deduced): QTextDocumentPrivate *p = d->pieceTable; | - |
1011 | QTextFormatCollection *fc = p->formatCollection(); executed (the execution status of this line is deduced): QTextFormatCollection *fc = p->formatCollection(); | - |
1012 | | - |
1013 | const QTextTableCell cell = cellAt(row, column); executed (the execution status of this line is deduced): const QTextTableCell cell = cellAt(row, column); | - |
1014 | if (!cell.isValid() || row != cell.row() || column != cell.column()) partially evaluated: !cell.isValid() no Evaluation Count:0 | yes Evaluation Count:56 |
partially evaluated: row != cell.row() no Evaluation Count:0 | yes Evaluation Count:56 |
partially evaluated: column != cell.column() no Evaluation Count:0 | yes Evaluation Count:56 |
| 0-56 |
1015 | return; | 0 |
1016 | | - |
1017 | QTextCharFormat fmt = cell.format(); executed (the execution status of this line is deduced): QTextCharFormat fmt = cell.format(); | - |
1018 | const int rowSpan = fmt.tableCellRowSpan(); executed (the execution status of this line is deduced): const int rowSpan = fmt.tableCellRowSpan(); | - |
1019 | const int colSpan = fmt.tableCellColumnSpan(); executed (the execution status of this line is deduced): const int colSpan = fmt.tableCellColumnSpan(); | - |
1020 | | - |
1021 | numRows = qMin(numRows, rows() - cell.row()); executed (the execution status of this line is deduced): numRows = qMin(numRows, rows() - cell.row()); | - |
1022 | numCols = qMin(numCols, columns() - cell.column()); executed (the execution status of this line is deduced): numCols = qMin(numCols, columns() - cell.column()); | - |
1023 | | - |
1024 | // nothing to merge? | - |
1025 | if (numRows < rowSpan || numCols < colSpan) evaluated: numRows < rowSpan yes Evaluation Count:1 | yes Evaluation Count:55 |
partially evaluated: numCols < colSpan no Evaluation Count:0 | yes Evaluation Count:55 |
| 0-55 |
1026 | return; executed: return; Execution Count:1 | 1 |
1027 | | - |
1028 | // check the edges of the merge rect to make sure no cell spans the edge | - |
1029 | for (int r = row; r < row + numRows; ++r) { evaluated: r < row + numRows yes Evaluation Count:97 | yes Evaluation Count:55 |
| 55-97 |
1030 | if (cellAt(r, column) == cellAt(r, column - 1)) partially evaluated: cellAt(r, column) == cellAt(r, column - 1) no Evaluation Count:0 | yes Evaluation Count:97 |
| 0-97 |
1031 | return; | 0 |
1032 | if (cellAt(r, column + numCols) == cellAt(r, column + numCols - 1)) partially evaluated: cellAt(r, column + numCols) == cellAt(r, column + numCols - 1) no Evaluation Count:0 | yes Evaluation Count:97 |
| 0-97 |
1033 | return; | 0 |
1034 | } executed: } Execution Count:97 | 97 |
1035 | | - |
1036 | for (int c = column; c < column + numCols; ++c) { evaluated: c < column + numCols yes Evaluation Count:106 | yes Evaluation Count:54 |
| 54-106 |
1037 | if (cellAt(row, c) == cellAt(row - 1, c)) partially evaluated: cellAt(row, c) == cellAt(row - 1, c) no Evaluation Count:0 | yes Evaluation Count:106 |
| 0-106 |
1038 | return; | 0 |
1039 | if (cellAt(row + numRows, c) == cellAt(row + numRows - 1, c)) evaluated: cellAt(row + numRows, c) == cellAt(row + numRows - 1, c) yes Evaluation Count:1 | yes Evaluation Count:105 |
| 1-105 |
1040 | return; executed: return; Execution Count:1 | 1 |
1041 | } executed: } Execution Count:105 | 105 |
1042 | | - |
1043 | p->beginEditBlock(); executed (the execution status of this line is deduced): p->beginEditBlock(); | - |
1044 | | - |
1045 | const int origCellPosition = cell.firstPosition() - 1; executed (the execution status of this line is deduced): const int origCellPosition = cell.firstPosition() - 1; | - |
1046 | | - |
1047 | const int cellFragment = d->grid[row * d->nCols + column]; executed (the execution status of this line is deduced): const int cellFragment = d->grid[row * d->nCols + column]; | - |
1048 | | - |
1049 | // find the position at which to insert the contents of the merged cells | - |
1050 | QFragmentFindHelper helper(origCellPosition, p->fragmentMap()); executed (the execution status of this line is deduced): QFragmentFindHelper helper(origCellPosition, p->fragmentMap()); | - |
1051 | QList<int>::Iterator it = qBinaryFind(d->cells.begin(), d->cells.end(), helper); executed (the execution status of this line is deduced): QList<int>::Iterator it = qBinaryFind(d->cells.begin(), d->cells.end(), helper); | - |
1052 | Q_ASSERT(it != d->cells.end()); executed (the execution status of this line is deduced): qt_noop(); | - |
1053 | Q_ASSERT(*it == cellFragment); executed (the execution status of this line is deduced): qt_noop(); | - |
1054 | const int insertCellIndex = it - d->cells.begin(); executed (the execution status of this line is deduced): const int insertCellIndex = it - d->cells.begin(); | - |
1055 | int insertFragment = d->cells.value(insertCellIndex + 1, d->fragment_end); executed (the execution status of this line is deduced): int insertFragment = d->cells.value(insertCellIndex + 1, d->fragment_end); | - |
1056 | uint insertPos = p->fragmentMap().position(insertFragment); executed (the execution status of this line is deduced): uint insertPos = p->fragmentMap().position(insertFragment); | - |
1057 | | - |
1058 | d->blockFragmentUpdates = true; executed (the execution status of this line is deduced): d->blockFragmentUpdates = true; | - |
1059 | | - |
1060 | bool rowHasText = cell.firstCursorPosition().block().length(); executed (the execution status of this line is deduced): bool rowHasText = cell.firstCursorPosition().block().length(); | - |
1061 | bool needsParagraph = rowHasText && colSpan == numCols; partially evaluated: rowHasText yes Evaluation Count:54 | no Evaluation Count:0 |
evaluated: colSpan == numCols yes Evaluation Count:20 | yes Evaluation Count:34 |
| 0-54 |
1062 | | - |
1063 | // find all cells that will be erased by the merge | - |
1064 | for (int r = row; r < row + numRows; ++r) { evaluated: r < row + numRows yes Evaluation Count:96 | yes Evaluation Count:54 |
| 54-96 |
1065 | int firstColumn = r < row + rowSpan ? column + colSpan : column; evaluated: r < row + rowSpan yes Evaluation Count:58 | yes Evaluation Count:38 |
| 38-58 |
1066 | | - |
1067 | // don't recompute the cell index for the first row | - |
1068 | int firstCellIndex = r == row ? insertCellIndex + 1 : -1; evaluated: r == row yes Evaluation Count:54 | yes Evaluation Count:42 |
| 42-54 |
1069 | int cellIndex = firstCellIndex; executed (the execution status of this line is deduced): int cellIndex = firstCellIndex; | - |
1070 | | - |
1071 | for (int c = firstColumn; c < column + numCols; ++c) { evaluated: c < column + numCols yes Evaluation Count:108 | yes Evaluation Count:96 |
| 96-108 |
1072 | const int fragment = d->grid[r * d->nCols + c]; executed (the execution status of this line is deduced): const int fragment = d->grid[r * d->nCols + c]; | - |
1073 | | - |
1074 | // already handled? | - |
1075 | if (fragment == cellFragment) evaluated: fragment == cellFragment yes Evaluation Count:2 | yes Evaluation Count:106 |
| 2-106 |
1076 | continue; executed: continue; Execution Count:2 | 2 |
1077 | | - |
1078 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment); executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment); | - |
1079 | uint pos = it.position(); executed (the execution status of this line is deduced): uint pos = it.position(); | - |
1080 | | - |
1081 | if (firstCellIndex == -1) { evaluated: firstCellIndex == -1 yes Evaluation Count:41 | yes Evaluation Count:65 |
| 41-65 |
1082 | QFragmentFindHelper helper(pos, p->fragmentMap()); executed (the execution status of this line is deduced): QFragmentFindHelper helper(pos, p->fragmentMap()); | - |
1083 | QList<int>::Iterator it = qBinaryFind(d->cells.begin(), d->cells.end(), helper); executed (the execution status of this line is deduced): QList<int>::Iterator it = qBinaryFind(d->cells.begin(), d->cells.end(), helper); | - |
1084 | Q_ASSERT(it != d->cells.end()); executed (the execution status of this line is deduced): qt_noop(); | - |
1085 | Q_ASSERT(*it == fragment); executed (the execution status of this line is deduced): qt_noop(); | - |
1086 | firstCellIndex = cellIndex = it - d->cells.begin(); executed (the execution status of this line is deduced): firstCellIndex = cellIndex = it - d->cells.begin(); | - |
1087 | } executed: } Execution Count:41 | 41 |
1088 | | - |
1089 | ++cellIndex; executed (the execution status of this line is deduced): ++cellIndex; | - |
1090 | | - |
1091 | QTextCharFormat fmt = fc->charFormat(it->format); executed (the execution status of this line is deduced): QTextCharFormat fmt = fc->charFormat(it->format); | - |
1092 | | - |
1093 | const int cellRowSpan = fmt.tableCellRowSpan(); executed (the execution status of this line is deduced): const int cellRowSpan = fmt.tableCellRowSpan(); | - |
1094 | const int cellColSpan = fmt.tableCellColumnSpan(); executed (the execution status of this line is deduced): const int cellColSpan = fmt.tableCellColumnSpan(); | - |
1095 | | - |
1096 | // update the grid for this cell | - |
1097 | for (int i = r; i < r + cellRowSpan; ++i) evaluated: i < r + cellRowSpan yes Evaluation Count:107 | yes Evaluation Count:106 |
| 106-107 |
1098 | for (int j = c; j < c + cellColSpan; ++j) evaluated: j < c + cellColSpan yes Evaluation Count:108 | yes Evaluation Count:107 |
| 107-108 |
1099 | d->grid[i * d->nCols + j] = cellFragment; executed: d->grid[i * d->nCols + j] = cellFragment; Execution Count:108 | 108 |
1100 | | - |
1101 | // erase the cell marker | - |
1102 | p->remove(pos, 1); executed (the execution status of this line is deduced): p->remove(pos, 1); | - |
1103 | | - |
1104 | const int nextFragment = d->cells.value(cellIndex, d->fragment_end); executed (the execution status of this line is deduced): const int nextFragment = d->cells.value(cellIndex, d->fragment_end); | - |
1105 | const uint nextPos = p->fragmentMap().position(nextFragment); executed (the execution status of this line is deduced): const uint nextPos = p->fragmentMap().position(nextFragment); | - |
1106 | | - |
1107 | Q_ASSERT(nextPos >= pos); executed (the execution status of this line is deduced): qt_noop(); | - |
1108 | | - |
1109 | // merge the contents of the cell (if not empty) | - |
1110 | if (nextPos > pos) { evaluated: nextPos > pos yes Evaluation Count:5 | yes Evaluation Count:101 |
| 5-101 |
1111 | if (needsParagraph) { evaluated: needsParagraph yes Evaluation Count:4 | yes Evaluation Count:1 |
| 1-4 |
1112 | needsParagraph = false; executed (the execution status of this line is deduced): needsParagraph = false; | - |
1113 | QTextCursor(p, insertPos++).insertBlock(); executed (the execution status of this line is deduced): QTextCursor(p, insertPos++).insertBlock(); | - |
1114 | p->move(pos + 1, insertPos, nextPos - pos); executed (the execution status of this line is deduced): p->move(pos + 1, insertPos, nextPos - pos); | - |
1115 | } else if (rowHasText) { executed: } Execution Count:4 partially evaluated: rowHasText yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-4 |
1116 | QTextCursor(p, insertPos++).insertText(QLatin1String(" ")); executed (the execution status of this line is deduced): QTextCursor(p, insertPos++).insertText(QLatin1String(" ")); | - |
1117 | p->move(pos + 1, insertPos, nextPos - pos); executed (the execution status of this line is deduced): p->move(pos + 1, insertPos, nextPos - pos); | - |
1118 | } else { executed: } Execution Count:1 | 1 |
1119 | p->move(pos, insertPos, nextPos - pos); never executed (the execution status of this line is deduced): p->move(pos, insertPos, nextPos - pos); | - |
1120 | } | 0 |
1121 | | - |
1122 | insertPos += nextPos - pos; executed (the execution status of this line is deduced): insertPos += nextPos - pos; | - |
1123 | rowHasText = true; executed (the execution status of this line is deduced): rowHasText = true; | - |
1124 | } executed: } Execution Count:5 | 5 |
1125 | } executed: } Execution Count:106 | 106 |
1126 | | - |
1127 | if (rowHasText) { evaluated: rowHasText yes Evaluation Count:58 | yes Evaluation Count:38 |
| 38-58 |
1128 | needsParagraph = true; executed (the execution status of this line is deduced): needsParagraph = true; | - |
1129 | rowHasText = false; executed (the execution status of this line is deduced): rowHasText = false; | - |
1130 | } executed: } Execution Count:58 | 58 |
1131 | | - |
1132 | // erase cells from last row | - |
1133 | if (firstCellIndex >= 0) { evaluated: firstCellIndex >= 0 yes Evaluation Count:95 | yes Evaluation Count:1 |
| 1-95 |
1134 | d->cellIndices.remove(firstCellIndex, cellIndex - firstCellIndex); executed (the execution status of this line is deduced): d->cellIndices.remove(firstCellIndex, cellIndex - firstCellIndex); | - |
1135 | d->cells.erase(d->cells.begin() + firstCellIndex, d->cells.begin() + cellIndex); executed (the execution status of this line is deduced): d->cells.erase(d->cells.begin() + firstCellIndex, d->cells.begin() + cellIndex); | - |
1136 | } executed: } Execution Count:95 | 95 |
1137 | } executed: } Execution Count:96 | 96 |
1138 | | - |
1139 | d->fragment_start = d->cells.first(); executed (the execution status of this line is deduced): d->fragment_start = d->cells.first(); | - |
1140 | | - |
1141 | fmt.setTableCellRowSpan(numRows); executed (the execution status of this line is deduced): fmt.setTableCellRowSpan(numRows); | - |
1142 | fmt.setTableCellColumnSpan(numCols); executed (the execution status of this line is deduced): fmt.setTableCellColumnSpan(numCols); | - |
1143 | p->setCharFormat(origCellPosition, 1, fmt); executed (the execution status of this line is deduced): p->setCharFormat(origCellPosition, 1, fmt); | - |
1144 | | - |
1145 | d->blockFragmentUpdates = false; executed (the execution status of this line is deduced): d->blockFragmentUpdates = false; | - |
1146 | d->dirty = false; executed (the execution status of this line is deduced): d->dirty = false; | - |
1147 | | - |
1148 | p->endEditBlock(); executed (the execution status of this line is deduced): p->endEditBlock(); | - |
1149 | } executed: } Execution Count:54 | 54 |
1150 | | - |
1151 | /*! | - |
1152 | \overload | - |
1153 | \since 4.1 | - |
1154 | | - |
1155 | Merges the cells selected by the provided \a cursor. | - |
1156 | | - |
1157 | \sa splitCell() | - |
1158 | */ | - |
1159 | void QTextTable::mergeCells(const QTextCursor &cursor) | - |
1160 | { | - |
1161 | if (!cursor.hasComplexSelection()) partially evaluated: !cursor.hasComplexSelection() no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
1162 | return; | 0 |
1163 | | - |
1164 | int firstRow, numRows, firstColumn, numColumns; executed (the execution status of this line is deduced): int firstRow, numRows, firstColumn, numColumns; | - |
1165 | cursor.selectedTableCells(&firstRow, &numRows, &firstColumn, &numColumns); executed (the execution status of this line is deduced): cursor.selectedTableCells(&firstRow, &numRows, &firstColumn, &numColumns); | - |
1166 | mergeCells(firstRow, firstColumn, numRows, numColumns); executed (the execution status of this line is deduced): mergeCells(firstRow, firstColumn, numRows, numColumns); | - |
1167 | } executed: } Execution Count:1 | 1 |
1168 | | - |
1169 | /*! | - |
1170 | \since 4.1 | - |
1171 | | - |
1172 | Splits the specified cell at \a row and \a column into an array of multiple | - |
1173 | cells with dimensions specified by \a numRows and \a numCols. | - |
1174 | | - |
1175 | \note It is only possible to split cells that span multiple rows or columns, such as rows | - |
1176 | that have been merged using mergeCells(). | - |
1177 | | - |
1178 | \sa mergeCells() | - |
1179 | */ | - |
1180 | void QTextTable::splitCell(int row, int column, int numRows, int numCols) | - |
1181 | { | - |
1182 | Q_D(QTextTable); executed (the execution status of this line is deduced): QTextTablePrivate * const d = d_func(); | - |
1183 | | - |
1184 | if (d->dirty) partially evaluated: d->dirty no Evaluation Count:0 | yes Evaluation Count:7 |
| 0-7 |
1185 | d->update(); never executed: d->update(); | 0 |
1186 | | - |
1187 | QTextDocumentPrivate *p = d->pieceTable; executed (the execution status of this line is deduced): QTextDocumentPrivate *p = d->pieceTable; | - |
1188 | QTextFormatCollection *c = p->formatCollection(); executed (the execution status of this line is deduced): QTextFormatCollection *c = p->formatCollection(); | - |
1189 | | - |
1190 | const QTextTableCell cell = cellAt(row, column); executed (the execution status of this line is deduced): const QTextTableCell cell = cellAt(row, column); | - |
1191 | if (!cell.isValid()) partially evaluated: !cell.isValid() no Evaluation Count:0 | yes Evaluation Count:7 |
| 0-7 |
1192 | return; | 0 |
1193 | row = cell.row(); executed (the execution status of this line is deduced): row = cell.row(); | - |
1194 | column = cell.column(); executed (the execution status of this line is deduced): column = cell.column(); | - |
1195 | | - |
1196 | QTextCharFormat fmt = cell.format(); executed (the execution status of this line is deduced): QTextCharFormat fmt = cell.format(); | - |
1197 | const int rowSpan = fmt.tableCellRowSpan(); executed (the execution status of this line is deduced): const int rowSpan = fmt.tableCellRowSpan(); | - |
1198 | const int colSpan = fmt.tableCellColumnSpan(); executed (the execution status of this line is deduced): const int colSpan = fmt.tableCellColumnSpan(); | - |
1199 | | - |
1200 | // nothing to split? | - |
1201 | if (numRows > rowSpan || numCols > colSpan) partially evaluated: numRows > rowSpan no Evaluation Count:0 | yes Evaluation Count:7 |
partially evaluated: numCols > colSpan no Evaluation Count:0 | yes Evaluation Count:7 |
| 0-7 |
1202 | return; | 0 |
1203 | | - |
1204 | p->beginEditBlock(); executed (the execution status of this line is deduced): p->beginEditBlock(); | - |
1205 | | - |
1206 | const int origCellPosition = cell.firstPosition() - 1; executed (the execution status of this line is deduced): const int origCellPosition = cell.firstPosition() - 1; | - |
1207 | | - |
1208 | QVarLengthArray<int> rowPositions(rowSpan); executed (the execution status of this line is deduced): QVarLengthArray<int> rowPositions(rowSpan); | - |
1209 | | - |
1210 | rowPositions[0] = cell.lastPosition(); executed (the execution status of this line is deduced): rowPositions[0] = cell.lastPosition(); | - |
1211 | | - |
1212 | for (int r = row + 1; r < row + rowSpan; ++r) { evaluated: r < row + rowSpan yes Evaluation Count:6 | yes Evaluation Count:7 |
| 6-7 |
1213 | // find the cell before which to insert the new cell markers | - |
1214 | int gridIndex = r * d->nCols + column; executed (the execution status of this line is deduced): int gridIndex = r * d->nCols + column; | - |
1215 | QVector<int>::iterator it = std::upper_bound(d->cellIndices.begin(), d->cellIndices.end(), gridIndex); executed (the execution status of this line is deduced): QVector<int>::iterator it = std::upper_bound(d->cellIndices.begin(), d->cellIndices.end(), gridIndex); | - |
1216 | int cellIndex = it - d->cellIndices.begin(); executed (the execution status of this line is deduced): int cellIndex = it - d->cellIndices.begin(); | - |
1217 | int fragment = d->cells.value(cellIndex, d->fragment_end); executed (the execution status of this line is deduced): int fragment = d->cells.value(cellIndex, d->fragment_end); | - |
1218 | rowPositions[r - row] = p->fragmentMap().position(fragment); executed (the execution status of this line is deduced): rowPositions[r - row] = p->fragmentMap().position(fragment); | - |
1219 | } executed: } Execution Count:6 | 6 |
1220 | | - |
1221 | fmt.setTableCellColumnSpan(1); executed (the execution status of this line is deduced): fmt.setTableCellColumnSpan(1); | - |
1222 | fmt.setTableCellRowSpan(1); executed (the execution status of this line is deduced): fmt.setTableCellRowSpan(1); | - |
1223 | const int fmtIndex = c->indexForFormat(fmt); executed (the execution status of this line is deduced): const int fmtIndex = c->indexForFormat(fmt); | - |
1224 | const int blockIndex = p->blockMap().find(cell.lastPosition())->format; executed (the execution status of this line is deduced): const int blockIndex = p->blockMap().find(cell.lastPosition())->format; | - |
1225 | | - |
1226 | int insertAdjustement = 0; executed (the execution status of this line is deduced): int insertAdjustement = 0; | - |
1227 | for (int i = 0; i < numRows; ++i) { evaluated: i < numRows yes Evaluation Count:8 | yes Evaluation Count:7 |
| 7-8 |
1228 | for (int c = 0; c < colSpan - numCols; ++c) evaluated: c < colSpan - numCols yes Evaluation Count:4 | yes Evaluation Count:8 |
| 4-8 |
1229 | p->insertBlock(QTextBeginningOfFrame, rowPositions[i] + insertAdjustement + c, blockIndex, fmtIndex); executed: p->insertBlock(QChar(0xfdd0), rowPositions[i] + insertAdjustement + c, blockIndex, fmtIndex); Execution Count:4 | 4 |
1230 | insertAdjustement += colSpan - numCols; executed (the execution status of this line is deduced): insertAdjustement += colSpan - numCols; | - |
1231 | } executed: } Execution Count:8 | 8 |
1232 | | - |
1233 | for (int i = numRows; i < rowSpan; ++i) { evaluated: i < rowSpan yes Evaluation Count:5 | yes Evaluation Count:7 |
| 5-7 |
1234 | for (int c = 0; c < colSpan; ++c) evaluated: c < colSpan yes Evaluation Count:7 | yes Evaluation Count:5 |
| 5-7 |
1235 | p->insertBlock(QTextBeginningOfFrame, rowPositions[i] + insertAdjustement + c, blockIndex, fmtIndex); executed: p->insertBlock(QChar(0xfdd0), rowPositions[i] + insertAdjustement + c, blockIndex, fmtIndex); Execution Count:7 | 7 |
1236 | insertAdjustement += colSpan; executed (the execution status of this line is deduced): insertAdjustement += colSpan; | - |
1237 | } executed: } Execution Count:5 | 5 |
1238 | | - |
1239 | fmt.setTableCellRowSpan(numRows); executed (the execution status of this line is deduced): fmt.setTableCellRowSpan(numRows); | - |
1240 | fmt.setTableCellColumnSpan(numCols); executed (the execution status of this line is deduced): fmt.setTableCellColumnSpan(numCols); | - |
1241 | p->setCharFormat(origCellPosition, 1, fmt); executed (the execution status of this line is deduced): p->setCharFormat(origCellPosition, 1, fmt); | - |
1242 | | - |
1243 | p->endEditBlock(); executed (the execution status of this line is deduced): p->endEditBlock(); | - |
1244 | } executed: } Execution Count:7 | 7 |
1245 | | - |
1246 | /*! | - |
1247 | Returns the number of rows in the table. | - |
1248 | | - |
1249 | \sa columns() | - |
1250 | */ | - |
1251 | int QTextTable::rows() const | - |
1252 | { | - |
1253 | Q_D(const QTextTable); executed (the execution status of this line is deduced): const QTextTablePrivate * const d = d_func(); | - |
1254 | if (d->dirty) evaluated: d->dirty yes Evaluation Count:133 | yes Evaluation Count:1592 |
| 133-1592 |
1255 | d->update(); executed: d->update(); Execution Count:133 | 133 |
1256 | | - |
1257 | return d->nRows; executed: return d->nRows; Execution Count:1725 | 1725 |
1258 | } | - |
1259 | | - |
1260 | /*! | - |
1261 | Returns the number of columns in the table. | - |
1262 | | - |
1263 | \sa rows() | - |
1264 | */ | - |
1265 | int QTextTable::columns() const | - |
1266 | { | - |
1267 | Q_D(const QTextTable); executed (the execution status of this line is deduced): const QTextTablePrivate * const d = d_func(); | - |
1268 | if (d->dirty) evaluated: d->dirty yes Evaluation Count:24 | yes Evaluation Count:504 |
| 24-504 |
1269 | d->update(); executed: d->update(); Execution Count:24 | 24 |
1270 | | - |
1271 | return d->nCols; executed: return d->nCols; Execution Count:528 | 528 |
1272 | } | - |
1273 | | - |
1274 | #if 0 | - |
1275 | void QTextTable::mergeCells(const QTextCursor &selection) | - |
1276 | { | - |
1277 | } | - |
1278 | #endif | - |
1279 | | - |
1280 | /*! | - |
1281 | \fn QTextCursor QTextTable::rowStart(const QTextCursor &cursor) const | - |
1282 | | - |
1283 | Returns a cursor pointing to the start of the row that contains the | - |
1284 | given \a cursor. | - |
1285 | | - |
1286 | \sa rowEnd() | - |
1287 | */ | - |
1288 | QTextCursor QTextTable::rowStart(const QTextCursor &c) const | - |
1289 | { | - |
1290 | Q_D(const QTextTable); never executed (the execution status of this line is deduced): const QTextTablePrivate * const d = d_func(); | - |
1291 | QTextTableCell cell = cellAt(c); never executed (the execution status of this line is deduced): QTextTableCell cell = cellAt(c); | - |
1292 | if (!cell.isValid()) never evaluated: !cell.isValid() | 0 |
1293 | return QTextCursor(); never executed: return QTextCursor(); | 0 |
1294 | | - |
1295 | int row = cell.row(); never executed (the execution status of this line is deduced): int row = cell.row(); | - |
1296 | QTextDocumentPrivate *p = d->pieceTable; never executed (the execution status of this line is deduced): QTextDocumentPrivate *p = d->pieceTable; | - |
1297 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), d->grid[row*d->nCols]); never executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), d->grid[row*d->nCols]); | - |
1298 | return QTextCursor(p, it.position()); never executed: return QTextCursor(p, it.position()); | 0 |
1299 | } | - |
1300 | | - |
1301 | /*! | - |
1302 | \fn QTextCursor QTextTable::rowEnd(const QTextCursor &cursor) const | - |
1303 | | - |
1304 | Returns a cursor pointing to the end of the row that contains the given | - |
1305 | \a cursor. | - |
1306 | | - |
1307 | \sa rowStart() | - |
1308 | */ | - |
1309 | QTextCursor QTextTable::rowEnd(const QTextCursor &c) const | - |
1310 | { | - |
1311 | Q_D(const QTextTable); never executed (the execution status of this line is deduced): const QTextTablePrivate * const d = d_func(); | - |
1312 | QTextTableCell cell = cellAt(c); never executed (the execution status of this line is deduced): QTextTableCell cell = cellAt(c); | - |
1313 | if (!cell.isValid()) never evaluated: !cell.isValid() | 0 |
1314 | return QTextCursor(); never executed: return QTextCursor(); | 0 |
1315 | | - |
1316 | int row = cell.row() + 1; never executed (the execution status of this line is deduced): int row = cell.row() + 1; | - |
1317 | int fragment = row < d->nRows ? d->grid[row*d->nCols] : d->fragment_end; never evaluated: row < d->nRows | 0 |
1318 | QTextDocumentPrivate *p = d->pieceTable; never executed (the execution status of this line is deduced): QTextDocumentPrivate *p = d->pieceTable; | - |
1319 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment); never executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment); | - |
1320 | return QTextCursor(p, it.position() - 1); never executed: return QTextCursor(p, it.position() - 1); | 0 |
1321 | } | - |
1322 | | - |
1323 | /*! | - |
1324 | \fn void QTextTable::setFormat(const QTextTableFormat &format) | - |
1325 | | - |
1326 | Sets the table's \a format. | - |
1327 | | - |
1328 | \sa format() | - |
1329 | */ | - |
1330 | void QTextTable::setFormat(const QTextTableFormat &format) | - |
1331 | { | - |
1332 | QTextTableFormat fmt = format; executed (the execution status of this line is deduced): QTextTableFormat fmt = format; | - |
1333 | // don't try to change the number of table columns from here | - |
1334 | fmt.setColumns(columns()); executed (the execution status of this line is deduced): fmt.setColumns(columns()); | - |
1335 | QTextObject::setFormat(fmt); executed (the execution status of this line is deduced): QTextObject::setFormat(fmt); | - |
1336 | } executed: } Execution Count:3 | 3 |
1337 | | - |
1338 | /*! | - |
1339 | \fn QTextTableFormat QTextTable::format() const | - |
1340 | | - |
1341 | Returns the table's format. | - |
1342 | | - |
1343 | \sa setFormat() | - |
1344 | */ | - |
1345 | | - |
1346 | QT_END_NAMESPACE | - |
1347 | | - |
| | |