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