| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtexttable.cpp |
| Switch to Source code | Preprocessed file |
| 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 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 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 never executed: fmt;return fmt;never executed: return fmt; | 0 | ||||||||||||||||||||||||
| 33 | } | - | ||||||||||||||||||||||||
| 34 | int QTextTableCell::tableCellFormatIndex() const | - | ||||||||||||||||||||||||
| 35 | { | - | ||||||||||||||||||||||||
| 36 | QTextDocumentPrivate *p = table->docHandle(); | - | ||||||||||||||||||||||||
| 37 | return never executed: QTextDocumentPrivate::FragmentIterator(&p->fragmentMap(), fragment)->format;return QTextDocumentPrivate::FragmentIterator(&p->fragmentMap(), fragment)->format;never executed: return QTextDocumentPrivate::FragmentIterator(&p->fragmentMap(), fragment)->format; | 0 | ||||||||||||||||||||||||
| 38 | } | - | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | - | |||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||
| 42 | - | |||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||
| 44 | - | |||||||||||||||||||||||||
| 45 | int QTextTableCell::row() const | - | ||||||||||||||||||||||||
| 46 | { | - | ||||||||||||||||||||||||
| 47 | const QTextTablePrivate *tp = table->d_func(); | - | ||||||||||||||||||||||||
| 48 | if (tp->dirty
| 0 | ||||||||||||||||||||||||
| 49 | tp->update(); never executed: tp->update(); | 0 | ||||||||||||||||||||||||
| 50 | - | |||||||||||||||||||||||||
| 51 | int idx = tp->findCellIndex(fragment); | - | ||||||||||||||||||||||||
| 52 | if (idx == -1
| 0 | ||||||||||||||||||||||||
| 53 | return never executed: idx;return idx;never executed: return idx; | 0 | ||||||||||||||||||||||||
| 54 | return never executed: tp->cellIndices.at(idx) / tp->nCols;return tp->cellIndices.at(idx) / tp->nCols;never executed: return tp->cellIndices.at(idx) / tp->nCols; | 0 | ||||||||||||||||||||||||
| 55 | } | - | ||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||
| 58 | - | |||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||
| 60 | - | |||||||||||||||||||||||||
| 61 | - | |||||||||||||||||||||||||
| 62 | int QTextTableCell::column() const | - | ||||||||||||||||||||||||
| 63 | { | - | ||||||||||||||||||||||||
| 64 | const QTextTablePrivate *tp = table->d_func(); | - | ||||||||||||||||||||||||
| 65 | if (tp->dirty
| 0 | ||||||||||||||||||||||||
| 66 | tp->update(); never executed: tp->update(); | 0 | ||||||||||||||||||||||||
| 67 | - | |||||||||||||||||||||||||
| 68 | int idx = tp->findCellIndex(fragment); | - | ||||||||||||||||||||||||
| 69 | if (idx == -1
| 0 | ||||||||||||||||||||||||
| 70 | return never executed: idx;return idx;never executed: return idx; | 0 | ||||||||||||||||||||||||
| 71 | return never executed: tp->cellIndices.at(idx) % tp->nCols;return tp->cellIndices.at(idx) % tp->nCols;never executed: return tp->cellIndices.at(idx) % tp->nCols; | 0 | ||||||||||||||||||||||||
| 72 | } | - | ||||||||||||||||||||||||
| 73 | - | |||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||
| 75 | - | |||||||||||||||||||||||||
| 76 | - | |||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||
| 78 | - | |||||||||||||||||||||||||
| 79 | int QTextTableCell::rowSpan() const | - | ||||||||||||||||||||||||
| 80 | { | - | ||||||||||||||||||||||||
| 81 | return never executed: format().tableCellRowSpan();return format().tableCellRowSpan();never executed: return format().tableCellRowSpan(); | 0 | ||||||||||||||||||||||||
| 82 | } | - | ||||||||||||||||||||||||
| 83 | - | |||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||
| 85 | - | |||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||
| 87 | - | |||||||||||||||||||||||||
| 88 | - | |||||||||||||||||||||||||
| 89 | int QTextTableCell::columnSpan() const | - | ||||||||||||||||||||||||
| 90 | { | - | ||||||||||||||||||||||||
| 91 | return never executed: format().tableCellColumnSpan();return format().tableCellColumnSpan();never executed: return format().tableCellColumnSpan(); | 0 | ||||||||||||||||||||||||
| 92 | } | - | ||||||||||||||||||||||||
| 93 | QTextCursor QTextTableCell::firstCursorPosition() const | - | ||||||||||||||||||||||||
| 94 | { | - | ||||||||||||||||||||||||
| 95 | return never executed: QTextCursorPrivate::fromPosition(table->d_func()->pieceTable, firstPosition());return QTextCursorPrivate::fromPosition(table->d_func()->pieceTable, firstPosition());never executed: return QTextCursorPrivate::fromPosition(table->d_func()->pieceTable, firstPosition()); | 0 | ||||||||||||||||||||||||
| 96 | } | - | ||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||
| 100 | - | |||||||||||||||||||||||||
| 101 | - | |||||||||||||||||||||||||
| 102 | - | |||||||||||||||||||||||||
| 103 | QTextCursor QTextTableCell::lastCursorPosition() const | - | ||||||||||||||||||||||||
| 104 | { | - | ||||||||||||||||||||||||
| 105 | return never executed: QTextCursorPrivate::fromPosition(table->d_func()->pieceTable, lastPosition());return QTextCursorPrivate::fromPosition(table->d_func()->pieceTable, lastPosition());never executed: return QTextCursorPrivate::fromPosition(table->d_func()->pieceTable, lastPosition()); | 0 | ||||||||||||||||||||||||
| 106 | } | - | ||||||||||||||||||||||||
| 107 | - | |||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||
| 109 | - | |||||||||||||||||||||||||
| 110 | - | |||||||||||||||||||||||||
| 111 | - | |||||||||||||||||||||||||
| 112 | - | |||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||
| 114 | int QTextTableCell::firstPosition() const | - | ||||||||||||||||||||||||
| 115 | { | - | ||||||||||||||||||||||||
| 116 | QTextDocumentPrivate *p = table->docHandle(); | - | ||||||||||||||||||||||||
| 117 | return never executed: p->fragmentMap().position(fragment) + 1;return p->fragmentMap().position(fragment) + 1;never executed: return p->fragmentMap().position(fragment) + 1; | 0 | ||||||||||||||||||||||||
| 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
| 0 | ||||||||||||||||||||||||
| 132 | f = td->cells.value(index + 1, td->fragment_end); never executed: f = td->cells.value(index + 1, td->fragment_end); | 0 | ||||||||||||||||||||||||
| 133 | else | - | ||||||||||||||||||||||||
| 134 | f = td->fragment_end; never executed: f = td->fragment_end; | 0 | ||||||||||||||||||||||||
| 135 | return never executed: p->fragmentMap().position(f);return p->fragmentMap().position(f);never executed: return p->fragmentMap().position(f); | 0 | ||||||||||||||||||||||||
| 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 never executed: QTextFrame::iterator(const_cast<QTextTable *>(table), b, b, e);return QTextFrame::iterator(const_cast<QTextTable *>(table), b, b, e);never executed: return QTextFrame::iterator(const_cast<QTextTable *>(table), b, b, e); | 0 | ||||||||||||||||||||||||
| 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 never executed: QTextFrame::iterator(const_cast<QTextTable *>(table), e, b, e);return QTextFrame::iterator(const_cast<QTextTable *>(table), e, b, e);never executed: return QTextFrame::iterator(const_cast<QTextTable *>(table), e, b, e); | 0 | ||||||||||||||||||||||||
| 163 | } | - | ||||||||||||||||||||||||
| 164 | QTextTablePrivate::~QTextTablePrivate() | - | ||||||||||||||||||||||||
| 165 | { | - | ||||||||||||||||||||||||
| 166 | if (grid
| 0 | ||||||||||||||||||||||||
| 167 | free(grid); never executed: free(grid); | 0 | ||||||||||||||||||||||||
| 168 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 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__,327) : 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
| 0 | ||||||||||||||||||||||||
| 198 | d->cells.append(pieceTable->insertBlock(QChar(0xfdd0), pos, cellIdx, charIdx)); | - | ||||||||||||||||||||||||
| 199 | - | |||||||||||||||||||||||||
| 200 | ++pos; | - | ||||||||||||||||||||||||
| 201 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 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 never executed: table;return table;never executed: return table; | 0 | ||||||||||||||||||||||||
| 213 | } | - | ||||||||||||||||||||||||
| 214 | - | |||||||||||||||||||||||||
| 215 | struct QFragmentFindHelper | - | ||||||||||||||||||||||||
| 216 | { | - | ||||||||||||||||||||||||
| 217 | inline QFragmentFindHelper(int _pos, const QTextDocumentPrivate::FragmentMap &map) | - | ||||||||||||||||||||||||
| 218 | : pos(_pos), fragmentMap(map) {} never executed: end of block | 0 | ||||||||||||||||||||||||
| 219 | uint pos; | - | ||||||||||||||||||||||||
| 220 | const QTextDocumentPrivate::FragmentMap &fragmentMap; | - | ||||||||||||||||||||||||
| 221 | }; | - | ||||||||||||||||||||||||
| 222 | - | |||||||||||||||||||||||||
| 223 | static inline bool operator<(int fragment, const QFragmentFindHelper &helper) | - | ||||||||||||||||||||||||
| 224 | { | - | ||||||||||||||||||||||||
| 225 | return never executed: helper.fragmentMap.position(fragment) < helper.pos;return helper.fragmentMap.position(fragment) < helper.pos;never executed: return helper.fragmentMap.position(fragment) < helper.pos; | 0 | ||||||||||||||||||||||||
| 226 | } | - | ||||||||||||||||||||||||
| 227 | - | |||||||||||||||||||||||||
| 228 | static inline bool operator<(const QFragmentFindHelper &helper, int fragment) | - | ||||||||||||||||||||||||
| 229 | { | - | ||||||||||||||||||||||||
| 230 | return never executed: helper.pos < helper.fragmentMap.position(fragment);return helper.pos < helper.fragmentMap.position(fragment);never executed: return helper.pos < helper.fragmentMap.position(fragment); | 0 | ||||||||||||||||||||||||
| 231 | } | - | ||||||||||||||||||||||||
| 232 | - | |||||||||||||||||||||||||
| 233 | int QTextTablePrivate::findCellIndex(int fragment) const | - | ||||||||||||||||||||||||
| 234 | { | - | ||||||||||||||||||||||||
| 235 | QFragmentFindHelper helper(pieceTable->fragmentMap().position(fragment), | - | ||||||||||||||||||||||||
| 236 | pieceTable->fragmentMap()); | - | ||||||||||||||||||||||||
| 237 | QList<int>::ConstIterator it = std::lower_bound(cells.constBegin(), cells.constEnd(), helper); | - | ||||||||||||||||||||||||
| 238 | if ((
| 0 | ||||||||||||||||||||||||
| 239 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||||||||
| 240 | return never executed: it - cells.constBegin();return 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 (blockFragmentUpdates
| 0 | ||||||||||||||||||||||||
| 247 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 248 | if (type == QChar(0xfdd0)
| 0 | ||||||||||||||||||||||||
| 249 | ((!(cells.indexOf(fragment) == -1)) ? qt_assert("cells.indexOf(fragment) == -1",__FILE__,400) : qt_noop()); | - | ||||||||||||||||||||||||
| 250 | const uint pos = pieceTable->fragmentMap().position(fragment); | - | ||||||||||||||||||||||||
| 251 | QFragmentFindHelper helper(pos, pieceTable->fragmentMap()); | - | ||||||||||||||||||||||||
| 252 | QList<int>::Iterator it = std::lower_bound(cells.begin(), cells.end(), helper); | - | ||||||||||||||||||||||||
| 253 | cells.insert(it, fragment); | - | ||||||||||||||||||||||||
| 254 | if (!fragment_start
| 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
| 0 | ||||||||||||||||||||||||
| 265 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 266 | if (type == QChar(0xfdd0)
| 0 | ||||||||||||||||||||||||
| 267 | ((!(cells.indexOf(fragment) != -1)) ? qt_assert("cells.indexOf(fragment) != -1",__FILE__,418) : qt_noop()); | - | ||||||||||||||||||||||||
| 268 | cells.removeAll(fragment); | - | ||||||||||||||||||||||||
| 269 | if (fragment_start == fragment
| 0 | ||||||||||||||||||||||||
| 270 | fragment_start = cells.at(0); | - | ||||||||||||||||||||||||
| 271 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 272 | if (fragment_start != fragment
| 0 | ||||||||||||||||||||||||
| 273 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 274 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 275 | QTextFramePrivate::fragmentRemoved(type, fragment); | - | ||||||||||||||||||||||||
| 276 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 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()
| 0 | ||||||||||||||||||||||||
| 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
| 0 | ||||||||||||||||||||||||
| 301 | ++ never executed: cell;++cell;never executed: ++cell; | 0 | ||||||||||||||||||||||||
| 302 | - | |||||||||||||||||||||||||
| 303 | int r = cell/nCols; | - | ||||||||||||||||||||||||
| 304 | int c = cell%nCols; | - | ||||||||||||||||||||||||
| 305 | cellIndices[i] = cell; | - | ||||||||||||||||||||||||
| 306 | - | |||||||||||||||||||||||||
| 307 | if (r + rowspan > nRows
| 0 | ||||||||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||
| 313 | ((!(c + colspan <= nCols)) ? qt_assert("c + colspan <= nCols",__FILE__,472) : qt_noop()); | - | ||||||||||||||||||||||||
| 314 | for (int ii = 0; ii < rowspan
| 0 | ||||||||||||||||||||||||
| 315 | for (int jj = 0; jj < colspan
| 0 | ||||||||||||||||||||||||
| 316 | ((!(grid[(r+ii)*nCols + c+jj] == 0)) ? qt_assert("grid[(r+ii)*nCols + c+jj] == 0",__FILE__,475) : qt_noop()); | - | ||||||||||||||||||||||||
| 317 | grid[(r+ii)*nCols + c+jj] = fragment; | - | ||||||||||||||||||||||||
| 318 | - | |||||||||||||||||||||||||
| 319 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 320 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 321 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 322 | - | |||||||||||||||||||||||||
| 323 | - | |||||||||||||||||||||||||
| 324 | dirty = false; | - | ||||||||||||||||||||||||
| 325 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 326 | QTextTable::QTextTable(QTextDocument *doc) | - | ||||||||||||||||||||||||
| 327 | : QTextFrame(*new QTextTablePrivate(doc), doc) | - | ||||||||||||||||||||||||
| 328 | { | - | ||||||||||||||||||||||||
| 329 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 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
| 0 | ||||||||||||||||||||||||
| 342 | d->update(); never executed: d->update(); | 0 | ||||||||||||||||||||||||
| 343 | - | |||||||||||||||||||||||||
| 344 | if (row < 0
| 0 | ||||||||||||||||||||||||
| 345 | return never executed: QTextTableCell();return QTextTableCell();never executed: return QTextTableCell(); | 0 | ||||||||||||||||||||||||
| 346 | - | |||||||||||||||||||||||||
| 347 | return never executed: QTextTableCell(this, d->grid[row*d->nCols + col]);return QTextTableCell(this, d->grid[row*d->nCols + col]);never executed: return QTextTableCell(this, d->grid[row*d->nCols + col]); | 0 | ||||||||||||||||||||||||
| 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->dirty
| 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 < 0
| 0 | ||||||||||||||||||||||||
| 365 | return never executed: QTextTableCell();return QTextTableCell();never executed: return QTextTableCell(); | 0 | ||||||||||||||||||||||||
| 366 | - | |||||||||||||||||||||||||
| 367 | QFragmentFindHelper helper(position, map); | - | ||||||||||||||||||||||||
| 368 | QList<int>::ConstIterator it = std::lower_bound(d->cells.begin(), d->cells.end(), helper); | - | ||||||||||||||||||||||||
| 369 | if (it != d->cells.begin()
| 0 | ||||||||||||||||||||||||
| 370 | -- never executed: it;--it;never executed: --it; | 0 | ||||||||||||||||||||||||
| 371 | - | |||||||||||||||||||||||||
| 372 | return never executed: QTextTableCell(this, *it);return QTextTableCell(this, *it);never executed: return QTextTableCell(this, *it); | 0 | ||||||||||||||||||||||||
| 373 | } | - | ||||||||||||||||||||||||
| 374 | QTextTableCell QTextTable::cellAt(const QTextCursor &c) const | - | ||||||||||||||||||||||||
| 375 | { | - | ||||||||||||||||||||||||
| 376 | return never executed: cellAt(c.position());return cellAt(c.position());never executed: return cellAt(c.position()); | 0 | ||||||||||||||||||||||||
| 377 | } | - | ||||||||||||||||||||||||
| 378 | void QTextTable::resize(int rows, int cols) | - | ||||||||||||||||||||||||
| 379 | { | - | ||||||||||||||||||||||||
| 380 | QTextTablePrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 381 | if (d->dirty
| 0 | ||||||||||||||||||||||||
| 382 | d->update(); never executed: d->update(); | 0 | ||||||||||||||||||||||||
| 383 | - | |||||||||||||||||||||||||
| 384 | int nRows = this->rows(); | - | ||||||||||||||||||||||||
| 385 | int nCols = this->columns(); | - | ||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | if (rows == nRows
| 0 | ||||||||||||||||||||||||
| 388 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 389 | - | |||||||||||||||||||||||||
| 390 | d->pieceTable->beginEditBlock(); | - | ||||||||||||||||||||||||
| 391 | - | |||||||||||||||||||||||||
| 392 | if (nCols < cols
| 0 | ||||||||||||||||||||||||
| 393 | insertColumns(nCols, cols - nCols); never executed: insertColumns(nCols, cols - nCols); | 0 | ||||||||||||||||||||||||
| 394 | else if (nCols > cols
| 0 | ||||||||||||||||||||||||
| 395 | removeColumns(cols, nCols - cols); never executed: removeColumns(cols, nCols - cols); | 0 | ||||||||||||||||||||||||
| 396 | - | |||||||||||||||||||||||||
| 397 | if (nRows < rows
| 0 | ||||||||||||||||||||||||
| 398 | insertRows(nRows, rows-nRows); never executed: insertRows(nRows, rows-nRows); | 0 | ||||||||||||||||||||||||
| 399 | else if (nRows > rows
| 0 | ||||||||||||||||||||||||
| 400 | removeRows(rows, nRows-rows); never executed: removeRows(rows, nRows-rows); | 0 | ||||||||||||||||||||||||
| 401 | - | |||||||||||||||||||||||||
| 402 | d->pieceTable->endEditBlock(); | - | ||||||||||||||||||||||||
| 403 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 404 | void QTextTable::insertRows(int pos, int num) | - | ||||||||||||||||||||||||
| 405 | { | - | ||||||||||||||||||||||||
| 406 | QTextTablePrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 407 | if (num <= 0
| 0 | ||||||||||||||||||||||||
| 408 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 409 | - | |||||||||||||||||||||||||
| 410 | if (d->dirty
| 0 | ||||||||||||||||||||||||
| 411 | d->update(); never executed: d->update(); | 0 | ||||||||||||||||||||||||
| 412 | - | |||||||||||||||||||||||||
| 413 | if (pos > d->nRows
| 0 | ||||||||||||||||||||||||
| 414 | pos = d->nRows; never executed: pos = d->nRows; | 0 | ||||||||||||||||||||||||
| 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
| 0 | ||||||||||||||||||||||||
| 424 | for (int i = 0; i < d->nCols
| 0 | ||||||||||||||||||||||||
| 425 | int cell = d->grid[pos*d->nCols + i]; | - | ||||||||||||||||||||||||
| 426 | if (cell == d->grid[(pos-1)*d->nCols+i]
| 0 | ||||||||||||||||||||||||
| 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 | } never executed: else if (!insert_beforeend of block
| 0 | ||||||||||||||||||||||||
| 434 | insert_before = cell; | - | ||||||||||||||||||||||||
| 435 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 436 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 437 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 438 | insert_before = (pos == 0
| 0 | ||||||||||||||||||||||||
| 439 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 440 | if (extended < d->nCols
| 0 | ||||||||||||||||||||||||
| 441 | ((!(insert_before)) ? qt_assert("insert_before",__FILE__,710) : 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__,715) : 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)
| 0 | ||||||||||||||||||||||||
| 452 | p->insertBlock(QChar(0xfdd0), pos, bfmt, cfmt, QTextUndoCommand::MoveCursor); never executed: p->insertBlock(QChar(0xfdd0), pos, bfmt, cfmt, QTextUndoCommand::MoveCursor); | 0 | ||||||||||||||||||||||||
| 453 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 454 | - | |||||||||||||||||||||||||
| 455 | - | |||||||||||||||||||||||||
| 456 | p->endEditBlock(); | - | ||||||||||||||||||||||||
| 457 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 458 | void QTextTable::insertColumns(int pos, int num) | - | ||||||||||||||||||||||||
| 459 | { | - | ||||||||||||||||||||||||
| 460 | QTextTablePrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 461 | if (num <= 0
| 0 | ||||||||||||||||||||||||
| 462 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 463 | - | |||||||||||||||||||||||||
| 464 | if (d->dirty
| 0 | ||||||||||||||||||||||||
| 465 | d->update(); never executed: d->update(); | 0 | ||||||||||||||||||||||||
| 466 | - | |||||||||||||||||||||||||
| 467 | if (pos > d->nCols
| 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 | QList<int> extendedSpans; | - | ||||||||||||||||||||||||
| 476 | for (int i = 0; i < d->nRows
| 0 | ||||||||||||||||||||||||
| 477 | int cell; | - | ||||||||||||||||||||||||
| 478 | if (i == d->nRows - 1
| 0 | ||||||||||||||||||||||||
| 479 | cell = d->fragment_end; | - | ||||||||||||||||||||||||
| 480 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 481 | int logicalGridIndexBeforePosition = pos > 0
| 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: while (logicalGridIndex < logicalGridIndexBeforePositionend of block
| 0 | ||||||||||||||||||||||||
| 495 | && gridArrayOffset < d->nRows*d->nCols
| 0 | ||||||||||||||||||||||||
| 496 | - | |||||||||||||||||||||||||
| 497 | if (logicalGridIndex < logicalGridIndexBeforePosition
| 0 | ||||||||||||||||||||||||
| 498 | && gridArrayOffset == d->nRows*d->nCols
| 0 | ||||||||||||||||||||||||
| 499 | cell = d->fragment_end; never executed: cell = d->fragment_end; | 0 | ||||||||||||||||||||||||
| 500 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 501 | - | |||||||||||||||||||||||||
| 502 | if (pos > 0
| 0 | ||||||||||||||||||||||||
| 503 | - | |||||||||||||||||||||||||
| 504 | if (!extendedSpans.contains(cell)
| 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: else {end of block | 0 | ||||||||||||||||||||||||
| 513 | - | |||||||||||||||||||||||||
| 514 | - | |||||||||||||||||||||||||
| 515 | if (i > 0
| 0 | ||||||||||||||||||||||||
| 516 | int gridIndex = i*d->nCols + pos; | - | ||||||||||||||||||||||||
| 517 | const int gridEnd = d->nRows * d->nCols - 1; | - | ||||||||||||||||||||||||
| 518 | while (gridIndex < gridEnd
| 0 | ||||||||||||||||||||||||
| 519 | ++gridIndex; | - | ||||||||||||||||||||||||
| 520 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 521 | if (gridIndex == gridEnd
| 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__,807) : 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 < num
| 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()
| 0 | ||||||||||||||||||||||||
| 543 | for (int i = num; i > 0
| 0 | ||||||||||||||||||||||||
| 544 | columnWidths.insert(pos, columnWidths[qMax(0, pos-1)]); never executed: columnWidths.insert(pos, columnWidths[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 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 563 | - | |||||||||||||||||||||||||
| 564 | - | |||||||||||||||||||||||||
| 565 | - | |||||||||||||||||||||||||
| 566 | - | |||||||||||||||||||||||||
| 567 | - | |||||||||||||||||||||||||
| 568 | - | |||||||||||||||||||||||||
| 569 | - | |||||||||||||||||||||||||
| 570 | void QTextTable::appendColumns(int count) | - | ||||||||||||||||||||||||
| 571 | { | - | ||||||||||||||||||||||||
| 572 | insertColumns(columns(), count); | - | ||||||||||||||||||||||||
| 573 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 574 | void QTextTable::removeRows(int pos, int num) | - | ||||||||||||||||||||||||
| 575 | { | - | ||||||||||||||||||||||||
| 576 | QTextTablePrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 577 | - | |||||||||||||||||||||||||
| 578 | - | |||||||||||||||||||||||||
| 579 | if (num <= 0
| 0 | ||||||||||||||||||||||||
| 580 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 581 | if (d->dirty
| 0 | ||||||||||||||||||||||||
| 582 | d->update(); never executed: d->update(); | 0 | ||||||||||||||||||||||||
| 583 | if (pos >= d->nRows
| 0 | ||||||||||||||||||||||||
| 584 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 585 | if (pos+num > d->nRows
| 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 == 0
| 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 | QList<int> touchedCells; | - | ||||||||||||||||||||||||
| 603 | for (int r = pos; r < pos + num
| 0 | ||||||||||||||||||||||||
| 604 | for (int c = 0; c < d->nCols
| 0 | ||||||||||||||||||||||||
| 605 | int cell = d->grid[r*d->nCols + c]; | - | ||||||||||||||||||||||||
| 606 | if (touchedCells.contains(cell)
| 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 > 1
| 0 | ||||||||||||||||||||||||
| 613 | fmt.setTableCellRowSpan(span - 1); | - | ||||||||||||||||||||||||
| 614 | p->setCharFormat(it.position(), 1, fmt); | - | ||||||||||||||||||||||||
| 615 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 616 | - | |||||||||||||||||||||||||
| 617 | int index = d->cells.indexOf(cell) + 1; | - | ||||||||||||||||||||||||
| 618 | int f_end = index < d->cells.size()
| 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 <= 0
| 0 | ||||||||||||||||||||||||
| 633 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 634 | if (d->dirty
| 0 | ||||||||||||||||||||||||
| 635 | d->update(); never executed: d->update(); | 0 | ||||||||||||||||||||||||
| 636 | if (pos >= d->nCols
| 0 | ||||||||||||||||||||||||
| 637 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 638 | if (pos + num > d->nCols
| 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 == 0
| 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 | QList<int> touchedCells; | - | ||||||||||||||||||||||||
| 656 | for (int r = 0; r < d->nRows
| 0 | ||||||||||||||||||||||||
| 657 | for (int c = pos; c < pos + num
| 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)
| 0 | ||||||||||||||||||||||||
| 663 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 664 | touchedCells << cell; | - | ||||||||||||||||||||||||
| 665 | - | |||||||||||||||||||||||||
| 666 | if (span > 1
| 0 | ||||||||||||||||||||||||
| 667 | fmt.setTableCellColumnSpan(span - 1); | - | ||||||||||||||||||||||||
| 668 | p->setCharFormat(it.position(), 1, fmt); | - | ||||||||||||||||||||||||
| 669 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 670 | - | |||||||||||||||||||||||||
| 671 | int index = d->cells.indexOf(cell) + 1; | - | ||||||||||||||||||||||||
| 672 | int f_end = index < d->cells.size()
| 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() > pos
| 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->dirty
| 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()
| 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 < rowSpan
| 0 | ||||||||||||||||||||||||
| 713 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 714 | - | |||||||||||||||||||||||||
| 715 | - | |||||||||||||||||||||||||
| 716 | for (int r = row; r < row + numRows
| 0 | ||||||||||||||||||||||||
| 717 | if (cellAt(r, column) == cellAt(r, column - 1)
| 0 | ||||||||||||||||||||||||
| 718 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 719 | if (cellAt(r, column + numCols) == cellAt(r, column + numCols - 1)
| 0 | ||||||||||||||||||||||||
| 720 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 721 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 722 | - | |||||||||||||||||||||||||
| 723 | for (int c = column; c < column + numCols
| 0 | ||||||||||||||||||||||||
| 724 | if (cellAt(row, c) == cellAt(row - 1, c)
| 0 | ||||||||||||||||||||||||
| 725 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 726 | if (cellAt(row + numRows, c) == cellAt(row + numRows - 1, c)
| 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>::Iterator it = std::lower_bound(d->cells.begin(), d->cells.end(), helper); | - | ||||||||||||||||||||||||
| 739 | ((!(it != d->cells.end())) ? qt_assert("it != d->cells.end()",__FILE__,1044) : qt_noop()); | - | ||||||||||||||||||||||||
| 740 | ((!(!(helper < *it))) ? qt_assert("!(helper < *it)",__FILE__,1045) : qt_noop()); | - | ||||||||||||||||||||||||
| 741 | ((!(*it == cellFragment)) ? qt_assert("*it == cellFragment",__FILE__,1046) : qt_noop()); | - | ||||||||||||||||||||||||
| 742 | const int insertCellIndex = it - d->cells.begin(); | - | ||||||||||||||||||||||||
| 743 | int insertFragment = d->cells.value(insertCellIndex + 1, d->fragment_end); | - | ||||||||||||||||||||||||
| 744 | uint insertPos = p->fragmentMap().position(insertFragment); | - | ||||||||||||||||||||||||
| 745 | - | |||||||||||||||||||||||||
| 746 | d->blockFragmentUpdates = true; | - | ||||||||||||||||||||||||
| 747 | - | |||||||||||||||||||||||||
| 748 | bool rowHasText = cell.firstCursorPosition().block().length(); | - | ||||||||||||||||||||||||
| 749 | bool needsParagraph = rowHasText
| 0 | ||||||||||||||||||||||||
| 750 | - | |||||||||||||||||||||||||
| 751 | - | |||||||||||||||||||||||||
| 752 | for (int r = row; r < row + numRows
| 0 | ||||||||||||||||||||||||
| 753 | int firstColumn = r < row + rowSpan
| 0 | ||||||||||||||||||||||||
| 754 | - | |||||||||||||||||||||||||
| 755 | - | |||||||||||||||||||||||||
| 756 | int firstCellIndex = r == row
| 0 | ||||||||||||||||||||||||
| 757 | int cellIndex = firstCellIndex; | - | ||||||||||||||||||||||||
| 758 | - | |||||||||||||||||||||||||
| 759 | for (int c = firstColumn; c < column + numCols
| 0 | ||||||||||||||||||||||||
| 760 | const int fragment = d->grid[r * d->nCols + c]; | - | ||||||||||||||||||||||||
| 761 | - | |||||||||||||||||||||||||
| 762 | - | |||||||||||||||||||||||||
| 763 | if (fragment == cellFragment
| 0 | ||||||||||||||||||||||||
| 764 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 765 | - | |||||||||||||||||||||||||
| 766 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment); | - | ||||||||||||||||||||||||
| 767 | uint pos = it.position(); | - | ||||||||||||||||||||||||
| 768 | - | |||||||||||||||||||||||||
| 769 | if (firstCellIndex == -1
| 0 | ||||||||||||||||||||||||
| 770 | QFragmentFindHelper helper(pos, p->fragmentMap()); | - | ||||||||||||||||||||||||
| 771 | QList<int>::Iterator it = std::lower_bound(d->cells.begin(), d->cells.end(), helper); | - | ||||||||||||||||||||||||
| 772 | ((!(it != d->cells.end())) ? qt_assert("it != d->cells.end()",__FILE__,1077) : qt_noop()); | - | ||||||||||||||||||||||||
| 773 | ((!(!(helper < *it))) ? qt_assert("!(helper < *it)",__FILE__,1078) : qt_noop()); | - | ||||||||||||||||||||||||
| 774 | ((!(*it == fragment)) ? qt_assert("*it == fragment",__FILE__,1079) : qt_noop()); | - | ||||||||||||||||||||||||
| 775 | firstCellIndex = cellIndex = it - d->cells.begin(); | - | ||||||||||||||||||||||||
| 776 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 777 | - | |||||||||||||||||||||||||
| 778 | ++cellIndex; | - | ||||||||||||||||||||||||
| 779 | - | |||||||||||||||||||||||||
| 780 | QTextCharFormat fmt = fc->charFormat(it->format); | - | ||||||||||||||||||||||||
| 781 | - | |||||||||||||||||||||||||
| 782 | const int cellRowSpan = fmt.tableCellRowSpan(); | - | ||||||||||||||||||||||||
| 783 | const int cellColSpan = fmt.tableCellColumnSpan(); | - | ||||||||||||||||||||||||
| 784 | - | |||||||||||||||||||||||||
| 785 | - | |||||||||||||||||||||||||
| 786 | for (int i = r; i < r + cellRowSpan
| 0 | ||||||||||||||||||||||||
| 787 | for (int j = c; j < c + cellColSpan
| 0 | ||||||||||||||||||||||||
| 788 | d->grid[i * d->nCols + j] = cellFragment; never executed: d->grid[i * d->nCols + j] = cellFragment; | 0 | ||||||||||||||||||||||||
| 789 | - | |||||||||||||||||||||||||
| 790 | - | |||||||||||||||||||||||||
| 791 | p->remove(pos, 1); | - | ||||||||||||||||||||||||
| 792 | - | |||||||||||||||||||||||||
| 793 | const int nextFragment = d->cells.value(cellIndex, d->fragment_end); | - | ||||||||||||||||||||||||
| 794 | const uint nextPos = p->fragmentMap().position(nextFragment); | - | ||||||||||||||||||||||||
| 795 | - | |||||||||||||||||||||||||
| 796 | ((!(nextPos >= pos)) ? qt_assert("nextPos >= pos",__FILE__,1101) : qt_noop()); | - | ||||||||||||||||||||||||
| 797 | - | |||||||||||||||||||||||||
| 798 | - | |||||||||||||||||||||||||
| 799 | if (nextPos > pos
| 0 | ||||||||||||||||||||||||
| 800 | if (needsParagraph
| 0 | ||||||||||||||||||||||||
| 801 | needsParagraph = false; | - | ||||||||||||||||||||||||
| 802 | QTextCursorPrivate::fromPosition(p, insertPos++).insertBlock(); | - | ||||||||||||||||||||||||
| 803 | p->move(pos + 1, insertPos, nextPos - pos); | - | ||||||||||||||||||||||||
| 804 | } never executed: else if (rowHasTextend of block
| 0 | ||||||||||||||||||||||||
| 805 | QTextCursorPrivate::fromPosition(p, insertPos++).insertText(QLatin1String(" ")); | - | ||||||||||||||||||||||||
| 806 | p->move(pos + 1, insertPos, nextPos - pos); | - | ||||||||||||||||||||||||
| 807 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 808 | p->move(pos, insertPos, nextPos - pos); | - | ||||||||||||||||||||||||
| 809 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 810 | - | |||||||||||||||||||||||||
| 811 | insertPos += nextPos - pos; | - | ||||||||||||||||||||||||
| 812 | rowHasText = true; | - | ||||||||||||||||||||||||
| 813 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 814 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 815 | - | |||||||||||||||||||||||||
| 816 | if (rowHasText
| 0 | ||||||||||||||||||||||||
| 817 | needsParagraph = true; | - | ||||||||||||||||||||||||
| 818 | rowHasText = false; | - | ||||||||||||||||||||||||
| 819 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 820 | - | |||||||||||||||||||||||||
| 821 | - | |||||||||||||||||||||||||
| 822 | if (firstCellIndex >= 0
| 0 | ||||||||||||||||||||||||
| 823 | d->cellIndices.remove(firstCellIndex, cellIndex - firstCellIndex); | - | ||||||||||||||||||||||||
| 824 | d->cells.erase(d->cells.begin() + firstCellIndex, d->cells.begin() + cellIndex); | - | ||||||||||||||||||||||||
| 825 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 826 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 827 | - | |||||||||||||||||||||||||
| 828 | d->fragment_start = d->cells.first(); | - | ||||||||||||||||||||||||
| 829 | - | |||||||||||||||||||||||||
| 830 | fmt.setTableCellRowSpan(numRows); | - | ||||||||||||||||||||||||
| 831 | fmt.setTableCellColumnSpan(numCols); | - | ||||||||||||||||||||||||
| 832 | p->setCharFormat(origCellPosition, 1, fmt); | - | ||||||||||||||||||||||||
| 833 | - | |||||||||||||||||||||||||
| 834 | d->blockFragmentUpdates = false; | - | ||||||||||||||||||||||||
| 835 | d->dirty = false; | - | ||||||||||||||||||||||||
| 836 | - | |||||||||||||||||||||||||
| 837 | p->endEditBlock(); | - | ||||||||||||||||||||||||
| 838 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 839 | void QTextTable::mergeCells(const QTextCursor &cursor) | - | ||||||||||||||||||||||||
| 840 | { | - | ||||||||||||||||||||||||
| 841 | if (!cursor.hasComplexSelection()
| 0 | ||||||||||||||||||||||||
| 842 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 843 | - | |||||||||||||||||||||||||
| 844 | int firstRow, numRows, firstColumn, numColumns; | - | ||||||||||||||||||||||||
| 845 | cursor.selectedTableCells(&firstRow, &numRows, &firstColumn, &numColumns); | - | ||||||||||||||||||||||||
| 846 | mergeCells(firstRow, firstColumn, numRows, numColumns); | - | ||||||||||||||||||||||||
| 847 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 848 | void QTextTable::splitCell(int row, int column, int numRows, int numCols) | - | ||||||||||||||||||||||||
| 849 | { | - | ||||||||||||||||||||||||
| 850 | QTextTablePrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 851 | - | |||||||||||||||||||||||||
| 852 | if (d->dirty
| 0 | ||||||||||||||||||||||||
| 853 | d->update(); never executed: d->update(); | 0 | ||||||||||||||||||||||||
| 854 | - | |||||||||||||||||||||||||
| 855 | QTextDocumentPrivate *p = d->pieceTable; | - | ||||||||||||||||||||||||
| 856 | QTextFormatCollection *c = p->formatCollection(); | - | ||||||||||||||||||||||||
| 857 | - | |||||||||||||||||||||||||
| 858 | const QTextTableCell cell = cellAt(row, column); | - | ||||||||||||||||||||||||
| 859 | if (!cell.isValid()
| 0 | ||||||||||||||||||||||||
| 860 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 861 | row = cell.row(); | - | ||||||||||||||||||||||||
| 862 | column = cell.column(); | - | ||||||||||||||||||||||||
| 863 | - | |||||||||||||||||||||||||
| 864 | QTextCharFormat fmt = cell.format(); | - | ||||||||||||||||||||||||
| 865 | const int rowSpan = fmt.tableCellRowSpan(); | - | ||||||||||||||||||||||||
| 866 | const int colSpan = fmt.tableCellColumnSpan(); | - | ||||||||||||||||||||||||
| 867 | - | |||||||||||||||||||||||||
| 868 | - | |||||||||||||||||||||||||
| 869 | if (numRows > rowSpan
| 0 | ||||||||||||||||||||||||
| 870 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 871 | - | |||||||||||||||||||||||||
| 872 | p->beginEditBlock(); | - | ||||||||||||||||||||||||
| 873 | - | |||||||||||||||||||||||||
| 874 | const int origCellPosition = cell.firstPosition() - 1; | - | ||||||||||||||||||||||||
| 875 | - | |||||||||||||||||||||||||
| 876 | QVarLengthArray<int> rowPositions(rowSpan); | - | ||||||||||||||||||||||||
| 877 | - | |||||||||||||||||||||||||
| 878 | rowPositions[0] = cell.lastPosition(); | - | ||||||||||||||||||||||||
| 879 | - | |||||||||||||||||||||||||
| 880 | for (int r = row + 1; r < row + rowSpan
| 0 | ||||||||||||||||||||||||
| 881 | - | |||||||||||||||||||||||||
| 882 | int gridIndex = r * d->nCols + column; | - | ||||||||||||||||||||||||
| 883 | QVector<int>::iterator it = std::upper_bound(d->cellIndices.begin(), d->cellIndices.end(), gridIndex); | - | ||||||||||||||||||||||||
| 884 | int cellIndex = it - d->cellIndices.begin(); | - | ||||||||||||||||||||||||
| 885 | int fragment = d->cells.value(cellIndex, d->fragment_end); | - | ||||||||||||||||||||||||
| 886 | rowPositions[r - row] = p->fragmentMap().position(fragment); | - | ||||||||||||||||||||||||
| 887 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 888 | - | |||||||||||||||||||||||||
| 889 | fmt.setTableCellColumnSpan(1); | - | ||||||||||||||||||||||||
| 890 | fmt.setTableCellRowSpan(1); | - | ||||||||||||||||||||||||
| 891 | const int fmtIndex = c->indexForFormat(fmt); | - | ||||||||||||||||||||||||
| 892 | const int blockIndex = p->blockMap().find(cell.lastPosition())->format; | - | ||||||||||||||||||||||||
| 893 | - | |||||||||||||||||||||||||
| 894 | int insertAdjustement = 0; | - | ||||||||||||||||||||||||
| 895 | for (int i = 0; i < numRows
| 0 | ||||||||||||||||||||||||
| 896 | for (int c = 0; c < colSpan - numCols
| 0 | ||||||||||||||||||||||||
| 897 | p->insertBlock(QChar(0xfdd0), rowPositions[i] + insertAdjustement + c, blockIndex, fmtIndex); never executed: p->insertBlock(QChar(0xfdd0), rowPositions[i] + insertAdjustement + c, blockIndex, fmtIndex); | 0 | ||||||||||||||||||||||||
| 898 | insertAdjustement += colSpan - numCols; | - | ||||||||||||||||||||||||
| 899 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 900 | - | |||||||||||||||||||||||||
| 901 | for (int i = numRows; i < rowSpan
| 0 | ||||||||||||||||||||||||
| 902 | for (int c = 0; c < colSpan
| 0 | ||||||||||||||||||||||||
| 903 | p->insertBlock(QChar(0xfdd0), rowPositions[i] + insertAdjustement + c, blockIndex, fmtIndex); never executed: p->insertBlock(QChar(0xfdd0), rowPositions[i] + insertAdjustement + c, blockIndex, fmtIndex); | 0 | ||||||||||||||||||||||||
| 904 | insertAdjustement += colSpan; | - | ||||||||||||||||||||||||
| 905 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 906 | - | |||||||||||||||||||||||||
| 907 | fmt.setTableCellRowSpan(numRows); | - | ||||||||||||||||||||||||
| 908 | fmt.setTableCellColumnSpan(numCols); | - | ||||||||||||||||||||||||
| 909 | p->setCharFormat(origCellPosition, 1, fmt); | - | ||||||||||||||||||||||||
| 910 | - | |||||||||||||||||||||||||
| 911 | p->endEditBlock(); | - | ||||||||||||||||||||||||
| 912 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 913 | - | |||||||||||||||||||||||||
| 914 | - | |||||||||||||||||||||||||
| 915 | - | |||||||||||||||||||||||||
| 916 | - | |||||||||||||||||||||||||
| 917 | - | |||||||||||||||||||||||||
| 918 | - | |||||||||||||||||||||||||
| 919 | int QTextTable::rows() const | - | ||||||||||||||||||||||||
| 920 | { | - | ||||||||||||||||||||||||
| 921 | const QTextTablePrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 922 | if (d->dirty
| 0 | ||||||||||||||||||||||||
| 923 | d->update(); never executed: d->update(); | 0 | ||||||||||||||||||||||||
| 924 | - | |||||||||||||||||||||||||
| 925 | return never executed: d->nRows;return d->nRows;never executed: return d->nRows; | 0 | ||||||||||||||||||||||||
| 926 | } | - | ||||||||||||||||||||||||
| 927 | - | |||||||||||||||||||||||||
| 928 | - | |||||||||||||||||||||||||
| 929 | - | |||||||||||||||||||||||||
| 930 | - | |||||||||||||||||||||||||
| 931 | - | |||||||||||||||||||||||||
| 932 | - | |||||||||||||||||||||||||
| 933 | int QTextTable::columns() const | - | ||||||||||||||||||||||||
| 934 | { | - | ||||||||||||||||||||||||
| 935 | const QTextTablePrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 936 | if (d->dirty
| 0 | ||||||||||||||||||||||||
| 937 | d->update(); never executed: d->update(); | 0 | ||||||||||||||||||||||||
| 938 | - | |||||||||||||||||||||||||
| 939 | return never executed: d->nCols;return d->nCols;never executed: return d->nCols; | 0 | ||||||||||||||||||||||||
| 940 | } | - | ||||||||||||||||||||||||
| 941 | QTextCursor QTextTable::rowStart(const QTextCursor &c) const | - | ||||||||||||||||||||||||
| 942 | { | - | ||||||||||||||||||||||||
| 943 | const QTextTablePrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 944 | QTextTableCell cell = cellAt(c); | - | ||||||||||||||||||||||||
| 945 | if (!cell.isValid()
| 0 | ||||||||||||||||||||||||
| 946 | return never executed: QTextCursor();return QTextCursor();never executed: return QTextCursor(); | 0 | ||||||||||||||||||||||||
| 947 | - | |||||||||||||||||||||||||
| 948 | int row = cell.row(); | - | ||||||||||||||||||||||||
| 949 | QTextDocumentPrivate *p = d->pieceTable; | - | ||||||||||||||||||||||||
| 950 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), d->grid[row*d->nCols]); | - | ||||||||||||||||||||||||
| 951 | return never executed: QTextCursorPrivate::fromPosition(p, it.position());return QTextCursorPrivate::fromPosition(p, it.position());never executed: return QTextCursorPrivate::fromPosition(p, it.position()); | 0 | ||||||||||||||||||||||||
| 952 | } | - | ||||||||||||||||||||||||
| 953 | QTextCursor QTextTable::rowEnd(const QTextCursor &c) const | - | ||||||||||||||||||||||||
| 954 | { | - | ||||||||||||||||||||||||
| 955 | const QTextTablePrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 956 | QTextTableCell cell = cellAt(c); | - | ||||||||||||||||||||||||
| 957 | if (!cell.isValid()
| 0 | ||||||||||||||||||||||||
| 958 | return never executed: QTextCursor();return QTextCursor();never executed: return QTextCursor(); | 0 | ||||||||||||||||||||||||
| 959 | - | |||||||||||||||||||||||||
| 960 | int row = cell.row() + 1; | - | ||||||||||||||||||||||||
| 961 | int fragment = row < d->nRows
| 0 | ||||||||||||||||||||||||
| 962 | QTextDocumentPrivate *p = d->pieceTable; | - | ||||||||||||||||||||||||
| 963 | QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment); | - | ||||||||||||||||||||||||
| 964 | return never executed: QTextCursorPrivate::fromPosition(p, it.position() - 1);return QTextCursorPrivate::fromPosition(p, it.position() - 1);never executed: return QTextCursorPrivate::fromPosition(p, it.position() - 1); | 0 | ||||||||||||||||||||||||
| 965 | } | - | ||||||||||||||||||||||||
| 966 | void QTextTable::setFormat(const QTextTableFormat &format) | - | ||||||||||||||||||||||||
| 967 | { | - | ||||||||||||||||||||||||
| 968 | QTextTableFormat fmt = format; | - | ||||||||||||||||||||||||
| 969 | - | |||||||||||||||||||||||||
| 970 | fmt.setColumns(columns()); | - | ||||||||||||||||||||||||
| 971 | QTextObject::setFormat(fmt); | - | ||||||||||||||||||||||||
| 972 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 973 | - | |||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |