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


C++ QTextDocument::begin方法代码示例

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


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

示例1: testFetchMoreText

void TestSpellCheck::testFetchMoreText()
{
    MySpellCheck checker;
    QTextDocument doc;
    QString text("some simple text\na second parag with more text\n");
    doc.setPlainText(text);

    checker.startRun(&doc, 0, text.size());
    QTextBlock block = doc.begin();
    QCOMPARE(checker.publicFetchMoreText(), block.text());
    block = block.next();
    QVERIFY(block.isValid());
    QCOMPARE(checker.publicFetchMoreText(), block.text());

    QTextCursor cursor(&doc);
    QTextCharFormat cf;
    cf.setProperty(KoCharacterStyle::Language, QVariant("pl"));
    cursor.setPosition(4, QTextCursor::KeepAnchor);
    cursor.mergeCharFormat(cf);

    checker.startRun(&doc, 0, text.size());
    block = doc.begin();
    QCOMPARE(checker.publicFetchMoreText(), QString("some"));
    QCOMPARE(checker.publicFetchMoreText(), block.text().mid(4));
    block = block.next();
    QVERIFY(block.isValid());
    QCOMPARE(checker.publicFetchMoreText(), block.text());

    // add some more
    cursor.setPosition(block.position() + 2);
    cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); // 'second'
    int position2 = cursor.anchor();
    int position3 = cursor.position();
    cf.setProperty(KoCharacterStyle::Language, QVariant("br"));
    cursor.mergeCharFormat(cf);
    cursor.movePosition(QTextCursor::NextWord, QTextCursor::MoveAnchor, 2);
    cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); // 'with'
    cf.setProperty(KoCharacterStyle::Language, QVariant("en"));
    cursor.mergeCharFormat(cf);

    checker.startRun(&doc, 0, text.size());
    checker.setDefaultLanguage("en_NZ");
    block = doc.begin();
    QCOMPARE(checker.publicFetchMoreText(), QString("some"));
    QCOMPARE(checker.publicFetchMoreText(), block.text().mid(4));
    block = block.next();
    QVERIFY(block.isValid());
    QCOMPARE(checker.publicFetchMoreText(), block.text().left(2));
    QCOMPARE(checker.publicFetchMoreText(), text.mid(position2, position3 - position2));
    QCOMPARE(checker.publicFetchMoreText(), text.mid(position3).trimmed());

    // start a check in the middle of a block
    checker.startRun(&doc, 4, 19);
    block = doc.begin();
    QCOMPARE(checker.publicFetchMoreText(), block.text().mid(4));
    block = block.next();
    QVERIFY(block.isValid());
    QCOMPARE(checker.publicFetchMoreText(), block.text().left(2));
}
开发者ID:KDE,项目名称:calligra-history,代码行数:59,代码来源:TestSpellCheck.cpp

示例2: begin

QTextBlock QTextDocumentProto::begin() const
{
  QTextDocument *item = qscriptvalue_cast<QTextDocument*>(thisObject());
  if (item)
    return item->begin();
  return QTextBlock();
}
开发者ID:,项目名称:,代码行数:7,代码来源:

示例3: testTabsUsed

void tst_QTextFormat::testTabsUsed()
{
    QTextDocument doc;
    QTextCursor cursor(&doc);

    QList<QTextOption::Tab> tabs;
    QTextBlockFormat format;
    QTextOption::Tab tab;
    tab.position = 100;
    tabs.append(tab);
    format.setTabPositions(tabs);
    cursor.mergeBlockFormat(format);
    cursor.insertText("foo\tbar");
    //doc.setPageSize(QSizeF(200, 200));
    doc.documentLayout()->pageCount(); // force layout;

    QTextBlock block = doc.begin();
    QTextLayout *layout = block.layout();
    QVERIFY(layout);
    QCOMPARE(layout->lineCount(), 1);
    QTextLine line = layout->lineAt(0);
    QCOMPARE(line.cursorToX(4), 100.);

    QTextOption option = layout->textOption();
    QCOMPARE(option.tabs().count(), tabs.count());

}
开发者ID:CodeDJ,项目名称:qt5-hidpi,代码行数:27,代码来源:tst_qtextformat.cpp

示例4: findAll

int GenericCodeEditor::findAll( const QRegExp &expr, QTextDocument::FindFlags options )
{
    mSearchSelections.clear();

    if(expr.isEmpty()) {
        this->updateExtraSelections();
        return 0;
    }

    QTextEdit::ExtraSelection selection;
    selection.format = mSearchResultTextFormat;

    QTextDocument *doc = QPlainTextEdit::document();
    QTextBlock block = doc->begin();
    QTextCursor cursor;

    while (block.isValid()) {
        int blockPos = block.position();
        int offset = 0;
        while(findInBlock(doc, block, expr, offset, options, cursor)) {
            offset = cursor.selectionEnd() - blockPos;

            if (cursor.hasSelection()) {
                selection.cursor = cursor;
                mSearchSelections.append(selection);
            } else
                offset += 1;
        }
        block = block.next();
    }

    this->updateExtraSelections();

    return mSearchSelections.count();
}
开发者ID:ARTisERR0R,项目名称:supercollider,代码行数:35,代码来源:editor.cpp

示例5: drawDisplay

void PluginListDelegate::drawDisplay(QPainter* painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
{
    QTextDocument textDocument;
    textDocument.setHtml(text);

    QTextLayout textLayout(textDocument.begin());
    textLayout.setFont(option.font);

    const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0) + 1;
    QRect textRect = rect.adjusted(textMargin, 0, -textMargin, 0); // remove width padding

    textLayout.beginLayout();
    qreal height = 0;
    while (1) {
        QTextLine line = textLayout.createLine();
        if (!line.isValid()) {
            break;
        }

        line.setLineWidth(textRect.width());
        height += 3;
        line.setPosition(QPoint(0, height));
        height += line.height();
    }
    textLayout.endLayout();

    textLayout.draw(painter, QPointF(textRect.left(), textRect.top()));
}
开发者ID:JoseAngelMuyoz,项目名称:QupZilla,代码行数:28,代码来源:pluginlistdelegate.cpp

示例6: focusInEvent

void SchematicName::focusInEvent(QFocusEvent *fe) {
  QGraphicsTextItem::focusInEvent(fe);
  qApp->installEventFilter(this);
  QTextDocument *doc = document();
  QTextCursor cursor(doc->begin());
  cursor.select(QTextCursor::Document);
  setTextCursor(cursor);
}
开发者ID:opentoonz,项目名称:opentoonz,代码行数:8,代码来源:schematicnode.cpp

示例7: setAlignment

 // Set the alignment of all blocks to the given alignment
 void setAlignment(Qt::Alignment align) {
     QTextDocument* textDocument = document();
     for (QTextBlock it = textDocument->begin(); it != textDocument->end(); it = it.next()) {
         QTextCursor cur(it);
         QTextBlockFormat format = cur.blockFormat();
         format.setAlignment(align);
         cur.setBlockFormat(format);
     }
 }
开发者ID:afester,项目名称:CodeSamples,代码行数:10,代码来源:TextItem.cpp

示例8: toStringFromDocument

QString Dialog::toStringFromDocument() {
    QTextDocument *doc = message()->document();
    QString txt;
    for (QTextBlock bl = doc->begin(); bl != doc->end(); bl = bl.next())
        if (bl.isValid()) {
            for (QTextBlock::iterator it = bl.begin(); !it.atEnd(); ++it) {
                QTextFragment fragm = it.fragment();
                if (fragm.isValid() && fragm.charFormat().isImageFormat()) {
                    QString imgName = fragm.charFormat().toImageFormat().name();
                    txt += imgName;
                } else if (fragm.isValid())
                    txt += fragm.text();
            }

            if (bl != doc->begin())
                txt += "\n";
        }
    int i = (int)txt.size() - 1;
    while (i >= 0 && (txt[i] == ' ' || txt[i] == '\n')) --i;
    txt.remove(i + 1, txt.size() - i - 1);
    return txt;
}
开发者ID:pva701,项目名称:codes,代码行数:22,代码来源:dialog.cpp

示例9: setInternalAlignment

void TextItem::setInternalAlignment(Qt::Alignment align) {
	// Store alignment
	alignment = align;

    // Set the alignment of all blocks to the given alignment
    QTextDocument* textDocument = textItem->document();
    for (QTextBlock it = textDocument->begin(); it != textDocument->end(); it = it.next()) {
		QTextCursor cur(it);
		QTextBlockFormat format = cur.blockFormat();
		format.setAlignment(align);
		cur.setBlockFormat(format);
    }
}
开发者ID:afester,项目名称:CodeSamples,代码行数:13,代码来源:TextItem.cpp

示例10: main

int main(int argv, char **args)
{
    QString contentString("One\nTwp\nThree");

    QTextDocument *doc = new QTextDocument(contentString);

//! [0]
    for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next())
        cout << it.text().toStdString() << endl;
//! [0]

    return 0;
}
开发者ID:,项目名称:,代码行数:13,代码来源:

示例11: paintEvent

void LineNumberWidget::paintEvent( QPaintEvent* /*e*/ )
{
int max=0;
int l=0;
QPainter painter( this );
painter.setFont(numfont);
const QFontMetrics fm(numfont);
int yOffset = m_editor->verticalScrollBar()->value();
QTextDocument *doc = m_editor->document();
int i = 1;
QTextBlock p = doc->begin();
QString numtext;
const QBrush oldbrush=painter.brush();
QPen oldpen(QColor("#136872"));
oldpen.setStyle(Qt::SolidLine);
painter.setPen(oldpen);
painter.drawLine(width()-2,0,width()-2,height());
while ( p.isValid() ) 
	{
	QPointF point = p.layout()->position();
	if ( point.y() + 20 - yOffset < 0 ) 
		{
		i++;
		p = p.next();
		continue;
		}		
	if ( (int)(point.y()) - yOffset > height() ) break;
	for (int j = 0; j < 3; ++j)
		{
		if (m_editor->UserBookmark[j]==i) 
 			{
			const QBrush brush(QColor("#1B8EA6"));
			painter.fillRect(2, (int)(point.y()) - yOffset,fm.width("0")+6,fm.lineSpacing(), brush);
			const QPen pen(QColor("#FFFFFF"));
			painter.setPen(pen);
			painter.drawText(4, (int)(point.y()) - yOffset,width()-4,fm.lineSpacing(),Qt::AlignLeft | Qt::AlignTop,QString::number(j+1));
 			}
		}
	painter.setPen(oldpen);
	numtext=QString::number(i);
	painter.drawText(0, (int)(point.y()) - yOffset,width()-4,fm.lineSpacing(),Qt::AlignRight | Qt::AlignTop,numtext);
	l= fm.width(numtext)+18+fm.width("0");
	if (l>max) max=l;
	i++;
	p = p.next();
	}
	if (i>=10000) setFixedWidth(max);	
painter.end();
}
开发者ID:svn2github,项目名称:texstudio,代码行数:49,代码来源:linenumberwidget.cpp

示例12: saveOdf

void KPrPlaceholderTextStrategy::saveOdf( KoShapeSavingContext & context )
{
    if (m_textShape) {
        KoTextShapeData *shapeData = qobject_cast<KoTextShapeData*>(m_textShape->userData());
        if (shapeData) {
            KoStyleManager *styleManager = KoTextDocument(shapeData->document()).styleManager();
            if (styleManager) {
                QTextDocument *document = shapeData->document();
                QTextBlock block = document->begin();
                QString styleName = KoTextWriter::saveParagraphStyle(block, styleManager, context);
                context.xmlWriter().addAttribute("draw:text-style-name", styleName);
            }
        }
    }
    KPrPlaceholderStrategy::saveOdf( context );
}
开发者ID:KDE,项目名称:calligra,代码行数:16,代码来源:KPrPlaceholderTextStrategy.cpp

示例13: updateExistsTextColor

void TextOutput::updateExistsTextColor()
{
    if (!m_existsTimer.hasExpired(1000)) return;

    QTextDocument* doc = document();
    for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next())
    {
        QTextCursor cur(it);
        cur.select(QTextCursor::BlockUnderCursor);

        QTextCharFormat f(cur.charFormat());
        QColor color(f.foreground().color());
        color.setAlpha(128);
        f.setForeground(color);
        cur.setCharFormat(f);
    }
}
开发者ID:JoeyFan,项目名称:liteide,代码行数:17,代码来源:textoutput.cpp

示例14: getInput

bool CVProjectDialog::getInput(Core::CVProject& proj) {
    proj.name = _name->text();
	proj.path = _path->text() + QDir::separator() + proj.name;
    proj.type = _type->currentIndex() == 0 ? Core::CVProject::PHOTOGRAMMETRY : Core::CVProject::LIDAR;
	proj.refPath = _conf->text();
	if (proj.type == Core::CVProject::PHOTOGRAMMETRY) {
		proj.scale = _scale->currentText();
	}

	proj.datum = _epsg->currentText().toInt();

	QTextDocument* doc = _note->document();
	QStringList l;
	for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next()) {
         l << it.text();
	}
	proj.notes = l.join("\n");
	return !proj.name.isEmpty() && !proj.path.isEmpty() && !proj.refPath.isEmpty();
}
开发者ID:geoin,项目名称:ControlloVoliRT,代码行数:19,代码来源:cvprojectdialog.cpp

示例15: cursorToHtml

QString LiteEditorWidget::cursorToHtml(QTextCursor cursor) const
{
    QTextDocument *tempDocument = new QTextDocument;
    QTextCursor tempCursor(tempDocument);
    tempCursor.insertFragment(cursor.selection());

    // Apply the additional formats set by the syntax highlighter
    QTextBlock start = document()->findBlock(cursor.selectionStart());
    QTextBlock end = document()->findBlock(cursor.selectionEnd());
    end = end.next();

    const int selectionStart = cursor.selectionStart();
    const int endOfDocument = tempDocument->characterCount() - 1;
    for (QTextBlock current = start; current.isValid() && current != end; current = current.next()) {
        const QTextLayout *layout = current.layout();
        foreach (const QTextLayout::FormatRange &range, layout->additionalFormats()) {
            const int start = current.position() + range.start - selectionStart;
            const int end = start + range.length;
            if (end <= 0 || start >= endOfDocument)
                continue;
            tempCursor.setPosition(qMax(start, 0));
            tempCursor.setPosition(qMin(end, endOfDocument), QTextCursor::KeepAnchor);
            tempCursor.setCharFormat(range.format);
        }
    }

    // Reset the user states since they are not interesting
    for (QTextBlock block = tempDocument->begin(); block.isValid(); block = block.next())
        block.setUserState(-1);

    // Make sure the text appears pre-formatted
    tempCursor.setPosition(0);
    tempCursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
    QTextBlockFormat blockFormat = tempCursor.blockFormat();
    blockFormat.setNonBreakableLines(true);
    tempCursor.setBlockFormat(blockFormat);
    QString html = tempCursor.selection().toHtml();//("utf-8");
    html.replace("\t","&nbsp&nbsp&nbsp&nbsp");
    delete tempDocument;
    return html;
}
开发者ID:priest671,项目名称:liteide,代码行数:41,代码来源:liteeditorwidget.cpp


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