⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtextobject.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*!  \internal*/void QTextFrame::setLayoutData(QTextFrameLayoutData *data){    Q_D(QTextFrame);    delete d->layoutData;    d->layoutData = data;}void QTextFramePrivate::fragmentAdded(const QChar &type, uint fragment){    if (type == QTextBeginningOfFrame) {        Q_ASSERT(!fragment_start);        fragment_start = fragment;    } else if (type == QTextEndOfFrame) {        Q_ASSERT(!fragment_end);        fragment_end = fragment;    } else if (type == QChar::ObjectReplacementCharacter) {        Q_ASSERT(!fragment_start);        Q_ASSERT(!fragment_end);        fragment_start = fragment;        fragment_end = fragment;    } else {        Q_ASSERT(false);    }}void QTextFramePrivate::fragmentRemoved(const QChar &type, uint fragment){    Q_UNUSED(fragment); // --release warning    if (type == QTextBeginningOfFrame) {        Q_ASSERT(fragment_start == fragment);        fragment_start = 0;    } else if (type == QTextEndOfFrame) {        Q_ASSERT(fragment_end == fragment);        fragment_end = 0;    } else if (type == QChar::ObjectReplacementCharacter) {        Q_ASSERT(fragment_start == fragment);        Q_ASSERT(fragment_end == fragment);        fragment_start = 0;        fragment_end = 0;    } else {        Q_ASSERT(false);    }    remove_me();}void QTextFramePrivate::remove_me(){    Q_Q(QTextFrame);    if (fragment_start == 0 && fragment_end == 0        && !parentFrame) {        q->document()->docHandle()->deleteObject(q);        return;    }    if (!parentFrame)        return;    int index = parentFrame->d_func()->childFrames.indexOf(q);    // iterator over all children and move them to the parent    for (int i = 0; i < childFrames.size(); ++i) {        QTextFrame *c = childFrames.at(i);        parentFrame->d_func()->childFrames.insert(index, c);        c->d_func()->parentFrame = parentFrame;        ++index;    }    Q_ASSERT(parentFrame->d_func()->childFrames.at(index) == q);    parentFrame->d_func()->childFrames.removeAt(index);    childFrames.clear();    parentFrame = 0;}/*!    \class QTextFrame::iterator    \brief The iterator class provides an iterator for reading    the contents of a QTextFrame.    \ingroup text    A frame consists of an arbitrary sequence of \l{QTextBlock}s and    child \l{QTextFrame}s. This class provides a way to iterate over the    child objects of a frame, and read their contents. It does not provide    a way to modify the contents of the frame.*//*!    \fn bool QTextFrame::iterator::atEnd() const    Returns true if the current item is the last item in the text frame.*//*!    Returns an iterator pointing to the first document element inside the frame.    \sa end()*/QTextFrame::iterator QTextFrame::begin() const{    const QTextDocumentPrivate *priv = docHandle();    int b = priv->blockMap().findNode(firstPosition());    int e = priv->blockMap().findNode(lastPosition()+1);    return iterator(const_cast<QTextFrame *>(this), b, b, e);}/*!    Returns an iterator pointing to the last document element inside the frame.    \sa begin()*/QTextFrame::iterator QTextFrame::end() const{    const QTextDocumentPrivate *priv = docHandle();    int b = priv->blockMap().findNode(firstPosition());    int e = priv->blockMap().findNode(lastPosition()+1);    return iterator(const_cast<QTextFrame *>(this), e, b, e);}/*!    Constructs an invalid iterator.*/QTextFrame::iterator::iterator(){    f = 0;    b = 0;    e = 0;    cf = 0;    cb = 0;}/*!  \internal*/QTextFrame::iterator::iterator(QTextFrame *frame, int block, int begin, int end){    f = frame;    b = begin;    e = end;    cf = 0;    cb = block;}/*!    Copy constructor. Constructs a copy of the \a other iterator.*/QTextFrame::iterator::iterator(const iterator &other){    f = other.f;    b = other.b;    e = other.e;    cf = other.cf;    cb = other.cb;}/*!    Assigns \a other to this iterator and returns a reference to    this iterator.*/QTextFrame::iterator &QTextFrame::iterator::operator=(const iterator &other){    f = other.f;    b = other.b;    e = other.e;    cf = other.cf;    cb = other.cb;    return *this;}/*!    Returns the current frame pointed to by the iterator, or 0 if the    iterator currently points to a block.    \sa currentBlock()*/QTextFrame *QTextFrame::iterator::currentFrame() const{    return cf;}/*!    Returns the current block the iterator points to. If the iterator    points to a child frame, the returned block is invalid.    \sa currentFrame()*/QTextBlock QTextFrame::iterator::currentBlock() const{    if (!f)        return QTextBlock();    return QTextBlock(f->docHandle(), cb);}/*!    Moves the iterator to the next frame or block.    \sa currentBlock() currentFrame()*/QTextFrame::iterator &QTextFrame::iterator::operator++(){    const QTextDocumentPrivate *priv = f->docHandle();    const QTextDocumentPrivate::BlockMap &map = priv->blockMap();    if (cf) {        int end = cf->lastPosition() + 1;        cb = map.findNode(end);        cf = 0;    } else if (cb) {        cb = map.next(cb);        if (cb == e)            return *this;        int pos = map.position(cb);        // check if we entered a frame        QTextDocumentPrivate::FragmentIterator frag = priv->find(pos-1);        if (priv->buffer().at(frag->stringPosition) != QChar::ParagraphSeparator) {            QTextFrame *nf = qobject_cast<QTextFrame *>(priv->objectForFormat(frag->format));            if (nf) {                if (priv->buffer().at(frag->stringPosition) == QTextBeginningOfFrame && nf != f) {                    cf = nf;                    cb = 0;                } else {                    Q_ASSERT(priv->buffer().at(frag->stringPosition) != QTextEndOfFrame);                }            }        }    }    return *this;}/*!    Moves the iterator to the previous frame or block.    \sa currentBlock() currentFrame()*/QTextFrame::iterator &QTextFrame::iterator::operator--(){    const QTextDocumentPrivate *priv = f->docHandle();    const QTextDocumentPrivate::BlockMap &map = priv->blockMap();    if (cf) {        int start = cf->firstPosition() - 1;        cb = map.findNode(start);        cf = 0;    } else {        if (cb == b)            goto end;        if (cb != e) {            int pos = map.position(cb);            // check if we have to enter a frame            QTextDocumentPrivate::FragmentIterator frag = priv->find(pos-1);            if (priv->buffer().at(frag->stringPosition) != QChar::ParagraphSeparator) {                QTextFrame *pf = qobject_cast<QTextFrame *>(priv->objectForFormat(frag->format));                if (pf) {                    if (priv->buffer().at(frag->stringPosition) == QTextBeginningOfFrame) {                        Q_ASSERT(pf == f);                    } else if (priv->buffer().at(frag->stringPosition) == QTextEndOfFrame) {                        Q_ASSERT(pf != f);                        cf = pf;                        cb = 0;                        goto end;                    }                }            }        }        cb = map.previous(cb);    } end:    return *this;}/*!    \class QTextBlockUserData    \brief The QTextBlockUserData class is used to associate custom data with blocks of text.    \since 4.1    \ingroup text    QTextBlockUserData provides an abstract interface for container classes that are used    to associate application-specific user data with text blocks in a QTextDocument.    Generally, subclasses of this class provide functions to allow data to be stored    and retrieved, and instances are attached to blocks of text using    QTextBlock::setUserData(). This makes it possible to store additional data per text    block in a way that can be retrieved safely by the application.    Each subclass should provide a reimplementation of the destructor to ensure that any    private data is automatically cleaned up when user data objects are deleted.    \sa QTextBlock*//*!    Destroys the user data.*/QTextBlockUserData::~QTextBlockUserData(){}/*!    \class QTextBlock qtextblock.h    \brief The QTextBlock class provides a container for text fragments in a    QTextDocument.    \ingroup text    A text block encapsulates a block or paragraph of text in a QTextDocument.    QTextBlock provides read-only access to the block/paragraph structure of    QTextDocuments. It is mainly of use if you want to implement your own    layouts for the visual representation of a QTextDocument, or if you want to    iterate over a document and write out the contents in your own custom    format.    Text blocks are created by their parent documents. If you need to create    a new text block, or modify the contents of a document while examining its    contents, use the cursor-based interface provided by QTextCursor instead.    Each text block is located at a specific position() in a document().    The contents of the block can be obtained by using the text() function.    The length() function determines the block's size within the document    (including formatting characters).    The visual properties of the block are determined by its text layout(),    its charFormat(), and its blockFormat().    The next() and previous() functions enable iteration over consecutive    valid blocks in a document under the condition that the document is not    modified by other means during the iteration process. Note that, although    blocks are returned in sequence, adjacent blocks may come from different    places in the document structure. The validity of a block can be determined    by calling isValid().    QTextBlock provides comparison operators to make it easier to work with    blocks: \l operator==() compares two block for equality, \l operator!=()    compares two blocks for inequality, and \l operator<() determines whether    a block precedes another in the same document.    \img qtextblock-sequence.png    \sa QTextBlockFormat QTextCharFormat QTextFragment *//*!    \fn QTextBlock::QTextBlock(QTextDocumentPrivate *priv, int b)    \internal*//*!    \fn QTextBlock::QTextBlock()    \internal*//*!    \fn QTextBlock::QTextBlock(const QTextBlock &other)    Copies the \a other text block's attributes to this text block.*//*!    \fn bool QTextBlock::isValid() const    Returns true if this text block is valid; otherwise returns false.*//*!    \fn QTextBlock &QTextBlock::operator=(const QTextBlock &other)    Assigns the \a other text block to this text block.*//*!    \fn bool QTextBlock::operator==(const QTextBlock &other) const    Returns true if this text block is the same as the \a other text    block.*//*!    \fn bool QTextBlock::operator!=(const QTextBlock &other) const    Returns true if this text block is different from the \a other    text block.*//*!    \fn bool QTextBlock::operator<(const QTextBlock &other) const    Returns true if this text block occurs before the \a other text    block in the document.*//*!    \class QTextBlock::iterator    \brief The QTextBlock::iterator class provides an iterator for reading    the contents of a QTextBlock.    \ingroup text    A block consists of a sequence of text fragments. This class provides    a way to iterate over these, and read their contents. It does not provide    a way to modify the internal structure or contents of the block.    An iterator can be constructed and used to access the fragments within    a text block in the following way:    \quotefromfile snippets/textblock-fragments/xmlwriter.cpp    \skipto QTextBlock::iterator    \printuntil processFragment    \skipuntil }    \printline }    \sa QTextFragment*//*!    \typedef QTextBlock::Iterator    Qt-style synonym for QTextBlock::iterator.*//*!    \fn QTextBlock::iterator::iterator()    Constructs an iterator for this text block.*//*!    \fn QTextBlock::iterator::iterator(const iterator &other)    Copy constructor. Constructs a copy of the \a other iterator.*//*!    \fn bool QTextBlock::iterator::atEnd() const    Returns true if the current item is the last item in the text block.*//*!    \fn bool QTextBlock::iterator::operator==(const iterator &other) const    Retuns true if this iterator is the same as the \a other iterator;    otherwise returns false.*//*!    \fn bool QTextBlock::iterator::operator!=(const iterator &other) const    Retuns true if this iterator is different from the \a other iterator;    otherwise returns false.*//*!    \fn QTextBlock::iterator QTextBlock::iterator::operator++(int)    The postfix ++ operator (\c{i++}) advances the iterator to the    next item in the text block and returns an iterator to the old current    item.*//*!    \fn QTextBlock::iterator QTextBlock::iterator::operator--(int)    The postfix -- operator (\c{i--}) makes the preceding item current and    returns an iterator to the old current item.*//*!    \fn QTextDocumentPrivate *QTextBlock::docHandle() const    \internal*//*!    Returns the index of the block's first character within the document. */int QTextBlock::position() const{    if (!p || !n)        return 0;    return p->blockMap().position(n);}/*!    Returns the length of the block in characters.    \sa text() charFormat() blockFormat() */int QTextBlock::length() const{    if (!p || !n)        return 0;    return p->blockMap().size(n);}/*!    Returns true if the given \a position is located within the text    block; otherwise returns false. */bool QTextBlock::contains(int position) const{    if (!p || !n)        return false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -