本文整理汇总了C++中QTextDocumentPrivate类的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocumentPrivate类的具体用法?C++ QTextDocumentPrivate怎么用?C++ QTextDocumentPrivate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextDocumentPrivate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hitTest
/*!
\fn QString QAbstractTextDocumentLayout::anchorAt(const QPointF &position) const
Returns the reference of the anchor the given \a position, or an empty
string if no anchor exists at that point.
*/
QString QAbstractTextDocumentLayout::anchorAt(const QPointF& pos) const
{
int cursorPos = hitTest(pos, Qt::ExactHit);
if (cursorPos == -1)
return QString();
// compensate for preedit in the hit text block
QTextBlock block = document()->firstBlock();
while (block.isValid()) {
QRectF blockBr = blockBoundingRect(block);
if (blockBr.contains(pos)) {
QTextLayout *layout = block.layout();
int relativeCursorPos = cursorPos - block.position();
const int preeditLength = layout ? layout->preeditAreaText().length() : 0;
if (preeditLength > 0 && relativeCursorPos > layout->preeditAreaPosition())
cursorPos -= qMin(cursorPos - layout->preeditAreaPosition(), preeditLength);
break;
}
block = block.next();
}
QTextDocumentPrivate *pieceTable = qobject_cast<const QTextDocument *>(parent())->docHandle();
QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos);
QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format);
return fmt.anchorHref();
}
示例2: begin
/*!
Returns a frame iterator pointing to the end of the table's cell.
\sa begin()
*/
QTextFrame::iterator QTextTableCell::end() const
{
QTextDocumentPrivate *p = table->docHandle();
int b = p->blockMap().findNode(firstPosition());
int e = p->blockMap().findNode(lastPosition()+1);
return QTextFrame::iterator(const_cast<QTextTable *>(table), e, b, e);
}
示例3: format
/*!
Returns the cell's character format.
*/
QTextCharFormat QTextTableCell::format() const
{
QTextDocumentPrivate *p = table->docHandle();
QTextFormatCollection *c = p->formatCollection();
QTextCharFormat fmt = c->charFormat(tableCellFormatIndex());
fmt.setObjectType(QTextFormat::TableCellObject);
return fmt;
}
示例4: format
/*!
Returns the cell's character format.
*/
QTextCharFormat QTextTableCell::format() const
{
QTextDocumentPrivate *p = table->docHandle();
QTextFormatCollection *c = p->formatCollection();
QTextCharFormat fmt = c->charFormat(QTextDocumentPrivate::FragmentIterator(&p->fragmentMap(), fragment)->format);
fmt.setObjectType(QTextFormat::TableCellObject);
return fmt;
}
示例5: resize
/*!
\fn void QTextTable::insertRows(int index, int rows)
Inserts a number of \a rows before the row with the specified \a index.
\sa resize() insertColumns() removeRows() removeColumns()
*/
void QTextTable::insertRows(int pos, int num)
{
Q_D(QTextTable);
if (num <= 0)
return;
if (d->dirty)
d->update();
if (pos > d->nRows || pos < 0)
pos = d->nRows;
// qDebug() << "-------- insertRows" << pos << num;
QTextDocumentPrivate *p = d->pieceTable;
QTextFormatCollection *c = p->formatCollection();
p->beginEditBlock();
int extended = 0;
int insert_before = 0;
if (pos > 0 && pos < d->nRows) {
for (int i = 0; i < d->nCols; ++i) {
int cell = d->grid[pos*d->nCols + i];
if (cell == d->grid[(pos-1)*d->nCols+i]) {
// cell spans the insertion place, extend it
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
QTextCharFormat fmt = c->charFormat(it->format);
fmt.setTableCellRowSpan(fmt.tableCellRowSpan() + num);
p->setCharFormat(it.position(), 1, fmt);
extended++;
} else if (!insert_before) {
insert_before = cell;
}
}
} else {
insert_before = (pos == 0 ? d->grid[0] : d->fragment_end);
}
if (extended < d->nCols) {
Q_ASSERT(insert_before);
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), insert_before);
QTextCharFormat fmt = c->charFormat(it->format);
fmt.setTableCellRowSpan(1);
fmt.setTableCellColumnSpan(1);
Q_ASSERT(fmt.objectIndex() == objectIndex());
int pos = it.position();
int cfmt = p->formatCollection()->indexForFormat(fmt);
int bfmt = p->formatCollection()->indexForFormat(QTextBlockFormat());
// qDebug("inserting %d cells, nCols=%d extended=%d", num*(d->nCols-extended), d->nCols, extended);
for (int i = 0; i < num*(d->nCols-extended); ++i)
p->insertBlock(QTextBeginningOfFrame, pos, bfmt, cfmt, QTextUndoCommand::MoveCursor);
}
// qDebug() << "-------- end insertRows" << pos << num;
p->endEditBlock();
}
示例6: hitTest
/*!
\fn QString QAbstractTextDocumentLayout::anchorAt(const QPointF &position) const
Returns the reference of the anchor the given \a position, or an empty
string if no anchor exists at that point.
*/
QString QAbstractTextDocumentLayout::anchorAt(const QPointF& pos) const
{
int cursorPos = hitTest(pos, Qt::ExactHit);
if (cursorPos == -1)
return QString();
QTextDocumentPrivate *pieceTable = qobject_cast<const QTextDocument *>(parent())->docHandle();
QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos);
QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format);
return fmt.anchorHref();
}
示例7: rowEnd
/*!
\fn QTextCursor QTextTable::rowStart(const QTextCursor &cursor) const
Returns a cursor pointing to the start of the row that contains the
given \a cursor.
\sa rowEnd()
*/
QTextCursor QTextTable::rowStart(const QTextCursor &c) const
{
Q_D(const QTextTable);
QTextTableCell cell = cellAt(c);
if (!cell.isValid())
return QTextCursor();
int row = cell.row();
QTextDocumentPrivate *p = d->pieceTable;
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), d->grid[row*d->nCols]);
return QTextCursor(p, it.position());
}
示例8: lastPosition
/*!
\internal
Returns the last valid position in the document occupied by this cell.
*/
int QTextTableCell::lastPosition() const
{
QTextDocumentPrivate *p = table->docHandle();
const QTextTablePrivate *td = table->d_func();
int index = table->d_func()->findCellIndex(fragment);
int f;
if (index != -1)
f = td->cells.value(index + 1, td->fragment_end);
else
f = td->fragment_end;
return p->fragmentMap().position(f);
}
示例9: rowStart
/*!
\fn QTextCursor QTextTable::rowEnd(const QTextCursor &cursor) const
Returns a cursor pointing to the end of the row that contains the given
\a cursor.
\sa rowStart()
*/
QTextCursor QTextTable::rowEnd(const QTextCursor &c) const
{
Q_D(const QTextTable);
QTextTableCell cell = cellAt(c);
if (!cell.isValid())
return QTextCursor();
int row = cell.row() + 1;
int fragment = row < d->nRows ? d->grid[row*d->nCols] : d->fragment_end;
QTextDocumentPrivate *p = d->pieceTable;
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment);
return QTextCursor(p, it.position() - 1);
}
示例10:
QTextObject *QTextDocumentPrivate::objectForIndex(int objectIndex) const
{
if (objectIndex < 0)
return 0;
QTextObject *object = objects.value(objectIndex, 0);
if (!object) {
QTextDocumentPrivate *that = const_cast<QTextDocumentPrivate *>(this);
QTextFormat fmt = formats.objectFormat(objectIndex);
object = that->createObject(fmt, objectIndex);
}
return object;
}
示例11: insert
void QTextDocumentFragmentPrivate::insert(QTextCursor &_cursor) const
{
if (_cursor.isNull())
return;
QTextDocumentPrivate *destPieceTable = _cursor.d->priv;
destPieceTable->beginEditBlock();
QTextCursor sourceCursor(doc);
sourceCursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
QTextCopyHelper(sourceCursor, _cursor, importedFromPlainText, _cursor.charFormat()).copy();
destPieceTable->endEditBlock();
}
示例12: insertRows
/*!
\fn void QTextTable::insertColumns(int index, int columns)
Inserts a number of \a columns before the column with the specified \a index.
\sa insertRows() resize() removeRows() removeColumns() appendRows() appendColumns()
*/
void QTextTable::insertColumns(int pos, int num)
{
Q_D(QTextTable);
if (num <= 0)
return;
if (d->dirty)
d->update();
if (pos > d->nCols || pos < 0)
pos = d->nCols;
// qDebug() << "-------- insertCols" << pos << num;
QTextDocumentPrivate *p = d->pieceTable;
QTextFormatCollection *c = p->formatCollection();
p->beginEditBlock();
for (int i = 0; i < d->nRows; ++i) {
int cell;
if (i == d->nRows - 1 && pos == d->nCols)
cell = d->fragment_end;
else
cell = d->grid[i*d->nCols + pos];
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
QTextCharFormat fmt = c->charFormat(it->format);
if (pos > 0 && pos < d->nCols && cell == d->grid[i*d->nCols + pos - 1]) {
// cell spans the insertion place, extend it
fmt.setTableCellColumnSpan(fmt.tableCellColumnSpan() + num);
p->setCharFormat(it.position(), 1, fmt);
} else {
fmt.setTableCellRowSpan(1);
fmt.setTableCellColumnSpan(1);
Q_ASSERT(fmt.objectIndex() == objectIndex());
int position = it.position();
int cfmt = p->formatCollection()->indexForFormat(fmt);
int bfmt = p->formatCollection()->indexForFormat(QTextBlockFormat());
for (int i = 0; i < num; ++i)
p->insertBlock(QTextBeginningOfFrame, position, bfmt, cfmt, QTextUndoCommand::MoveCursor);
}
}
QTextTableFormat tfmt = format();
tfmt.setColumns(tfmt.columns()+num);
QVector<QTextLength> columnWidths = tfmt.columnWidthConstraints();
if (! columnWidths.isEmpty()) {
for (int i = num; i > 0; --i)
columnWidths.insert(pos, columnWidths[qMax(0, pos-1)]);
}
tfmt.setColumnWidthConstraints (columnWidths);
QTextObject::setFormat(tfmt);
// qDebug() << "-------- end insertCols" << pos << num;
p->endEditBlock();
}
示例13: Q_Q
void QTextTablePrivate::update() const
{
Q_Q(const QTextTable);
nCols = q->format().columns();
nRows = (cells.size() + nCols-1)/nCols;
// qDebug(">>>> QTextTablePrivate::update, nRows=%d, nCols=%d", nRows, nCols);
grid = (int *)realloc(grid, nRows*nCols*sizeof(int));
memset(grid, 0, nRows*nCols*sizeof(int));
QTextDocumentPrivate *p = pieceTable;
QTextFormatCollection *c = p->formatCollection();
cellIndices.resize(cells.size());
int cell = 0;
for (int i = 0; i < cells.size(); ++i) {
int fragment = cells.at(i);
QTextCharFormat fmt = c->charFormat(QTextDocumentPrivate::FragmentIterator(&p->fragmentMap(), fragment)->format);
int rowspan = fmt.tableCellRowSpan();
int colspan = fmt.tableCellColumnSpan();
// skip taken cells
while (cell < nRows*nCols && grid[cell])
++cell;
int r = cell/nCols;
int c = cell%nCols;
cellIndices[i] = cell;
if (r + rowspan > nRows) {
grid = (int *)realloc(grid, sizeof(int)*(r + rowspan)*nCols);
memset(grid + (nRows*nCols), 0, sizeof(int)*(r+rowspan-nRows)*nCols);
nRows = r + rowspan;
}
Q_ASSERT(c + colspan <= nCols);
for (int ii = 0; ii < rowspan; ++ii) {
for (int jj = 0; jj < colspan; ++jj) {
Q_ASSERT(grid[(r+ii)*nCols + c+jj] == 0);
grid[(r+ii)*nCols + c+jj] = fragment;
// qDebug(" setting cell %d span=%d/%d at %d/%d", fragment, rowspan, colspan, r+ii, c+jj);
}
}
}
// qDebug("<<<< end: nRows=%d, nCols=%d", nRows, nCols);
dirty = false;
}
示例14: firstPosition
/*!
\internal
Returns the first valid position in the document occupied by this cell.
*/
int QTextTableCell::firstPosition() const
{
QTextDocumentPrivate *p = table->docHandle();
return p->fragmentMap().position(fragment) + 1;
}
示例15: format
/*!
\fn QTextCharFormat QAbstractTextDocumentLayout::format(int position)
Returns the character format that is applicable at the given \a position.
*/
QTextCharFormat QAbstractTextDocumentLayout::format(int pos)
{
QTextDocumentPrivate *pieceTable = qobject_cast<QTextDocument *>(parent())->docHandle();
int idx = pieceTable->find(pos).value()->format;
return pieceTable->formatCollection()->charFormat(idx);
}