Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | void QTextTableCell::setFormat(const QTextCharFormat &format) | - |
7 | { | - |
8 | QTextCharFormat fmt = format; | - |
9 | fmt.clearProperty(QTextFormat::ObjectIndex); | - |
10 | fmt.setObjectType(QTextFormat::TableCellObject); | - |
11 | QTextDocumentPrivate *p = table->docHandle(); | - |
12 | QTextDocumentPrivate::FragmentIterator frag(&p->fragmentMap(), fragment); | - |
13 | | - |
14 | QTextFormatCollection *c = p->formatCollection(); | - |
15 | QTextCharFormat oldFormat = c->charFormat(frag->format); | - |
16 | fmt.setTableCellRowSpan(oldFormat.tableCellRowSpan()); | - |
17 | fmt.setTableCellColumnSpan(oldFormat.tableCellColumnSpan()); | - |
18 | | - |
19 | p->setCharFormat(frag.position(), 1, fmt, QTextDocumentPrivate::SetFormatAndPreserveObjectIndices); | - |
20 | } | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | QTextCharFormat QTextTableCell::format() const | - |
26 | { | - |
27 | QTextDocumentPrivate *p = table->docHandle(); | - |
28 | QTextFormatCollection *c = p->formatCollection(); | - |
29 | | - |
30 | QTextCharFormat fmt = c->charFormat(tableCellFormatIndex()); | - |
31 | fmt.setObjectType(QTextFormat::TableCellObject); | - |
32 | return fmt; | - |
33 | } | - |
34 | int QTextTableCell::tableCellFormatIndex() const | - |
35 | { | - |
36 | QTextDocumentPrivate *p = table->docHandle(); | - |
37 | return QTextDocumentPrivate::FragmentIterator(&p->fragmentMap(), fragment)->format; | - |
38 | } | - |
39 | | - |
40 | | - |
41 | | - |
42 | | - |
43 | | - |
44 | | - |
45 | int QTextTableCell::row() const | - |
46 | { | - |
47 | const QTextTablePrivate *tp = table->d_func(); | - |
48 | if (tp->dirty) | - |
49 | tp->update(); | - |
50 | | - |
51 | int idx = tp->findCellIndex(fragment); | - |
52 | if (idx == -1) | - |
53 | return idx; | - |
54 | return tp->cellIndices.at(idx) / tp->nCols; | - |
55 | } | - |
56 | | - |
57 | | - |
58 | | - |
59 | | - |
60 | | - |
61 | | - |
62 | int QTextTableCell::column() const | - |
63 | { | - |
64 | const QTextTablePrivate *tp = table->d_func(); | - |
65 | if (tp->dirty) | - |
66 | tp->update(); | - |
67 | | - |
68 | int idx = tp->findCellIndex(fragment); | - |
69 | if (idx == -1) | - |
70 | return idx; | - |
71 | return tp->cellIndices.at(idx) % tp->nCols; | - |
72 | } | - |
73 | | - |
74 | | - |
75 | | - |
76 | | - |
77 | | - |
78 | | - |
79 | int QTextTableCell::rowSpan() const | - |
80 | { | - |
81 | return format().tableCellRowSpan(); | - |
82 | } | - |
83 | | - |
84 | | - |
85 | | - |
86 | | - |
87 | | - |
88 | | - |
89 | int QTextTableCell::columnSpan() const | - |
90 | { | - |
91 | return format().tableCellColumnSpan(); | - |
92 | } | - |
93 | QTextCursor QTextTableCell::firstCursorPosition() const | - |
94 | { | - |
95 | return QTextCursorPrivate::fromPosition(table->d_func()->pieceTable, firstPosition()); | - |
96 | } | - |
97 | | - |
98 | | - |
99 | | - |
100 | | - |
101 | | - |
102 | | - |
103 | QTextCursor QTextTableCell::lastCursorPosition() const | - |
104 | { | - |
105 | return QTextCursorPrivate::fromPosition(table->d_func()->pieceTable, lastPosition()); | - |
106 | } | - |
107 | | - |
108 | | - |
109 | | - |
110 | | - |
111 | | - |
112 | | - |
113 | | - |
114 | int QTextTableCell::firstPosition() const | - |
115 | { | - |
116 | QTextDocumentPrivate *p = table->docHandle(); | - |
117 | return p->fragmentMap().position(fragment) + 1; | - |
118 | } | - |
119 | | - |
120 | | - |
121 | | - |
122 | | - |
123 | | - |
124 | | - |
125 | int QTextTableCell::lastPosition() const | - |
126 | { | - |
127 | QTextDocumentPrivate *p = table->docHandle(); | - |
128 | const QTextTablePrivate *td = table->d_func(); | - |
129 | int index = table->d_func()->findCellIndex(fragment); | - |
130 | int f; | - |
131 | if (index != -1) | - |
132 | f = td->cells.value(index + 1, td->fragment_end); | - |
133 | else | - |
134 | f = td->fragment_end; | - |
135 | return p->fragmentMap().position(f); | - |
136 | } | - |
137 | | - |
138 | | - |
139 | | - |
140 | | - |
141 | | - |
142 | | - |
143 | | - |
144 | QTextFrame::iterator QTextTableCell::begin() const | - |
145 | { | - |
146 | QTextDocumentPrivate *p = table->docHandle(); | - |
147 | int b = p->blockMap().findNode(firstPosition()); | - |
148 | int e = p->blockMap().findNode(lastPosition()+1); | - |
149 | return QTextFrame::iterator(const_cast<QTextTable *>(table), b, b, e); | - |
150 | } | - |
151 | | - |
152 | | - |
153 | | - |
154 | | - |
155 | | - |
156 | | - |
157 | QTextFrame::iterator QTextTableCell::end() const | - |
158 | { | - |
159 | QTextDocumentPrivate *p = table->docHandle(); | - |
160 | int b = p->blockMap().findNode(firstPosition()); | - |
161 | int e = p->blockMap().findNode(lastPosition()+1); | - |
162 | return QTextFrame::iterator(const_cast<QTextTable *>(table), e, b, e); | - |
163 | } | - |
164 | QTextTablePrivate::~QTextTablePrivate() | - |
165 | { | - |
166 | if (grid) | - |
167 | free(grid); | - |
168 | } | - |
169 | | - |
170 | | - |
171 | QTextTable *QTextTablePrivate::createTable(QTextDocumentPrivate *pieceTable, int pos, int rows, int cols, const QTextTableFormat &tableFormat) | - |
172 | { | - |
173 | QTextTableFormat fmt = tableFormat; | - |
174 | fmt.setColumns(cols); | - |
175 | QTextTable *table = qobject_cast<QTextTable *>(pieceTable->createObject(fmt)); | - |
176 | ((!(table)) ? qt_assert("table",__FILE__,327333) : qt_noop()); | - |
177 | | - |
178 | pieceTable->beginEditBlock(); | - |
179 | | - |
180 | | - |
181 | | - |
182 | QTextCharFormat charFmt; | - |
183 | charFmt.setObjectIndex(table->objectIndex()); | - |
184 | charFmt.setObjectType(QTextFormat::TableCellObject); | - |
185 | | - |
186 | | - |
187 | int charIdx = pieceTable->formatCollection()->indexForFormat(charFmt); | - |
188 | int cellIdx = pieceTable->formatCollection()->indexForFormat(QTextBlockFormat()); | - |
189 | | - |
190 | QTextTablePrivate *d = table->d_func(); | - |
191 | d->blockFragmentUpdates = true; | - |
192 | | - |
193 | d->fragment_start = pieceTable->insertBlock(QChar(0xfdd0), pos, cellIdx, charIdx); | - |
194 | d->cells.append(d->fragment_start); | - |
195 | ++pos; | - |
196 | | - |
197 | for (int i = 1; i < rows*cols; ++i) { | - |
198 | d->cells.append(pieceTable->insertBlock(QChar(0xfdd0), pos, cellIdx, charIdx)); | - |
199 | | - |
200 | ++pos; | - |
201 | } | - |
202 | | - |
203 | d->fragment_end = pieceTable->insertBlock(QChar(0xfdd1), pos, cellIdx, charIdx); | - |
204 | | - |
205 | ++pos; | - |
206 | | - |
207 | d->blockFragmentUpdates = false; | - |
208 | d->dirty = true; | - |
209 | | - |
210 | pieceTable->endEditBlock(); | - |
211 | | - |
212 | return table; | - |
213 | } | - |
214 | | - |
215 | struct QFragmentFindHelper | - |
216 | { | - |
217 | inline QFragmentFindHelper(int _pos, const QTextDocumentPrivate::FragmentMap &map) | - |
218 | : pos(_pos), fragmentMap(map) {} | - |
219 | uint pos; | - |
220 | const QTextDocumentPrivate::FragmentMap &fragmentMap; | - |
221 | }; | - |
222 | | - |
223 | static inline bool operator<(int fragment, const QFragmentFindHelper &helper) | - |
224 | { | - |
225 | return helper.fragmentMap.position(fragment) < helper.pos; | - |
226 | } | - |
227 | | - |
228 | static inline bool operator<(const QFragmentFindHelper &helper, int fragment) | - |
229 | { | - |
230 | return helper.pos < helper.fragmentMap.position(fragment); | - |
231 | } | - |
232 | | - |
233 | int QTextTablePrivate::findCellIndex(int fragment) const | - |
234 | { | - |
235 | QFragmentFindHelper helper(pieceTable->fragmentMap().position(fragment), | - |
236 | pieceTable->fragmentMap()); | - |
237 | QList<int>::ConstIteratorconst auto it = std::lower_bound(cells.constBegin(), cells.constEnd(), helper); | - |
238 | if ((TRUE | never evaluated | FALSE | never evaluated |
it == cells.constEnd())TRUE | never evaluated | FALSE | never evaluated |
|| (TRUE | never evaluated | FALSE | never evaluated |
helper < *it)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
239 | return never executed: return -1; -1;never executed: return -1; | 0 |
240 | return never executed: return it - cells.constBegin(); it - cells.constBegin();never executed: return it - cells.constBegin(); | 0 |
241 | } | - |
242 | | - |
243 | void QTextTablePrivate::fragmentAdded(QChar type, uint fragment) | - |
244 | { | - |
245 | dirty = true; | - |
246 | if (blockFragmentUpdatesTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
247 | return; never executed: return; | 0 |
248 | if (type == QChar(0xfdd0)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
249 | ((!(cells.indexOf(fragment) == -1)) ? qt_assert("cells.indexOf(fragment) == -1",__FILE__,400406) : qt_noop()); | - |
250 | const uint pos = pieceTable->fragmentMap().position(fragment); | - |
251 | QFragmentFindHelper helper(pos, pieceTable->fragmentMap()); | - |
252 | QList<int>::Iteratorauto it = std::lower_bound(cells.begin(), cells.end(), helper); | - |
253 | cells.insert(it, fragment); | - |
254 | if (!fragment_startTRUE | never evaluated | FALSE | never evaluated |
|| pos < pieceTable->fragmentMap().position(fragment_start)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
255 | fragment_start = fragment; never executed: fragment_start = fragment; | 0 |
256 | return; never executed: return; | 0 |
257 | } | - |
258 | QTextFramePrivate::fragmentAdded(type, fragment); | - |
259 | } never executed: end of block | 0 |
260 | | - |
261 | void QTextTablePrivate::fragmentRemoved(QChar type, uint fragment) | - |
262 | { | - |
263 | dirty = true; | - |
264 | if (blockFragmentUpdates) | - |
265 | return; | - |
266 | if (type == QChar(0xfdd0)) { | - |
267 | ((!(cells.indexOf(fragment) != -1)) ? qt_assert("cells.indexOf(fragment) != -1",__FILE__,418424) : qt_noop()); | - |
268 | cells.removeAll(fragment); | - |
269 | if (fragment_start == fragment && cells.size()) { | - |
270 | fragment_start = cells.at(0); | - |
271 | } | - |
272 | if (fragment_start != fragment) | - |
273 | return; | - |
274 | } | - |
275 | QTextFramePrivate::fragmentRemoved(type, fragment); | - |
276 | } | - |
277 | void QTextTablePrivate::update() const | - |
278 | { | - |
279 | const QTextTable * const q = q_func(); | - |
280 | nCols = q->format().columns(); | - |
281 | nRows = (cells.size() + nCols-1)/nCols; | - |
282 | | - |
283 | | - |
284 | grid = q_check_ptr((int *)realloc(grid, nRows*nCols*sizeof(int))); | - |
285 | memset(grid, 0, nRows*nCols*sizeof(int)); | - |
286 | | - |
287 | QTextDocumentPrivate *p = pieceTable; | - |
288 | QTextFormatCollection *c = p->formatCollection(); | - |
289 | | - |
290 | cellIndices.resize(cells.size()); | - |
291 | | - |
292 | int cell = 0; | - |
293 | for (int i = 0; i < cells.size(); ++i) { | - |
294 | int fragment = cells.at(i); | - |
295 | QTextCharFormat fmt = c->charFormat(QTextDocumentPrivate::FragmentIterator(&p->fragmentMap(), fragment)->format); | - |
296 | int rowspan = fmt.tableCellRowSpan(); | - |
297 | int colspan = fmt.tableCellColumnSpan(); | - |
298 | | - |
299 | | - |
300 | while (cell < nRows*nCols && grid[cell]) | - |
301 | ++cell; | - |
302 | | - |
303 | int r = cell/nCols; | - |
304 | int c = cell%nCols; | - |
305 | cellIndices[i] = cell; | - |
306 | | - |
307 | if (r + rowspan > nRows) { | - |
308 | grid = q_check_ptr((int *)realloc(grid, sizeof(int)*(r + rowspan)*nCols)); | - |
309 | memset(grid + (nRows*nCols), 0, sizeof(int)*(r+rowspan-nRows)*nCols); | - |
310 | nRows = r + rowspan; | - |
311 | } | - |
312 | | - |
313 | ((!(c + colspan <= nCols)) ? qt_assert("c + colspan <= nCols",__FILE__,472478) : qt_noop()); | - |
314 | for (int ii = 0; ii < rowspan; ++ii) { | - |
315 | for (int jj = 0; jj < colspan; ++jj) { | - |
316 | ((!(grid[(r+ii)*nCols + c+jj] == 0)) ? qt_assert("grid[(r+ii)*nCols + c+jj] == 0",__FILE__,475481) : qt_noop()); | - |
317 | grid[(r+ii)*nCols + c+jj] = fragment; | - |
318 | | - |
319 | } | - |
320 | } | - |
321 | } | - |
322 | | - |
323 | | - |
324 | dirty = false; | - |
325 | } | - |
326 | QTextTable::QTextTable(QTextDocument *doc) | - |
327 | : QTextFrame(*new QTextTablePrivate(doc), doc) | - |
328 | { | - |
329 | } | - |
330 | | - |
331 | | - |
332 | | - |
333 | | - |
334 | | - |
335 | QTextTable::~QTextTable() | - |
336 | { | - |
337 | } | - |
338 | QTextTableCell QTextTable::cellAt(int row, int col) const | - |
339 | { | - |
340 | const QTextTablePrivate * const d = d_func(); | - |
341 | if (d->dirty) | - |
342 | d->update(); | - |
343 | | - |
344 | if (row < 0 || row >= d->nRows || col < 0 || col >= d->nCols) | - |
345 | return QTextTableCell(); | - |
346 | | - |
347 | return QTextTableCell(this, d->grid[row*d->nCols + col]); | - |
348 | } | - |
349 | | - |
350 | | - |
351 | | - |
352 | | - |
353 | | - |
354 | | - |
355 | | - |
356 | QTextTableCell QTextTable::cellAt(int position) const | - |
357 | { | - |
358 | const QTextTablePrivate * const d = d_func(); | - |
359 | if (d->dirtyTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
360 | d->update(); never executed: d->update(); | 0 |
361 | | - |
362 | uint pos = (uint)position; | - |
363 | const QTextDocumentPrivate::FragmentMap &map = d->pieceTable->fragmentMap(); | - |
364 | if (position < 0TRUE | never evaluated | FALSE | never evaluated |
|| map.position(d->fragment_start) >= posTRUE | never evaluated | FALSE | never evaluated |
|| map.position(d->fragment_end) < posTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
365 | return never executed: return QTextTableCell(); QTextTableCell();never executed: return QTextTableCell(); | 0 |
366 | | - |
367 | QFragmentFindHelper helper(position, map); | - |
368 | QList<int>::ConstIteratorauto it = std::lower_bound(d->cells.begin(), d->cells.end(), helper); | - |
369 | if (it != d->cells.begin()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
370 | -- never executed: --it; it;never executed: --it; | 0 |
371 | | - |
372 | return never executed: return QTextTableCell(this, *it); QTextTableCell(this, *it);never executed: return QTextTableCell(this, *it); | 0 |
373 | } | - |
374 | QTextTableCell QTextTable::cellAt(const QTextCursor &c) const | - |
375 | { | - |
376 | return cellAt(c.position()); | - |
377 | } | - |
378 | void QTextTable::resize(int rows, int cols) | - |
379 | { | - |
380 | QTextTablePrivate * const d = d_func(); | - |
381 | if (d->dirty) | - |
382 | d->update(); | - |
383 | | - |
384 | int nRows = this->rows(); | - |
385 | int nCols = this->columns(); | - |
386 | | - |
387 | if (rows == nRows && cols == nCols) | - |
388 | return; | - |
389 | | - |
390 | d->pieceTable->beginEditBlock(); | - |
391 | | - |
392 | if (nCols < cols) | - |
393 | insertColumns(nCols, cols - nCols); | - |
394 | else if (nCols > cols) | - |
395 | removeColumns(cols, nCols - cols); | - |
396 | | - |
397 | if (nRows < rows) | - |
398 | insertRows(nRows, rows-nRows); | - |
399 | else if (nRows > rows) | - |
400 | removeRows(rows, nRows-rows); | - |
401 | | - |
402 | d->pieceTable->endEditBlock(); | - |
403 | } | - |
404 | void QTextTable::insertRows(int pos, int num) | - |
405 | { | - |
406 | QTextTablePrivate * const d = d_func(); | - |
407 | if (num <= 0) | - |
408 | return; | - |
409 | | - |
410 | if (d->dirty) | - |
411 | d->update(); | - |
412 | | - |
413 | if (pos > d->nRows || pos < 0) | - |
414 | pos = d->nRows; | - |
415 | | - |
416 | | - |
417 | QTextDocumentPrivate *p = d->pieceTable; | - |
418 | QTextFormatCollection *c = p->formatCollection(); | - |
419 | p->beginEditBlock(); | - |
420 | | - |
421 | int extended = 0; | - |
422 | int insert_before = 0; | - |
423 | if (pos > 0 && pos < d->nRows) { | - |
424 | for (int i = 0; i < d->nCols; ++i) { | - |
425 | int cell = d->grid[pos*d->nCols + i]; | - |
426 | if (cell == d->grid[(pos-1)*d->nCols+i]) { | - |
427 | | - |
428 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); | - |
429 | QTextCharFormat fmt = c->charFormat(it->format); | - |
430 | fmt.setTableCellRowSpan(fmt.tableCellRowSpan() + num); | - |
431 | p->setCharFormat(it.position(), 1, fmt); | - |
432 | extended++; | - |
433 | } else if (!insert_before) { | - |
434 | insert_before = cell; | - |
435 | } | - |
436 | } | - |
437 | } else { | - |
438 | insert_before = (pos == 0 ? d->grid[0] : d->fragment_end); | - |
439 | } | - |
440 | if (extended < d->nCols) { | - |
441 | ((!(insert_before)) ? qt_assert("insert_before",__FILE__,710716) : qt_noop()); | - |
442 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), insert_before); | - |
443 | QTextCharFormat fmt = c->charFormat(it->format); | - |
444 | fmt.setTableCellRowSpan(1); | - |
445 | fmt.setTableCellColumnSpan(1); | - |
446 | ((!(fmt.objectIndex() == objectIndex())) ? qt_assert("fmt.objectIndex() == objectIndex()",__FILE__,715721) : qt_noop()); | - |
447 | int pos = it.position(); | - |
448 | int cfmt = p->formatCollection()->indexForFormat(fmt); | - |
449 | int bfmt = p->formatCollection()->indexForFormat(QTextBlockFormat()); | - |
450 | | - |
451 | for (int i = 0; i < num*(d->nCols-extended); ++i) | - |
452 | p->insertBlock(QChar(0xfdd0), pos, bfmt, cfmt, QTextUndoCommand::MoveCursor); | - |
453 | } | - |
454 | | - |
455 | | - |
456 | p->endEditBlock(); | - |
457 | } | - |
458 | void QTextTable::insertColumns(int pos, int num) | - |
459 | { | - |
460 | QTextTablePrivate * const d = d_func(); | - |
461 | if (num <= 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
462 | return; never executed: return; | 0 |
463 | | - |
464 | if (d->dirtyTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
465 | d->update(); never executed: d->update(); | 0 |
466 | | - |
467 | if (pos > d->nColsTRUE | never evaluated | FALSE | never evaluated |
|| pos < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
468 | pos = d->nCols; never executed: pos = d->nCols; | 0 |
469 | | - |
470 | | - |
471 | QTextDocumentPrivate *p = d->pieceTable; | - |
472 | QTextFormatCollection *c = p->formatCollection(); | - |
473 | p->beginEditBlock(); | - |
474 | | - |
475 | QListQVector<int> extendedSpans; | - |
476 | for (int i = 0; i < d->nRowsTRUE | never evaluated | FALSE | never evaluated |
; ++i) { | 0 |
477 | int cell; | - |
478 | if (i == d->nRows - 1TRUE | never evaluated | FALSE | never evaluated |
&& pos == d->nColsTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
479 | cell = d->fragment_end; | - |
480 | } never executed: end of block else { | 0 |
481 | int logicalGridIndexBeforePosition = pos > 0TRUE | never evaluated | FALSE | never evaluated |
| 0 |
482 | ? d->findCellIndex(d->grid[i*d->nCols + pos - 1]) | - |
483 | : -1; | - |
484 | | - |
485 | | - |
486 | | - |
487 | | - |
488 | int logicalGridIndex; | - |
489 | int gridArrayOffset = i*d->nCols + pos; | - |
490 | do { | - |
491 | cell = d->grid[gridArrayOffset]; | - |
492 | logicalGridIndex = d->findCellIndex(cell); | - |
493 | gridArrayOffset++; | - |
494 | } never executed: end of block while (logicalGridIndex < logicalGridIndexBeforePositionTRUE | never evaluated | FALSE | never evaluated |
| 0 |
495 | && gridArrayOffset < d->nRows*d->nColsTRUE | never evaluated | FALSE | never evaluated |
); | 0 |
496 | | - |
497 | if (logicalGridIndex < logicalGridIndexBeforePositionTRUE | never evaluated | FALSE | never evaluated |
| 0 |
498 | && gridArrayOffset == d->nRows*d->nColsTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
499 | cell = d->fragment_end; never executed: cell = d->fragment_end; | 0 |
500 | } never executed: end of block | 0 |
501 | | - |
502 | if (pos > 0TRUE | never evaluated | FALSE | never evaluated |
&& pos < d->nColsTRUE | never evaluated | FALSE | never evaluated |
&& cell == d->grid[i*d->nCols + pos - 1]TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
503 | | - |
504 | if (!extendedSpans.contains(cell)TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
505 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); | - |
506 | QTextCharFormat fmt = c->charFormat(it->format); | - |
507 | fmt.setTableCellColumnSpan(fmt.tableCellColumnSpan() + num); | - |
508 | p->setCharFormat(it.position(), 1, fmt); | - |
509 | d->dirty = true; | - |
510 | extendedSpans << cell; | - |
511 | } never executed: end of block | 0 |
512 | } never executed: end of block else { | 0 |
513 | | - |
514 | | - |
515 | if (i > 0TRUE | never evaluated | FALSE | never evaluated |
&& pos < d->nColsTRUE | never evaluated | FALSE | never evaluated |
&& cell == d->grid[(i-1) * d->nCols + pos]TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
516 | int gridIndex = i*d->nCols + pos; | - |
517 | const int gridEnd = d->nRows * d->nCols - 1; | - |
518 | while (gridIndex < gridEndTRUE | never evaluated | FALSE | never evaluated |
&& cell == d->grid[gridIndex]TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
519 | ++gridIndex; | - |
520 | } never executed: end of block | 0 |
521 | if (gridIndex == gridEndTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
522 | cell = d->fragment_end; never executed: cell = d->fragment_end; | 0 |
523 | else | - |
524 | cell = d->grid[gridIndex]; never executed: cell = d->grid[gridIndex]; | 0 |
525 | } | - |
526 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); | - |
527 | QTextCharFormat fmt = c->charFormat(it->format); | - |
528 | fmt.setTableCellRowSpan(1); | - |
529 | fmt.setTableCellColumnSpan(1); | - |
530 | ((!(fmt.objectIndex() == objectIndex())) ? qt_assert("fmt.objectIndex() == objectIndex()",__FILE__,807813) : qt_noop()); | - |
531 | int position = it.position(); | - |
532 | int cfmt = p->formatCollection()->indexForFormat(fmt); | - |
533 | int bfmt = p->formatCollection()->indexForFormat(QTextBlockFormat()); | - |
534 | for (int i = 0; i < numTRUE | never evaluated | FALSE | never evaluated |
; ++i) | 0 |
535 | p->insertBlock(QChar(0xfdd0), position, bfmt, cfmt, QTextUndoCommand::MoveCursor); never executed: p->insertBlock(QChar(0xfdd0), position, bfmt, cfmt, QTextUndoCommand::MoveCursor); | 0 |
536 | } never executed: end of block | 0 |
537 | } | - |
538 | | - |
539 | QTextTableFormat tfmt = format(); | - |
540 | tfmt.setColumns(tfmt.columns()+num); | - |
541 | QVector<QTextLength> columnWidths = tfmt.columnWidthConstraints(); | - |
542 | if (! columnWidths.isEmpty()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
543 | for (int i = num; i > 0TRUE | never evaluated | FALSE | never evaluated |
; --i) | 0 |
544 | columnWidths.insert(pos, columnWidths[.at(qMax(0, pos - 1)]);))); never executed: columnWidths.insert(pos, columnWidths.at(qMax(0, pos - 1))); | 0 |
545 | } never executed: end of block | 0 |
546 | tfmt.setColumnWidthConstraints (columnWidths); | - |
547 | QTextObject::setFormat(tfmt); | - |
548 | | - |
549 | | - |
550 | p->endEditBlock(); | - |
551 | } never executed: end of block | 0 |
552 | | - |
553 | | - |
554 | | - |
555 | | - |
556 | | - |
557 | | - |
558 | | - |
559 | void QTextTable::appendRows(int count) | - |
560 | { | - |
561 | insertRows(rows(), count); | - |
562 | } | - |
563 | | - |
564 | | - |
565 | | - |
566 | | - |
567 | | - |
568 | | - |
569 | | - |
570 | void QTextTable::appendColumns(int count) | - |
571 | { | - |
572 | insertColumns(columns(), count); | - |
573 | } | - |
574 | void QTextTable::removeRows(int pos, int num) | - |
575 | { | - |
576 | QTextTablePrivate * const d = d_func(); | - |
577 | | - |
578 | | - |
579 | if (num <= 0TRUE | never evaluated | FALSE | never evaluated |
|| pos < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
580 | return; never executed: return; | 0 |
581 | if (d->dirtyTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
582 | d->update(); never executed: d->update(); | 0 |
583 | if (pos >= d->nRowsTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
584 | return; never executed: return; | 0 |
585 | if (pos+num > d->nRowsTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
586 | num = d->nRows - pos; never executed: num = d->nRows - pos; | 0 |
587 | | - |
588 | QTextDocumentPrivate *p = d->pieceTable; | - |
589 | QTextFormatCollection *collection = p->formatCollection(); | - |
590 | p->beginEditBlock(); | - |
591 | | - |
592 | | - |
593 | if (pos == 0TRUE | never evaluated | FALSE | never evaluated |
&& num == d->nRowsTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
594 | const int pos = p->fragmentMap().position(d->fragment_start); | - |
595 | p->remove(pos, p->fragmentMap().position(d->fragment_end) - pos + 1); | - |
596 | p->endEditBlock(); | - |
597 | return; never executed: return; | 0 |
598 | } | - |
599 | | - |
600 | p->aboutToRemoveCell(cellAt(pos, 0).firstPosition(), cellAt(pos + num - 1, d->nCols - 1).lastPosition()); | - |
601 | | - |
602 | QListQVector<int> touchedCells; | - |
603 | for (int r = pos; r < pos + numTRUE | never evaluated | FALSE | never evaluated |
; ++r) { | 0 |
604 | for (int c = 0; c < d->nColsTRUE | never evaluated | FALSE | never evaluated |
; ++c) { | 0 |
605 | int cell = d->grid[r*d->nCols + c]; | - |
606 | if (touchedCells.contains(cell)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
607 | continue; never executed: continue; | 0 |
608 | touchedCells << cell; | - |
609 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); | - |
610 | QTextCharFormat fmt = collection->charFormat(it->format); | - |
611 | int span = fmt.tableCellRowSpan(); | - |
612 | if (span > 1TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
613 | fmt.setTableCellRowSpan(span - 1); | - |
614 | p->setCharFormat(it.position(), 1, fmt); | - |
615 | } never executed: end of block else { | 0 |
616 | | - |
617 | int index = d->cells.indexOf(cell) + 1; | - |
618 | int f_end = index < d->cells.size()TRUE | never evaluated | FALSE | never evaluated |
? d->cells.at(index) : d->fragment_end; | 0 |
619 | p->remove(it.position(), p->fragmentMap().position(f_end) - it.position()); | - |
620 | } never executed: end of block | 0 |
621 | } | - |
622 | } never executed: end of block | 0 |
623 | | - |
624 | p->endEditBlock(); | - |
625 | | - |
626 | } never executed: end of block | 0 |
627 | void QTextTable::removeColumns(int pos, int num) | - |
628 | { | - |
629 | QTextTablePrivate * const d = d_func(); | - |
630 | | - |
631 | | - |
632 | if (num <= 0TRUE | never evaluated | FALSE | never evaluated |
|| pos < 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
633 | return; never executed: return; | 0 |
634 | if (d->dirtyTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
635 | d->update(); never executed: d->update(); | 0 |
636 | if (pos >= d->nColsTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
637 | return; never executed: return; | 0 |
638 | if (pos + num > d->nColsTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
639 | pos = d->nCols - num; never executed: pos = d->nCols - num; | 0 |
640 | | - |
641 | QTextDocumentPrivate *p = d->pieceTable; | - |
642 | QTextFormatCollection *collection = p->formatCollection(); | - |
643 | p->beginEditBlock(); | - |
644 | | - |
645 | | - |
646 | if (pos == 0TRUE | never evaluated | FALSE | never evaluated |
&& num == d->nColsTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
647 | const int pos = p->fragmentMap().position(d->fragment_start); | - |
648 | p->remove(pos, p->fragmentMap().position(d->fragment_end) - pos + 1); | - |
649 | p->endEditBlock(); | - |
650 | return; never executed: return; | 0 |
651 | } | - |
652 | | - |
653 | p->aboutToRemoveCell(cellAt(0, pos).firstPosition(), cellAt(d->nRows - 1, pos + num - 1).lastPosition()); | - |
654 | | - |
655 | QListQVector<int> touchedCells; | - |
656 | for (int r = 0; r < d->nRowsTRUE | never evaluated | FALSE | never evaluated |
; ++r) { | 0 |
657 | for (int c = pos; c < pos + numTRUE | never evaluated | FALSE | never evaluated |
; ++c) { | 0 |
658 | int cell = d->grid[r*d->nCols + c]; | - |
659 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); | - |
660 | QTextCharFormat fmt = collection->charFormat(it->format); | - |
661 | int span = fmt.tableCellColumnSpan(); | - |
662 | if (touchedCells.contains(cell)TRUE | never evaluated | FALSE | never evaluated |
&& span <= 1TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
663 | continue; never executed: continue; | 0 |
664 | touchedCells << cell; | - |
665 | | - |
666 | if (span > 1TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
667 | fmt.setTableCellColumnSpan(span - 1); | - |
668 | p->setCharFormat(it.position(), 1, fmt); | - |
669 | } never executed: end of block else { | 0 |
670 | | - |
671 | int index = d->cells.indexOf(cell) + 1; | - |
672 | int f_end = index < d->cells.size()TRUE | never evaluated | FALSE | never evaluated |
? d->cells.at(index) : d->fragment_end; | 0 |
673 | p->remove(it.position(), p->fragmentMap().position(f_end) - it.position()); | - |
674 | } never executed: end of block | 0 |
675 | } | - |
676 | } never executed: end of block | 0 |
677 | | - |
678 | QTextTableFormat tfmt = format(); | - |
679 | tfmt.setColumns(tfmt.columns()-num); | - |
680 | QVector<QTextLength> columnWidths = tfmt.columnWidthConstraints(); | - |
681 | if (columnWidths.count() > posTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
682 | columnWidths.remove(pos, num); | - |
683 | tfmt.setColumnWidthConstraints (columnWidths); | - |
684 | } never executed: end of block | 0 |
685 | QTextObject::setFormat(tfmt); | - |
686 | | - |
687 | p->endEditBlock(); | - |
688 | | - |
689 | } never executed: end of block | 0 |
690 | void QTextTable::mergeCells(int row, int column, int numRows, int numCols) | - |
691 | { | - |
692 | QTextTablePrivate * const d = d_func(); | - |
693 | | - |
694 | if (d->dirtyTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
695 | d->update(); never executed: d->update(); | 0 |
696 | | - |
697 | QTextDocumentPrivate *p = d->pieceTable; | - |
698 | QTextFormatCollection *fc = p->formatCollection(); | - |
699 | | - |
700 | const QTextTableCell cell = cellAt(row, column); | - |
701 | if (!cell.isValid()TRUE | never evaluated | FALSE | never evaluated |
|| row != cell.row()TRUE | never evaluated | FALSE | never evaluated |
|| column != cell.column()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
702 | return; never executed: return; | 0 |
703 | | - |
704 | QTextCharFormat fmt = cell.format(); | - |
705 | const int rowSpan = fmt.tableCellRowSpan(); | - |
706 | const int colSpan = fmt.tableCellColumnSpan(); | - |
707 | | - |
708 | numRows = qMin(numRows, rows() - cell.row()); | - |
709 | numCols = qMin(numCols, columns() - cell.column()); | - |
710 | | - |
711 | | - |
712 | if (numRows < rowSpanTRUE | never evaluated | FALSE | never evaluated |
|| numCols < colSpanTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
713 | return; never executed: return; | 0 |
714 | | - |
715 | | - |
716 | for (int r = row; r < row + numRowsTRUE | never evaluated | FALSE | never evaluated |
; ++r) { | 0 |
717 | if (cellAt(r, column) == cellAt(r, column - 1)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
718 | return; never executed: return; | 0 |
719 | if (cellAt(r, column + numCols) == cellAt(r, column + numCols - 1)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
720 | return; never executed: return; | 0 |
721 | } never executed: end of block | 0 |
722 | | - |
723 | for (int c = column; c < column + numColsTRUE | never evaluated | FALSE | never evaluated |
; ++c) { | 0 |
724 | if (cellAt(row, c) == cellAt(row - 1, c)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
725 | return; never executed: return; | 0 |
726 | if (cellAt(row + numRows, c) == cellAt(row + numRows - 1, c)TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
727 | return; never executed: return; | 0 |
728 | } never executed: end of block | 0 |
729 | | - |
730 | p->beginEditBlock(); | - |
731 | | - |
732 | const int origCellPosition = cell.firstPosition() - 1; | - |
733 | | - |
734 | const int cellFragment = d->grid[row * d->nCols + column]; | - |
735 | | - |
736 | | - |
737 | QFragmentFindHelper helper(origCellPosition, p->fragmentMap()); | - |
738 | QList<int>::Iteratorconst auto begin = d->cells.cbegin(); | - |
739 | const auto it = std::lower_bound(d->cells.begin(),, d->cells.endcend(), helper); | - |
740 | ((!(it != d->cells.end())) ? qt_assert("it != d->cells.end()",__FILE__,10441051) : qt_noop()); | - |
741 | ((!(!(helper < *it))) ? qt_assert("!(helper < *it)",__FILE__,10451052) : qt_noop()); | - |
742 | ((!(*it == cellFragment)) ? qt_assert("*it == cellFragment",__FILE__,10461053) : qt_noop()); | - |
743 | const int insertCellIndex = it - d->cells.begin();; | - |
744 | int insertFragment = d->cells.value(insertCellIndex + 1, d->fragment_end); | - |
745 | uint insertPos = p->fragmentMap().position(insertFragment); | - |
746 | | - |
747 | d->blockFragmentUpdates = true; | - |
748 | | - |
749 | bool rowHasText = cell.firstCursorPosition().block().length(); | - |
750 | bool needsParagraph = rowHasTextTRUE | never evaluated | FALSE | never evaluated |
&& colSpan == numColsTRUE | never evaluated | FALSE | never evaluated |
; | 0 |
751 | | - |
752 | | - |
753 | for (int r = row; r < row + numRowsTRUE | never evaluated | FALSE | never evaluated |
; ++r) { | 0 |
754 | int firstColumn = r < row + rowSpanTRUE | never evaluated | FALSE | never evaluated |
? column + colSpan : column; | 0 |
755 | | - |
756 | | - |
757 | int firstCellIndex = r == rowTRUE | never evaluated | FALSE | never evaluated |
? insertCellIndex + 1 : -1; | 0 |
758 | int cellIndex = firstCellIndex; | - |
759 | | - |
760 | for (int c = firstColumn; c < column + numColsTRUE | never evaluated | FALSE | never evaluated |
; ++c) { | 0 |
761 | const int fragment = d->grid[r * d->nCols + c]; | - |
762 | | - |
763 | | - |
764 | if (fragment == cellFragmentTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
765 | continue; never executed: continue; | 0 |
766 | | - |
767 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment); | - |
768 | uint pos = it.position(); | - |
769 | | - |
770 | if (firstCellIndex == -1TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
771 | QFragmentFindHelper helper(pos, p->fragmentMap()); | - |
772 | QList<int>::Iteratorconst auto begin = d->cells.cbegin(); | - |
773 | const auto it = std::lower_bound(d->cells.begin(),, d->cells.endcend(), helper); | - |
774 | ((!(it != d->cells.end())) ? qt_assert("it != d->cells.end()",__FILE__,10771085) : qt_noop()); | - |
775 | ((!(!(helper < *it))) ? qt_assert("!(helper < *it)",__FILE__,10781086) : qt_noop()); | - |
776 | ((!(*it == fragment)) ? qt_assert("*it == fragment",__FILE__,10791087) : qt_noop()); | - |
777 | firstCellIndex = cellIndex = it - d->cells.begin();; | - |
778 | } never executed: end of block | 0 |
779 | | - |
780 | ++cellIndex; | - |
781 | | - |
782 | QTextCharFormat fmt = fc->charFormat(it->format); | - |
783 | | - |
784 | const int cellRowSpan = fmt.tableCellRowSpan(); | - |
785 | const int cellColSpan = fmt.tableCellColumnSpan(); | - |
786 | | - |
787 | | - |
788 | for (int i = r; i < r + cellRowSpanTRUE | never evaluated | FALSE | never evaluated |
; ++i) | 0 |
789 | for (int j = c; j < c + cellColSpanTRUE | never evaluated | FALSE | never evaluated |
; ++j) | 0 |
790 | d->grid[i * d->nCols + j] = cellFragment; never executed: d->grid[i * d->nCols + j] = cellFragment; | 0 |
791 | | - |
792 | | - |
793 | p->remove(pos, 1); | - |
794 | | - |
795 | const int nextFragment = d->cells.value(cellIndex, d->fragment_end); | - |
796 | const uint nextPos = p->fragmentMap().position(nextFragment); | - |
797 | | - |
798 | ((!(nextPos >= pos)) ? qt_assert("nextPos >= pos",__FILE__,11011109) : qt_noop()); | - |
799 | | - |
800 | | - |
801 | if (nextPos > posTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
802 | if (needsParagraphTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
803 | needsParagraph = false; | - |
804 | QTextCursorPrivate::fromPosition(p, insertPos++).insertBlock(); | - |
805 | p->move(pos + 1, insertPos, nextPos - pos); | - |
806 | } never executed: end of block else if (rowHasTextTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
807 | QTextCursorPrivate::fromPosition(p, insertPos++).insertText(QLatin1String(" ")); | - |
808 | p->move(pos + 1, insertPos, nextPos - pos); | - |
809 | } never executed: end of block else { | 0 |
810 | p->move(pos, insertPos, nextPos - pos); | - |
811 | } never executed: end of block | 0 |
812 | | - |
813 | insertPos += nextPos - pos; | - |
814 | rowHasText = true; | - |
815 | } never executed: end of block | 0 |
816 | } never executed: end of block | 0 |
817 | | - |
818 | if (rowHasTextTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
819 | needsParagraph = true; | - |
820 | rowHasText = false; | - |
821 | } never executed: end of block | 0 |
822 | | - |
823 | | - |
824 | if (firstCellIndex >= 0TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
825 | d->cellIndices.remove(firstCellIndex, cellIndex - firstCellIndex); | - |
826 | d->cells.erase(d->cells.begin() + firstCellIndex, d->cells.begin() + cellIndex); | - |
827 | } never executed: end of block | 0 |
828 | } never executed: end of block | 0 |
829 | | - |
830 | d->fragment_start = d->cells.firstconstFirst(); | - |
831 | | - |
832 | fmt.setTableCellRowSpan(numRows); | - |
833 | fmt.setTableCellColumnSpan(numCols); | - |
834 | p->setCharFormat(origCellPosition, 1, fmt); | - |
835 | | - |
836 | d->blockFragmentUpdates = false; | - |
837 | d->dirty = false; | - |
838 | | - |
839 | p->endEditBlock(); | - |
840 | } never executed: end of block | 0 |
841 | void QTextTable::mergeCells(const QTextCursor &cursor) | - |
842 | { | - |
843 | if (!cursor.hasComplexSelection()) | - |
844 | return; | - |
845 | | - |
846 | int firstRow, numRows, firstColumn, numColumns; | - |
847 | cursor.selectedTableCells(&firstRow, &numRows, &firstColumn, &numColumns); | - |
848 | mergeCells(firstRow, firstColumn, numRows, numColumns); | - |
849 | } | - |
850 | void QTextTable::splitCell(int row, int column, int numRows, int numCols) | - |
851 | { | - |
852 | QTextTablePrivate * const d = d_func(); | - |
853 | | - |
854 | if (d->dirtyTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
855 | d->update(); never executed: d->update(); | 0 |
856 | | - |
857 | QTextDocumentPrivate *p = d->pieceTable; | - |
858 | QTextFormatCollection *c = p->formatCollection(); | - |
859 | | - |
860 | const QTextTableCell cell = cellAt(row, column); | - |
861 | if (!cell.isValid()TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
862 | return; never executed: return; | 0 |
863 | row = cell.row(); | - |
864 | column = cell.column(); | - |
865 | | - |
866 | QTextCharFormat fmt = cell.format(); | - |
867 | const int rowSpan = fmt.tableCellRowSpan(); | - |
868 | const int colSpan = fmt.tableCellColumnSpan(); | - |
869 | | - |
870 | | - |
871 | if (numRows > rowSpanTRUE | never evaluated | FALSE | never evaluated |
|| numCols > colSpanTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
872 | return; never executed: return; | 0 |
873 | | - |
874 | p->beginEditBlock(); | - |
875 | | - |
876 | const int origCellPosition = cell.firstPosition() - 1; | - |
877 | | - |
878 | QVarLengthArray<int> rowPositions(rowSpan); | - |
879 | | - |
880 | rowPositions[0] = cell.lastPosition(); | - |
881 | | - |
882 | for (int r = row + 1; r < row + rowSpanTRUE | never evaluated | FALSE | never evaluated |
; ++r) { | 0 |
883 | | - |
884 | int gridIndex = r * d->nCols + column; | - |
885 | QVector<int>::iteratorconst auto begin = d->cellIndices.cbegin(); | - |
886 | const auto it = std::upper_bound(d->cellIndices.begin(),, d->cellIndices.endcend(), gridIndex); | - |
887 | int cellIndex = it - d->cellIndices.begin();int fragment = d->cells.value(cellIndexit - begin, d->fragment_end); | - |
888 | rowPositions[r - row] = p->fragmentMap().position(fragment); | - |
889 | } never executed: end of block | 0 |
890 | | - |
891 | fmt.setTableCellColumnSpan(1); | - |
892 | fmt.setTableCellRowSpan(1); | - |
893 | const int fmtIndex = c->indexForFormat(fmt); | - |
894 | const int blockIndex = p->blockMap().find(cell.lastPosition())->format; | - |
895 | | - |
896 | int insertAdjustement = 0; | - |
897 | for (int i = 0; i < numRowsTRUE | never evaluated | FALSE | never evaluated |
; ++i) { | 0 |
898 | for (int c = 0; c < colSpan - numColsTRUE | never evaluated | FALSE | never evaluated |
; ++c) | 0 |
899 | p->insertBlock(QChar(0xfdd0), rowPositions[i] + insertAdjustement + c, blockIndex, fmtIndex); never executed: p->insertBlock(QChar(0xfdd0), rowPositions[i] + insertAdjustement + c, blockIndex, fmtIndex); | 0 |
900 | insertAdjustement += colSpan - numCols; | - |
901 | } never executed: end of block | 0 |
902 | | - |
903 | for (int i = numRows; i < rowSpanTRUE | never evaluated | FALSE | never evaluated |
; ++i) { | 0 |
904 | for (int c = 0; c < colSpanTRUE | never evaluated | FALSE | never evaluated |
; ++c) | 0 |
905 | p->insertBlock(QChar(0xfdd0), rowPositions[i] + insertAdjustement + c, blockIndex, fmtIndex); never executed: p->insertBlock(QChar(0xfdd0), rowPositions[i] + insertAdjustement + c, blockIndex, fmtIndex); | 0 |
906 | insertAdjustement += colSpan; | - |
907 | } never executed: end of block | 0 |
908 | | - |
909 | fmt.setTableCellRowSpan(numRows); | - |
910 | fmt.setTableCellColumnSpan(numCols); | - |
911 | p->setCharFormat(origCellPosition, 1, fmt); | - |
912 | | - |
913 | p->endEditBlock(); | - |
914 | } never executed: end of block | 0 |
915 | | - |
916 | | - |
917 | | - |
918 | | - |
919 | | - |
920 | | - |
921 | int QTextTable::rows() const | - |
922 | { | - |
923 | const QTextTablePrivate * const d = d_func(); | - |
924 | if (d->dirty) | - |
925 | d->update(); | - |
926 | | - |
927 | return d->nRows; | - |
928 | } | - |
929 | | - |
930 | | - |
931 | | - |
932 | | - |
933 | | - |
934 | | - |
935 | int QTextTable::columns() const | - |
936 | { | - |
937 | const QTextTablePrivate * const d = d_func(); | - |
938 | if (d->dirty) | - |
939 | d->update(); | - |
940 | | - |
941 | return d->nCols; | - |
942 | } | - |
943 | QTextCursor QTextTable::rowStart(const QTextCursor &c) const | - |
944 | { | - |
945 | const QTextTablePrivate * const d = d_func(); | - |
946 | QTextTableCell cell = cellAt(c); | - |
947 | if (!cell.isValid()) | - |
948 | return QTextCursor(); | - |
949 | | - |
950 | int row = cell.row(); | - |
951 | QTextDocumentPrivate *p = d->pieceTable; | - |
952 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), d->grid[row*d->nCols]); | - |
953 | return QTextCursorPrivate::fromPosition(p, it.position()); | - |
954 | } | - |
955 | QTextCursor QTextTable::rowEnd(const QTextCursor &c) const | - |
956 | { | - |
957 | const QTextTablePrivate * const d = d_func(); | - |
958 | QTextTableCell cell = cellAt(c); | - |
959 | if (!cell.isValid()) | - |
960 | return QTextCursor(); | - |
961 | | - |
962 | int row = cell.row() + 1; | - |
963 | int fragment = row < d->nRows ? d->grid[row*d->nCols] : d->fragment_end; | - |
964 | QTextDocumentPrivate *p = d->pieceTable; | - |
965 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment); | - |
966 | return QTextCursorPrivate::fromPosition(p, it.position() - 1); | - |
967 | } | - |
968 | void QTextTable::setFormat(const QTextTableFormat &format) | - |
969 | { | - |
970 | QTextTableFormat fmt = format; | - |
971 | | - |
972 | fmt.setColumns(columns()); | - |
973 | QTextObject::setFormat(fmt); | - |
974 | } | - |
975 | | - |
| | |