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


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

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


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

示例1: find

void FindAndReplace::find( bool next )
{
    QLineEdit * find = ui->findEdit;
    const QString & text = find->text();

    if ( text.isEmpty() )
        return;

    bool backward = !next;
    Shared::FindFlags findFlags = ui->findEdit->findOptions();
    bool caseSensitive = findFlags.testFlag( Shared::CaseSensitive );
    bool wholeWords = findFlags.testFlag( Shared::WholeWords );
    bool regExp = findFlags.testFlag( Shared::RegExp );

    QTextDocument::FindFlags flags;
    if ( backward )
        flags |= QTextDocument::FindBackward;

    if ( caseSensitive )
        flags |= QTextDocument::FindCaseSensitively;

    if ( wholeWords )
        flags |= QTextDocument::FindWholeWords;

    QTextDocument * document = d_editor->document();
    QTextCursor textCursor = d_editor->textCursor();
    do
    {
        if ( regExp )
            textCursor = document->find( QRegExp( text ), textCursor, flags );
        else
            textCursor = document->find( text, textCursor, flags );

        if ( textCursor.isNull() )
        {
            d_editor->moveCursor( next ? QTextCursor::Start : QTextCursor::End, QTextCursor::MoveAnchor );

            if ( regExp )
                textCursor = document->find( QRegExp( text ), textCursor, flags );
            else
                textCursor = document->find( text, textCursor, flags );
        }

        if ( textCursor.hasSelection() )
        {
            d_editor->setTextCursor( textCursor );
            break;
        }

    } while ( !textCursor.isNull() );

    d_editor->ensureCursorVisible();
    d_editor->setFocus();
}
开发者ID:adjustive,项目名称:NotesManager,代码行数:54,代码来源:findandreplace.cpp

示例2: findText

bool TextBrowserHelpViewer::findText(const QString &text, Core::FindFlags flags,
    bool incremental, bool fromSearch, bool *wrapped)
{
    if (wrapped)
        *wrapped = false;
    QTextDocument *doc = m_textBrowser->document();
    QTextCursor cursor = m_textBrowser->textCursor();
    if (!doc || cursor.isNull())
        return false;

    const int position = cursor.selectionStart();
    if (incremental)
        cursor.setPosition(position);

    QTextDocument::FindFlags f = Core::textDocumentFlagsForFindFlags(flags);
    QTextCursor found = doc->find(text, cursor, f);
    if (found.isNull()) {
        if ((flags & Core::FindBackward) == 0)
            cursor.movePosition(QTextCursor::Start);
        else
            cursor.movePosition(QTextCursor::End);
        found = doc->find(text, cursor, f);
        if (!found.isNull() && wrapped)
            *wrapped = true;
    }

    if (fromSearch) {
        cursor.beginEditBlock();
        m_textBrowser->viewport()->setUpdatesEnabled(false);

        QTextCharFormat marker;
        marker.setForeground(Qt::red);
        cursor.movePosition(QTextCursor::Start);
        m_textBrowser->setTextCursor(cursor);

        while (m_textBrowser->find(text)) {
            QTextCursor hit = m_textBrowser->textCursor();
            hit.mergeCharFormat(marker);
        }

        m_textBrowser->viewport()->setUpdatesEnabled(true);
        cursor.endEditBlock();
    }

    bool cursorIsNull = found.isNull();
    if (cursorIsNull) {
        found = m_textBrowser->textCursor();
        found.setPosition(position);
    }
    m_textBrowser->setTextCursor(found);
    return !cursorIsNull;
}
开发者ID:alexey-zayats,项目名称:athletic,代码行数:52,代码来源:textbrowserhelpviewer.cpp

示例3: finish

	void finish()
	{
		for (int i = 0; i < codeSections.size(); ++i)
		{
			QTextCharFormat fmt;
			fmt.setFontFamily("Monospace");
			doc->find(QString("$${{%1}}$$").arg(i)).insertText(codeSections.at(i), fmt);
		}
		for (int i = 0; i < htmlSections.size(); ++i)
		{
			doc->find(QString("$$[[%1]]$$").arg(i)).insertHtml(htmlSections.at(i));
		}
	}
开发者ID:02JanDal,项目名称:QMarkdown,代码行数:13,代码来源:QMarkdown.cpp

示例4: find

/*!
    \reimp
 */
void TextEditFindWidget::find(const QString &ttf, bool skipCurrent, bool backward, bool *found, bool *wrapped)
{
    if (!m_textEdit)
        return;

    QTextCursor cursor = m_textEdit->textCursor();
    QTextDocument *doc = m_textEdit->document();

    if (!doc || cursor.isNull())
        return;

    if (cursor.hasSelection())
        cursor.setPosition((skipCurrent && !backward) ? cursor.position() : cursor.anchor());

    *found = true;
    QTextCursor newCursor = cursor;

    if (!ttf.isEmpty()) {
        QTextDocument::FindFlags options;

        if (backward)
            options |= QTextDocument::FindBackward;

        if (caseSensitive())
            options |= QTextDocument::FindCaseSensitively;

        if (wholeWords())
            options |= QTextDocument::FindWholeWords;

        newCursor = doc->find(ttf, cursor, options);
        if (newCursor.isNull()) {
            QTextCursor ac(doc);
            ac.movePosition(options & QTextDocument::FindBackward
                    ? QTextCursor::End : QTextCursor::Start);
            newCursor = doc->find(ttf, ac, options);
            if (newCursor.isNull()) {
                *found = false;
                newCursor = cursor;
            } else {
                *wrapped = true;
            }
        }
    }

    if (!isVisible())
        show();

    m_textEdit->setTextCursor(newCursor);
}
开发者ID:wpbest,项目名称:copperspice,代码行数:52,代码来源:texteditfindwidget.cpp

示例5: findExpretion

/*!
 *  Find a string within document.
 *
 *  \param  findString  string to be found.
 *  \param  options     find options.
 */
void TextEdit::findExpretion(const QString &findString, QTextDocument::FindFlags options)
{
    /*! \todo fix the performance! */
    //highlight(findString, options);

    QTextDocument *document = this->document();
    QTextCursor findCursor(document);
    QTextCursor cursor(document);

    int pos = this->textCursor().position();
    if (textCursor().hasSelection() && options == QTextDocument::FindBackward){
        findCursor.setPosition(pos, QTextCursor::MoveAnchor);
        findCursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
    } else {
        findCursor.setPosition(pos, QTextCursor::MoveAnchor);
    }
    if (textCursor().hasSelection() && options == QTextDocument::FindBackward){
        cursor.setPosition(pos, QTextCursor::MoveAnchor);
        cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
    } else {
        cursor.setPosition(pos, QTextCursor::MoveAnchor);
    }

    if ((m_lastFindString.contains(findString) || findString.contains(m_lastFindString)) &&
        options != QTextDocument::FindBackward && textCursor().hasSelection() &&
        findString != m_lastFindString){
        findCursor.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
    }

    //if (!(this->textCursor().hasSelection()) && (!findString.isEmpty() || !findString.isNull()))
    findCursor = document->find(findString, findCursor, options);

    if (findCursor.isNull()) {
        if (options == QTextDocument::FindBackward){
            findCursor = cursor;
            findCursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
        }
        findCursor = document->find(findString, findCursor, options);
    }

    if (findCursor.isNull()) {
        this->setTextCursor(cursor);
    } else {
        this->setTextCursor(findCursor);
        //m_isFirstTime = false;
    }
    m_lastFindString = findString;
}
开发者ID:thesoulless,项目名称:SoulNote,代码行数:54,代码来源:textedit.cpp

示例6: textEditToPlainText

QString ChatEdit::textEditToPlainText()
{
	QTextDocument *doc = document();
	QString result;
	result.reserve(doc->characterCount());
	QTextCursor begin(doc);
	QTextCursor end;
	QString specialChar = QChar(QChar::ObjectReplacementCharacter);
	bool first = true;
	while (!begin.atEnd()) {
		end = doc->find(specialChar, begin, QTextDocument::FindCaseSensitively);
		QString postValue;
		bool atEnd = end.isNull();
		if (atEnd) {
			end = QTextCursor(doc);
			QTextBlock block = doc->lastBlock();
			end.setPosition(block.position() + block.length() - 1);
		} else {
			postValue = end.charFormat().toolTip();
		}
		begin.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,
						   end.position() - begin.position() - (atEnd ? 0 : 1));
		QString selectionText = begin.selection().toPlainText();
		if (!first)
			result += selectionText.midRef(1);
		else
			result += selectionText;
		result += postValue;
		begin = end;
		end.clearSelection();
		first = false;
	}
	return result;
}
开发者ID:akahan,项目名称:qutim,代码行数:34,代码来源:chatedit.cpp

示例7: find

QTextCursor QTextDocumentProto::find(const QRegExp &expr, int position, int options) const
{
  QTextDocument *item = qscriptvalue_cast<QTextDocument*>(thisObject());
  if (item)
    return item->find(expr, position, (QTextDocument::FindFlags)options);
  return QTextCursor();
}
开发者ID:,项目名称:,代码行数:7,代码来源:

示例8: on_calendarWidget_activated

void Journal::on_calendarWidget_activated(const QDate &date)
{
    ui->textEdit->setText(notes);
    QString searchString;
    searchString=date.toString();
    QTextDocument *document = ui->textEdit->document();

    bool found=false;
    QTextCursor highlightCursor(document);
    QTextCursor cursor(document);

    cursor.beginEditBlock();

    QTextCharFormat plainFormat(highlightCursor.charFormat());
    QTextCharFormat colorFormat = plainFormat;
    colorFormat.setForeground(Qt::red);

    while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {
        highlightCursor = document->find(searchString, highlightCursor, QTextDocument::FindWholeWords);

        if (!highlightCursor.isNull()) {
            found = true;
            highlightCursor.movePosition(QTextCursor::WordRight,
                                         QTextCursor::KeepAnchor);
            highlightCursor.mergeCharFormat(colorFormat);
        }
    }

    cursor.endEditBlock();


}
开发者ID:BSUIR350531,项目名称:piskarev,代码行数:32,代码来源:journal.cpp

示例9: testBasic

void TestFindMatch::testBasic()
{
    KoFindMatch match;

    QTextDocument *doc = new QTextDocument("Test Document", this);
    QVariant docVariant = QVariant::fromValue(doc);
    QVERIFY(docVariant.isValid());
    
    match.setContainer(docVariant);
    QCOMPARE(match.container(), docVariant);
    QCOMPARE(match.container().value<QTextDocument*>(), doc);

    QTextCursor cursor = doc->find("Document");
    QVariant curVariant = QVariant::fromValue(cursor);
    QVERIFY(curVariant.isValid());
    
    match.setLocation(curVariant);
    QCOMPARE(match.location(), curVariant);
    QCOMPARE(match.location().value<QTextCursor>(), cursor);

    QVERIFY(match.isValid());

    KoFindMatch other(docVariant, curVariant);
    QVERIFY(other.isValid());
    QCOMPARE(other.container(), docVariant);
    QCOMPARE(other.location(), curVariant);
}
开发者ID:KDE,项目名称:calligra,代码行数:27,代码来源:testfindmatch.cpp

示例10: getTextDocument

void	QsvTextOperationsWidget::on_replaceOldText_returnPressed()
{
	if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) ||
	    QApplication::keyboardModifiers().testFlag(Qt::AltModifier) ||
	    QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) ) {
		on_replaceAll_clicked();
		showReplace();
		return;
	}

	QTextCursor c = m_searchCursor;
	QTextDocument *doc = getTextDocument();
	if (!doc){
		qDebug("%s:%d - no document found, using a wrong class? wrong parent?", __FILE__,__LINE__);
		return;
	}
	c = doc->find( replaceFormUi->findText->text(), c, getReplaceFlags() );
	if (c.isNull())
		return;

	int start = c.selectionStart();
	int end   = c.selectionEnd();
	c.beginEditBlock();
	c.deleteChar();
	c.insertText( replaceFormUi->replaceText->text() );
	c.setPosition(start,QTextCursor::KeepAnchor);
	c.setPosition(end  ,QTextCursor::MoveAnchor);
	c.endEditBlock();
	setTextCursor( c );

	// is there any other apperance of this text?
	m_searchCursor = c;
	updateReplaceInput();
}
开发者ID:martinribelotta,项目名称:embedded-ide,代码行数:34,代码来源:qsvtextoperationswidget.cpp

示例11: testCopyAssign

void TestFindMatch::testCopyAssign()
{
    KoFindMatch match;

    QTextDocument *doc = new QTextDocument("Test Document", this);
    QVariant docVariant = QVariant::fromValue(doc);
    QTextCursor cursor = doc->find("Document");
    QVariant curVariant = QVariant::fromValue(cursor);

    QVERIFY(docVariant.isValid());
    QVERIFY(curVariant.isValid());
    
    match.setContainer(docVariant);
    match.setLocation(curVariant);

    KoFindMatch other(match);
    QVERIFY(other.isValid());
    QCOMPARE(other.container(), match.container());
    QCOMPARE(other.location(), match.location());

    KoFindMatch third = match;
    QVERIFY(third.isValid());
    QCOMPARE(third.container(), match.container());
    QCOMPARE(third.location(), match.location());

    QVERIFY(other == match);
}
开发者ID:KDE,项目名称:calligra,代码行数:27,代码来源:testfindmatch.cpp

示例12: QTextCursor

void PlainTextViewWidget::searchDocument(const QString &text, Qt::CaseSensitivity caseSensitive)
{
   m_currentSearchResult = QTextCursor();
   m_searchResults.clear();

   QTextDocument::FindFlags findFlags;
   if (caseSensitive == Qt::CaseSensitive) {
      findFlags |= QTextDocument::FindCaseSensitively;
   }

   QPlainTextEdit *textEdit = ui->plainTextEdit;
   QTextDocument *textDocument = textEdit->document();
   QTextCursor currentCursor = textEdit->textCursor();
   currentCursor.clearSelection(); // To get QTextDocument::find to work properly

   // Find all results forwards beginning from current cursor
   QTextCursor findCursor = textDocument->find(text, currentCursor, findFlags);
   if (!findCursor.isNull()) {
      // Set to first result after current cursor pos
      m_currentSearchResult = findCursor;
   }

   while (!findCursor.isNull()) {
      m_searchResults.append(findCursor);
      findCursor = textDocument->find(text, findCursor, findFlags);
   }

   // Find all results backwards beginning from current cursor
   findFlags |= QTextDocument::FindBackward;
   findCursor = textDocument->find(text, currentCursor, findFlags);
   while (!findCursor.isNull()) {
      m_searchResults.prepend(findCursor);
      findCursor = textDocument->find(text, findCursor, findFlags);
   }

   if (m_searchResults.isEmpty()) {
      ui->searchBar->setResultNumberAndCount(0, 0);
      return;
   }

   if (m_currentSearchResult.isNull()) {
      // Set to first result because after current cursor pos wasn't a search match
      m_currentSearchResult = m_searchResults.at(0);
   }

   jumpToHighlightResult(m_currentSearchResult);
}
开发者ID:tomvodi,项目名称:QTail,代码行数:47,代码来源:PlainTextViewWidget.cpp

示例13: findText

void CodeEditor::findText(QString text, int dir){
    QTextCursor cursor = textCursor();
    if(dir==0 || dir==-1){
        cursor.movePosition(cursor.PreviousWord);
    }
    QTextDocument* d = document();
    QTextCursor p;
    if(dir==-1){
        p = d->find(text,cursor,d->FindBackward);
    }
    else{
        p = d->find(text,cursor);
    }
    qDebug() << text << "Found...";
    qDebug() << p.blockNumber();
    if(!p.isNull()){
        setTextCursor(p);
    }
}
开发者ID:nikhilgv9,项目名称:specRTLViz,代码行数:19,代码来源:codeeditor.cpp

示例14: replaceIdToName

void QQTextEdit::replaceIdToName(QString id, QString name)
{
    QTextDocument *doc = this->document();
    QTextCursor cursor = doc->find(id, QTextCursor());

    if (cursor.isNull())
        return;

    cursor.insertText(name);
}
开发者ID:GHfangxin,项目名称:Qtqq,代码行数:10,代码来源:qqtextedit.cpp

示例15: findAllOccurrance

bool BaseEditor::findAllOccurrance(const QString &text, QTextDocument::FindFlags qff, bool isRE)
{
    QTextDocument *doc = document();

    findTextSelection.clear();
    bool finded=false;

    if(text.isEmpty())
    {
        prevFindCursor = QTextCursor();
        return finded;
    } else {
        QTextEdit::ExtraSelection es;
        QTextCursor highlightCursor(doc);

        QTextCharFormat plainFormat(highlightCursor.charFormat());
        QTextCharFormat colorFormat = plainFormat;
        colorFormat.setBackground(Qt::yellow);

        es.format = colorFormat;
        QRegExp re(text);

        while(!highlightCursor.isNull() && !highlightCursor.atEnd())
        {
            highlightCursor = isRE ? doc->find(re, highlightCursor, qff) :
                                     doc->find(text, highlightCursor, qff);

            if(!highlightCursor.isNull())
            {
                finded = true;
                es.cursor = highlightCursor;
                findTextSelection.append(es);
            }
        }
        if(!finded)
        {
            prevFindCursor = highlightCursor;
        }
        return finded;
    }
}
开发者ID:3rdpaw,项目名称:MdCharm,代码行数:41,代码来源:baseeditor.cpp


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