本文整理汇总了C++中QTextDocumentPrivate::remove方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocumentPrivate::remove方法的具体用法?C++ QTextDocumentPrivate::remove怎么用?C++ QTextDocumentPrivate::remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocumentPrivate
的用法示例。
在下文中一共展示了QTextDocumentPrivate::remove方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeRows
/*!
\fn void QTextTable::removeRows(int index, int rows)
Removes a number of \a rows starting with the row at the specified \a index.
\sa insertRows(), insertColumns(), resize(), removeColumns(), appendRows(), appendColumns()
*/
void QTextTable::removeRows(int pos, int num)
{
Q_D(QTextTable);
// qDebug() << "-------- removeRows" << pos << num;
if (num <= 0 || pos < 0)
return;
if (d->dirty)
d->update();
if (pos >= d->nRows)
return;
if (pos+num > d->nRows)
num = d->nRows - pos;
QTextDocumentPrivate *p = d->pieceTable;
QTextFormatCollection *collection = p->formatCollection();
p->beginEditBlock();
// delete whole table?
if (pos == 0 && num == d->nRows) {
const int pos = p->fragmentMap().position(d->fragment_start);
p->remove(pos, p->fragmentMap().position(d->fragment_end) - pos + 1);
p->endEditBlock();
return;
}
p->aboutToRemoveCell(cellAt(pos, 0).firstPosition(), cellAt(pos + num - 1, d->nCols - 1).lastPosition());
QList<int> touchedCells;
for (int r = pos; r < pos + num; ++r) {
for (int c = 0; c < d->nCols; ++c) {
int cell = d->grid[r*d->nCols + c];
if (touchedCells.contains(cell))
continue;
touchedCells << cell;
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
QTextCharFormat fmt = collection->charFormat(it->format);
int span = fmt.tableCellRowSpan();
if (span > 1) {
fmt.setTableCellRowSpan(span - 1);
p->setCharFormat(it.position(), 1, fmt);
} else {
// remove cell
int index = d->cells.indexOf(cell) + 1;
int f_end = index < d->cells.size() ? d->cells.at(index) : d->fragment_end;
p->remove(it.position(), p->fragmentMap().position(f_end) - it.position());
}
}
}
p->endEditBlock();
// qDebug() << "-------- end removeRows" << pos << num;
}
示例2: removeColumns
/*!
\fn void QTextTable::removeColumns(int index, int columns)
Removes a number of \a columns starting with the column at the specified
\a index.
\sa insertRows() insertColumns() removeRows() resize()
*/
void QTextTable::removeColumns(int pos, int num)
{
Q_D(QTextTable);
// qDebug() << "-------- removeCols" << pos << num;
if (num <= 0 || pos < 0)
return;
if (d->dirty)
d->update();
if (pos >= d->nCols)
return;
if (pos + num > d->nCols)
pos = d->nCols - num;
QTextDocumentPrivate *p = d->pieceTable;
QTextFormatCollection *collection = p->formatCollection();
p->beginEditBlock();
// delete whole table?
if (pos == 0 && num == d->nCols) {
const int pos = p->fragmentMap().position(d->fragment_start);
p->remove(pos, p->fragmentMap().position(d->fragment_end) - pos + 1);
p->endEditBlock();
return;
}
for (int r = 0; r < d->nRows; ++r) {
for (int c = pos; c < pos + num; ++c) {
int cell = d->grid[r*d->nCols + c];
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
QTextCharFormat fmt = collection->charFormat(it->format);
int span = fmt.tableCellColumnSpan();
if (span > 1) {
fmt.setTableCellColumnSpan(span - 1);
p->setCharFormat(it.position(), 1, fmt);
} else {
// remove cell
int index = d->cells.indexOf(cell) + 1;
int f_end = index < d->cells.size() ? d->cells.at(index) : d->fragment_end;
p->remove(it.position(), p->fragmentMap().position(f_end) - it.position());
}
}
}
QTextTableFormat tfmt = format();
tfmt.setColumns(tfmt.columns()-num);
QTextObject::setFormat(tfmt);
p->endEditBlock();
// qDebug() << "-------- end removeCols" << pos << num;
}
示例3: mergeCells
//.........这里部分代码省略.........
QFragmentFindHelper helper(origCellPosition, p->fragmentMap());
QList<int>::Iterator it = qBinaryFind(d->cells.begin(), d->cells.end(), helper);
Q_ASSERT(it != d->cells.end());
Q_ASSERT(*it == cellFragment);
const int insertCellIndex = it - d->cells.begin();
int insertFragment = d->cells.value(insertCellIndex + 1, d->fragment_end);
uint insertPos = p->fragmentMap().position(insertFragment);
d->blockFragmentUpdates = true;
bool rowHasText = cell.firstCursorPosition().block().length();
bool needsParagraph = rowHasText && colSpan == numCols;
// find all cells that will be erased by the merge
for (int r = row; r < row + numRows; ++r) {
int firstColumn = r < row + rowSpan ? column + colSpan : column;
// don't recompute the cell index for the first row
int firstCellIndex = r == row ? insertCellIndex + 1 : -1;
int cellIndex = firstCellIndex;
for (int c = firstColumn; c < column + numCols; ++c) {
const int fragment = d->grid[r * d->nCols + c];
// already handled?
if (fragment == cellFragment)
continue;
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment);
uint pos = it.position();
if (firstCellIndex == -1) {
QFragmentFindHelper helper(pos, p->fragmentMap());
QList<int>::Iterator it = qBinaryFind(d->cells.begin(), d->cells.end(), helper);
Q_ASSERT(it != d->cells.end());
Q_ASSERT(*it == fragment);
firstCellIndex = cellIndex = it - d->cells.begin();
}
++cellIndex;
QTextCharFormat fmt = fc->charFormat(it->format);
const int cellRowSpan = fmt.tableCellRowSpan();
const int cellColSpan = fmt.tableCellColumnSpan();
// update the grid for this cell
for (int i = r; i < r + cellRowSpan; ++i)
for (int j = c; j < c + cellColSpan; ++j)
d->grid[i * d->nCols + j] = cellFragment;
// erase the cell marker
p->remove(pos, 1);
const int nextFragment = d->cells.value(cellIndex, d->fragment_end);
const uint nextPos = p->fragmentMap().position(nextFragment);
Q_ASSERT(nextPos >= pos);
// merge the contents of the cell (if not empty)
if (nextPos > pos) {
if (needsParagraph) {
needsParagraph = false;
QTextCursor(p, insertPos++).insertBlock();
p->move(pos + 1, insertPos, nextPos - pos);
} else if (rowHasText) {
QTextCursor(p, insertPos++).insertText(QLatin1String(" "));
p->move(pos + 1, insertPos, nextPos - pos);
} else {
p->move(pos, insertPos, nextPos - pos);
}
insertPos += nextPos - pos;
rowHasText = true;
}
}
if (rowHasText) {
needsParagraph = true;
rowHasText = false;
}
// erase cells from last row
if (firstCellIndex >= 0) {
d->cellIndices.remove(firstCellIndex, cellIndex - firstCellIndex);
d->cells.erase(d->cells.begin() + firstCellIndex, d->cells.begin() + cellIndex);
}
}
d->fragment_start = d->cells.first();
fmt.setTableCellRowSpan(numRows);
fmt.setTableCellColumnSpan(numCols);
p->setCharFormat(origCellPosition, 1, fmt);
d->blockFragmentUpdates = false;
d->dirty = false;
p->endEditBlock();
}
示例4: removeColumns
/*!
\fn void QTextTable::removeColumns(int index, int columns)
Removes a number of \a columns starting with the column at the specified
\a index.
\sa insertRows(), insertColumns(), removeRows(), resize(), appendRows(), appendColumns()
*/
void QTextTable::removeColumns(int pos, int num)
{
Q_D(QTextTable);
// qDebug() << "-------- removeCols" << pos << num;
if (num <= 0 || pos < 0)
return;
if (d->dirty)
d->update();
if (pos >= d->nCols)
return;
if (pos + num > d->nCols)
pos = d->nCols - num;
QTextDocumentPrivate *p = d->pieceTable;
QTextFormatCollection *collection = p->formatCollection();
p->beginEditBlock();
// delete whole table?
if (pos == 0 && num == d->nCols) {
const int pos = p->fragmentMap().position(d->fragment_start);
p->remove(pos, p->fragmentMap().position(d->fragment_end) - pos + 1);
p->endEditBlock();
return;
}
p->aboutToRemoveCell(cellAt(0, pos).firstPosition(), cellAt(d->nRows - 1, pos + num - 1).lastPosition());
QList<int> touchedCells;
for (int r = 0; r < d->nRows; ++r) {
for (int c = pos; c < pos + num; ++c) {
int cell = d->grid[r*d->nCols + c];
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
QTextCharFormat fmt = collection->charFormat(it->format);
int span = fmt.tableCellColumnSpan();
if (touchedCells.contains(cell) && span <= 1)
continue;
touchedCells << cell;
if (span > 1) {
fmt.setTableCellColumnSpan(span - 1);
p->setCharFormat(it.position(), 1, fmt);
} else {
// remove cell
int index = d->cells.indexOf(cell) + 1;
int f_end = index < d->cells.size() ? d->cells.at(index) : d->fragment_end;
p->remove(it.position(), p->fragmentMap().position(f_end) - it.position());
}
}
}
QTextTableFormat tfmt = format();
tfmt.setColumns(tfmt.columns()-num);
QVector<QTextLength> columnWidths = tfmt.columnWidthConstraints();
if (columnWidths.count() > pos) {
columnWidths.remove(pos, num);
tfmt.setColumnWidthConstraints (columnWidths);
}
QTextObject::setFormat(tfmt);
p->endEditBlock();
// qDebug() << "-------- end removeCols" << pos << num;
}