当前位置: 首页>>代码示例>>C++>>正文


C++ QTextBlock::userData方法代码示例

本文整理汇总了C++中QTextBlock::userData方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextBlock::userData方法的具体用法?C++ QTextBlock::userData怎么用?C++ QTextBlock::userData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTextBlock的用法示例。


在下文中一共展示了QTextBlock::userData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: searchPreviousMatch

int ShaderEdit::searchPreviousMatch( QTextBlock block, int start, QString close, QString open )
{
	int skipNext = 0;
	--start;
	TextBlockData *data = (TextBlockData*)block.userData();
	
	do {
		if ( data ) {
			for ( int i = start; i >= 0; --i ) {
				ParenthesisInfo pi = data->parenthesis[i];
				QString s = pi.character;
				if ( s == open ) {
					if ( skipNext > 0 )
						--skipNext;
					else
						return block.position() + pi.position;
				}
				else if ( s == close )
					++skipNext;
			}
		}
		block = block.previous();
		data = (TextBlockData*)block.userData();
		if ( data )
			start = data->parenthesis.count() - 1;
	} while ( block.isValid() );
	
	return -1;
}
开发者ID:hftom,项目名称:MachinTruc,代码行数:29,代码来源:shaderedit.cpp

示例2: findOpeningMatch

static int findOpeningMatch(const QTextDocument *doc, int cursorPosition) {
  QTextBlock block = doc->findBlock(cursorPosition);
  TextBlockData *blockData =
    reinterpret_cast<TextBlockData *>(block.userData());

  if (!blockData->bracketPositions.isEmpty()) {
    int depth = 1;

    while (block.isValid()) {
      blockData = reinterpret_cast<TextBlockData *>(block.userData());

      if (blockData && !blockData->bracketPositions.isEmpty()) {
        for (int c = blockData->bracketPositions.count() - 1; c >= 0; --c) {
          int absPos = block.position() + blockData->bracketPositions.at(c);

          if (absPos >= cursorPosition - 1) continue;
          if (doc->characterAt(absPos) == '}') depth++;
          else depth--;
          if (depth == 0) return absPos;
        }
      }
      block = block.previous();
    }
  }
  return -1;
}
开发者ID:airlinepilot,项目名称:CAMotics,代码行数:26,代码来源:NCEdit.cpp

示例3: testCenteredItems

void TestDocumentLayout::testCenteredItems()
{
    initForNewTest("ListItem\nListItem\nListItem");

    KoListStyle listStyle;
    KoListLevelProperties llp;
    llp.setStyle(KoListStyle::DecimalItem);
    listStyle.setLevelProperties(llp);

    QTextBlock block = m_doc->begin(); // normal block
    QVERIFY(block.isValid());
    listStyle.applyStyle(block);
    block = block.next(); // centered block
    QVERIFY(block.isValid());
    listStyle.applyStyle(block);
    QTextBlockFormat fmt;
    fmt.setAlignment(Qt::AlignHCenter);
    QTextCursor cursor(block);
    cursor.mergeBlockFormat(fmt);
    block = block.next(); // centered RTL text.
    listStyle.applyStyle(block);
    cursor = QTextCursor(block);
    fmt.setProperty(KoParagraphStyle::TextProgressionDirection, KoText::RightLeftTopBottom);
    cursor.mergeBlockFormat(fmt);

    m_layout->layout();

    block = m_doc->begin();
    QTextLayout *layout = block.layout();
    QTextLine line1 = layout->lineAt(0);
    KoTextBlockData *data1 = dynamic_cast<KoTextBlockData *>(block.userData());
    QVERIFY(line1.isValid());
    QVERIFY(line1.width() < 200); // the counter takes some space.

    block = block.next();
    layout = block.layout();
    QTextLine line2 = layout->lineAt(0);
    KoTextBlockData *data2 = dynamic_cast<KoTextBlockData *>(block.userData());
    QVERIFY(line2.isValid());
    QVERIFY(line2.width() < 200); // the counter takes some space.
    QCOMPARE(line1.width(), line2.width());

    const qreal width1 = line1.naturalTextWidth() + data1->counterWidth() + data1->counterSpacing();
    const qreal width2 = line2.naturalTextWidth() + data2->counterWidth() + data2->counterSpacing();
    QCOMPARE(width1, width2);
    QVERIFY(data1->counterPosition().x() < data2->counterPosition().x());
    const qreal padding = (200 - width2) / 2;
    QVERIFY(padding > 0);// not really a layout test, but the rest will be bogus otherwise.
    QCOMPARE(data2->counterPosition().x(), padding); // close to the centered text.

    // right to left parag places the counter on the right. Its centered, so not the far right.
    block = block.next();
    layout = block.layout();
    QTextLine line = layout->lineAt(0);
    KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
    QCOMPARE(data->counterPosition().x(), 200 - padding - data->counterWidth());
}
开发者ID:HOST-Oman,项目名称:krita,代码行数:57,代码来源:TestLists.cpp

示例4: dictionaryChanged

void Document::dictionaryChanged()
{
	for (QTextBlock i = m_text->document()->begin(); i != m_text->document()->end(); i = i.next()) {
		if (i.userData()) {
			static_cast<BlockStats*>(i.userData())->checkSpelling(i.text(), m_dictionary);
		}
	}
	m_highlighter->rehighlight();
}
开发者ID:quickhand,项目名称:Prosit,代码行数:9,代码来源:document.cpp

示例5: testListParagraphIndent

void TestDocumentLayout::testListParagraphIndent()
{
    // test that the list item is drawn indented on an indented paragraph.
    initForNewTest("Foo\nBar\n");

    KoParagraphStyle h1;
    m_styleManager->add(&h1);
    KoParagraphStyle h2;
    m_styleManager->add(&h2);
    h2.setTextIndent(10);

    KoListStyle listStyle;
    h1.setListStyle(&listStyle);
    KoListStyle listStyle2;
    h2.setListStyle(&listStyle2);

    QTextBlock block = m_doc->begin();
    h1.applyStyle(block);
    block = block.next();
    h2.applyStyle(block);

    m_layout->layout();

    // still at h2 parag!
    KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
    QVERIFY(data);
    QCOMPARE(data->counterPosition(), QPointF(10, 14.4));
}
开发者ID:HOST-Oman,项目名称:krita,代码行数:28,代码来源:TestLists.cpp

示例6: if

    TokenIterator& operator --()
    {
        if(idx > 0)
        {
            --idx;
            return *this;
        }
        else if( idx < 0 )
        {
            return *this;
        }

        idx = -1;
        while( (blk = blk.previous()).isValid() )
        {
            data = static_cast<TextBlockData*>(blk.userData());

            if(data)
                idx = data->tokens.size() - 1;

            if (idx < 0)
                continue;

            // we have a valid idx
            break;
        }

        return *this;
    }
开发者ID:smrg-lm,项目名称:supercollider,代码行数:29,代码来源:tokens.hpp

示例7: around

    // Return an iterator for the token at 'pos' or 'pos-1'.
    // If there is no such token, the returned iterator is invalid.
    static TokenIterator around( const QTextBlock & block, int positionInBlock )
    {
        TokenIterator it;
        it.blk = block;
        it.idx = -1;

        if(!block.isValid())
            return it;

        it.data = static_cast<TextBlockData*>(block.userData());

        if (!it.data)
            return it;

        int n = it.data->tokens.size();
        for( int i = 0; i < n; ++i )
        {
            Token const & token = it.data->tokens[i];
            if(token.positionInBlock > positionInBlock) {
                return it;
            }
            else if(token.positionInBlock == positionInBlock - 1 || token.positionInBlock == positionInBlock)
            {
                it.idx = i;
                break;
            }
        }

        return it;
    }
开发者ID:smrg-lm,项目名称:supercollider,代码行数:32,代码来源:tokens.hpp

示例8: testRightToLeftList

void TestDocumentLayout::testRightToLeftList()
{
    initForNewTest("a\nb\nc");
    KoParagraphStyle h1;
    h1.setTextProgressionDirection(KoText::RightLeftTopBottom);
    m_styleManager->add(&h1);
    KoListStyle listStyle;
    KoListLevelProperties llp = listStyle.levelProperties(1);
    llp.setStyle(KoListStyle::DecimalItem);
    listStyle.setLevelProperties(llp);
    h1.setListStyle(&listStyle);

    QTextBlock block = m_doc->begin();
    h1.applyStyle(block);
    block = block.next();
    h1.applyStyle(block);
    block = block.next();
    h1.applyStyle(block);
    block = block.next();

    m_layout->layout();

    block = m_doc->begin();
    while (block.isValid()) {
        KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
        QVERIFY(data);
        QVERIFY(data->counterWidth() > 2);
        QVERIFY(data->counterPosition().x() > 100);
        QTextLine line = block.layout()->lineAt(0);
        QVERIFY(line.isValid());
        QCOMPARE(line.x(), (qreal)0);
        QCOMPARE(line.width() + data->counterWidth() + data->counterSpacing(), (qreal)200);
        block = block.next();
    }
}
开发者ID:HOST-Oman,项目名称:krita,代码行数:35,代码来源:TestLists.cpp

示例9: testLetterSynchronization

void TestDocumentLayout::testLetterSynchronization()
{
    // make numbering be  'y, z, aa, bb, cc'
    initForNewTest("a\nb\na\nb\nc");

    KoParagraphStyle h1;
    m_styleManager->add(&h1);
    KoListStyle listStyle;
    KoListLevelProperties llp;
    llp.setStyle(KoListStyle::AlphaLowerItem);
    llp.setLetterSynchronization(true);
    llp.setStartValue(25);
    listStyle.setLevelProperties(llp);
    h1.setListStyle(&listStyle);

    QTextBlock block = m_doc->begin();
    while (block.isValid()) {
        h1.applyStyle(block);
        block = block.next();
    }

    m_layout->layout();

    static const char *const values[] = { "y", "z", "aa", "bb", "cc" };
    block = m_doc->begin();
    int i = 0;
    while (block.isValid()) {
        KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
        QVERIFY(data);
        // qDebug() << "-> " << data->counterText() << endl;
        QCOMPARE(data->counterText(), QString(values[i++]));

        block = block.next();
    }
}
开发者ID:HOST-Oman,项目名称:krita,代码行数:35,代码来源:TestLists.cpp

示例10: searchNextMatch

int ShaderEdit::searchNextMatch( QTextBlock block, int start, QString open, QString close )
{
	int skipNext = 0;
	int i = start + 1;
	
	do {
		TextBlockData *data = (TextBlockData*)block.userData();
		if ( data ) {
			for ( ; i < data->parenthesis.count(); ++i ) {
				ParenthesisInfo pi = data->parenthesis[i];
				QString s = pi.character;
				if ( s == close ) {
					if ( skipNext > 0 )
						--skipNext;
					else
						return block.position() + pi.position;
				}
				else if ( s == open )
					++skipNext;
			}
		}
		block = block.next();
		i = 0;
	} while ( block.isValid() );
	
	return -1;
}
开发者ID:hftom,项目名称:MachinTruc,代码行数:27,代码来源:shaderedit.cpp

示例11: clearBlockObsoletePreviewInfo

void VPreviewManager::clearBlockObsoletePreviewInfo(long long p_timeStamp,
                                                    PreviewSource p_source)
{
    OrderedIntSet affectedBlocks;
    QVector<int> obsoleteBlocks;
    const QSet<int> &blocks = m_highlighter->getPossiblePreviewBlocks();
    for (auto i : blocks) {
        QTextBlock block = m_document->findBlockByNumber(i);
        if (!block.isValid()) {
            obsoleteBlocks.append(i);
            continue;
        }

        VTextBlockData *blockData = dynamic_cast<VTextBlockData *>(block.userData());
        if (!blockData) {
            continue;
        }

        if (blockData->clearObsoletePreview(p_timeStamp, p_source)) {
            affectedBlocks.insert(i, QMapDummyValue());
        }

        if (blockData->getPreviews().isEmpty()) {
            obsoleteBlocks.append(i);
        }
    }

    m_highlighter->clearPossiblePreviewBlocks(obsoleteBlocks);

    m_editor->relayout(affectedBlocks);
}
开发者ID:getwindow,项目名称:vnote,代码行数:31,代码来源:vpreviewmanager.cpp

示例12: updateCache

void KPrAttributeHeight::updateCache(KPrAnimationCache *cache, KPrShapeAnimation *shapeAnimation, qreal value)
{
    qreal tx = 0.0, ty = 0.0;
    KoShape * shape = shapeAnimation->shape();
    KoTextBlockData * textBlockData = shapeAnimation->textBlockData();
    QTransform transform;
    if (textBlockData) {
        if (KoTextShapeData *textShapeData = dynamic_cast<KoTextShapeData*>(shape->userData())) {
            QTextDocument *textDocument = textShapeData->document();
            for (int i = 0; i < textDocument->blockCount(); i++) {
                QTextBlock textBlock = textDocument->findBlockByNumber(i);
                if (textBlock.userData() == textBlockData) {
                    QTextLayout *layout = textBlock.layout();
                    value = value * cache->pageSize().height() / layout->boundingRect().height();
                    tx = layout->minimumWidth() * cache->zoom() / 2;
                    ty = layout->boundingRect().height() * cache->zoom() / 2;
                }
            }
        }
    }
    else {
        value = value * cache->pageSize().height() / shape->size().height();
        tx = shape->size().width() * cache->zoom() / 2;
        ty = shape->size().height() * cache->zoom() / 2;
    }
    transform.translate(tx, ty).scale(1, value).translate(-tx, -ty);
    cache->update(shape, shapeAnimation->textBlockData(), "transform", transform);
}
开发者ID:KDE,项目名称:calligra-history,代码行数:28,代码来源:KPrAttributeHeight.cpp

示例13: initCache

void KPrAttributeHeight::initCache(KPrAnimationCache *animationCache, int step, KPrShapeAnimation * shapeAnimation, qreal startValue, qreal endValue)
{
    qreal v1 = 0.0, v2 = 0.0, tx = 0.0, ty = 0.0;
    KoShape * shape = shapeAnimation->shape();
    KoTextBlockData * textBlockData = shapeAnimation->textBlockData();

    if (textBlockData) {
        if (KoTextShapeData *textShapeData = dynamic_cast<KoTextShapeData*>(shape->userData())) {
            QTextDocument *textDocument = textShapeData->document();
            for (int i = 0; i < textDocument->blockCount(); i++) {
                QTextBlock textBlock = textDocument->findBlockByNumber(i);
                if (textBlock.userData() == textBlockData) {
                    QTextLayout *layout = textBlock.layout();
                    v1 = startValue * animationCache->pageSize().height() / layout->boundingRect().height();
                    v2 = endValue * animationCache->pageSize().height() / layout->boundingRect().height();
                    tx = layout->minimumWidth() * animationCache->zoom() / 2;
                    ty = layout->boundingRect().height() * animationCache->zoom() / 2;
                }
            }
        }
    }
    else {
        v1 = startValue * animationCache->pageSize().height() / shape->size().height();
        v2 = endValue * animationCache->pageSize().height() / shape->size().height();
        tx = shape->size().width() * animationCache->zoom() / 2;
        ty = shape->size().height() * animationCache->zoom() / 2;
    }
    animationCache->init(step, shape, textBlockData, "transform", QTransform().translate(tx, ty).scale(1, v1).translate(-tx, -ty));
    animationCache->init(step + 1, shape, textBlockData, "transform", QTransform().translate(tx, ty).scale(1, v2).translate(-tx, -ty));
}
开发者ID:KDE,项目名称:calligra-history,代码行数:30,代码来源:KPrAttributeHeight.cpp

示例14: matchRightParenthesis

bool CodeEditor::matchRightParenthesis(QTextBlock currentBlock, int i, int numRightParentheses)
{
    TextBlockData *data = static_cast<TextBlockData *>(currentBlock.userData());
    QVector<ParenthesisInfo *> parentheses = data->parentheses();

    int docPos = currentBlock.position();
    for (; i > -1 && parentheses.size() > 0; --i)
    {
        ParenthesisInfo *info = parentheses.at(i);
        if (info->character == ')')
        {
            ++numRightParentheses;
            continue;
        }
        if (info->character == '(' && numRightParentheses == 0)
        {
            createParenthesisSelection(docPos + info->position);
            return true;
        }
        else
        {
            --numRightParentheses;
        }
    }

    currentBlock = currentBlock.previous();
    if (currentBlock.isValid())
        return matchRightParenthesis(currentBlock, 0, numRightParentheses);

    return false;
}
开发者ID:calaos,项目名称:calaos_installer,代码行数:31,代码来源:CodeEditor.cpp

示例15: testInvalidateLists

void TestDocumentLayout::testInvalidateLists()
{
    initForNewTest("Base\nListItem1\nListItem2");

    //KoParagraphStyle style;
    KoListStyle listStyle;
    KoListLevelProperties llp;
    llp.setStyle(KoListStyle::DecimalItem);
    listStyle.setLevelProperties(llp);
    //style.setListStyle(&listStyle);

    QTextBlock block = m_doc->begin().next();
    QVERIFY(block.isValid());
    listStyle.applyStyle(block);
    block = block.next();
    QVERIFY(block.isValid());
    listStyle.applyStyle(block);

    m_layout->layout();

    // check the list items were done (semi) properly
    block = m_doc->begin().next();
    QVERIFY(block.textList());
    KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
    QVERIFY(data);
    QVERIFY(data->hasCounterData());

    QTextCursor cursor(m_doc);
    cursor.setPosition(10); // list item1
    cursor.insertText("x");
    QCOMPARE(data->hasCounterData(), true); // nothing changed

    cursor.setPosition(22); // list item2
    cursor.insertText("x");
    QCOMPARE(data->hasCounterData(), true); // nothing changed
    cursor.deleteChar();
    QCOMPARE(data->hasCounterData(), true); // nothing changed

    cursor.setPosition(25); // end of doc
    cursor.insertBlock();
    block = cursor.block();
    QVERIFY(block.textList());
    QVERIFY(block.userData() == 0);

    QCOMPARE(data->hasCounterData(), false); // inserting a new block on this list made the list be invalidated
}
开发者ID:HOST-Oman,项目名称:krita,代码行数:46,代码来源:TestLists.cpp


注:本文中的QTextBlock::userData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。