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


C++ QTextCursor::removeSelectedText方法代码示例

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


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

示例1: editUncomment

void TikzEditorView::editUncomment()
{
	bool go = true;
	QTextCursor textCursor = m_tikzEditor->textCursor();
	if (textCursor.hasSelection())
	{
		textCursor.beginEditBlock();
		const int start = textCursor.selectionStart();
		int end = textCursor.selectionEnd() - 2;
		textCursor.setPosition(start, QTextCursor::MoveAnchor);
		textCursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
		while (textCursor.position() < end && go)
		{
			textCursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
			if (textCursor.selectedText() == QLatin1String("% "))
			{
				textCursor.removeSelectedText();
				--end;
			}
			go = textCursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor);
		}
		textCursor.endEditBlock();
	}
	else
	{
		textCursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
		textCursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
		if (textCursor.selectedText() == QLatin1String("% "))
			textCursor.removeSelectedText();
	}
}
开发者ID:jfmcarreira,项目名称:ktikz-old,代码行数:31,代码来源:tikzeditorview.cpp

示例2: preventDoubleSpace

void TextZone::preventDoubleSpace()
{

    QTextCursor *tCursor = new QTextCursor(document());
    int cursorPos = this->textCursor().position();
    QString prevChar;
    QString nextChar;

    if(this->textCursor().atBlockStart() == false){
        do {tCursor->setPosition(cursorPos);
            tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1);
            prevChar = tCursor->selectedText();
            if(prevChar == " "){
                tCursor->removeSelectedText();
                cursorPos -= 1;
            }
        }
        while(prevChar == " ");

    }
    if(this->textCursor().atBlockEnd() == false){
        do {tCursor->setPosition(cursorPos);
            tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1);
            nextChar = tCursor->selectedText();
            if(nextChar == " "){
                tCursor->removeSelectedText();
            }
        }
        while(nextChar == " ");

    }

    this->textCursor().insertText(" ");
}
开发者ID:jwvdveen,项目名称:plume-creator-legacy,代码行数:34,代码来源:textzone.cpp

示例3: printMessage

void GLFOutputWindow::printMessage(const char* message)
{
    static int index = 1;
    // Remove the first few lines when the buffer is overflow.
    int nlines = _pTextEdit->document()->lineCount();
    if (nlines > MAX_NUM_LINES)
    {
        int deleteNumLines = nlines / 2;
        for (int i = 0; i < deleteNumLines; ++i)
        {
            QTextCursor tc = _pTextEdit->textCursor();

            tc.movePosition(QTextCursor::Start);
            tc.select(QTextCursor::LineUnderCursor);
            tc.removeSelectedText();
        }

        QTextCursor tc = _pTextEdit->textCursor();
        tc.movePosition(QTextCursor::End);
        _pTextEdit->setTextCursor(tc);            
    }

    // Insert the new message
    char buffer[1024];
    sprintf(buffer, "%d: %s", index++, message);
    _pTextEdit->insertPlainText(QString(buffer));

    // Scroll to the bottom
    QScrollBar *sb = _pTextEdit->verticalScrollBar();
    sb->setValue(sb->maximum());
}
开发者ID:lihw,项目名称:glf,代码行数:31,代码来源:glf_output_window.cpp

示例4: handleHistory

void ConsoleWidget::handleHistory(bool down)
{
    int index;
    moveCursor(QTextCursor::End);
    QTextCursor cursor = textCursor();

    if (m_history.size()==0)
        return;

    if (down)
        m_histIndex--;
    else
        m_histIndex++;

    if (m_histIndex>m_history.size()-1)
        m_histIndex = m_history.size()-1;
    if (m_histIndex<0)
        m_histIndex = 0;
    index = m_history.size()-1-m_histIndex;

    cursor.select(QTextCursor::LineUnderCursor);
    cursor.removeSelectedText();

    handleColor();
    insertPlainText(m_prompt + m_history[index]);
    moveCursor(QTextCursor::End);
}
开发者ID:Taitanguo,项目名称:RobotFunctionDevelop,代码行数:27,代码来源:console.cpp

示例5: eventFilter

bool ChatWindow::eventFilter(QObject* sender, QEvent* event) {
    if (sender == ui->messagePlainTextEdit) {
        if (event->type() != QEvent::KeyPress) {
            return false;
        }
        QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
        if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) &&
            (keyEvent->modifiers() & Qt::ShiftModifier) == 0) {
            QString messageText = ui->messagePlainTextEdit->document()->toPlainText().trimmed();
            if (!messageText.isEmpty()) {
#ifdef HAVE_QXMPP
                const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
                QXmppMessage message;
                message.setTo(publicChatRoom->jid());
                message.setType(QXmppMessage::GroupChat);
                message.setBody(messageText);
                XmppClient::getInstance().getXMPPClient().sendPacket(message);
#endif // HAVE_QXMPP
                QTextCursor cursor = ui->messagePlainTextEdit->textCursor();
                cursor.select(QTextCursor::Document);
                cursor.removeSelectedText();
            }
            return true;
        }
    } else if (event->type() == QEvent::MouseButtonRelease) {
        QVariant userVar = sender->property("user");
        if (userVar.isValid()) {
            AddressManager::getInstance().goToUser(userVar.toString());
            return true;
        }
    }
    return QWidget::eventFilter(sender, event);
}
开发者ID:CoderPaulK,项目名称:hifi,代码行数:33,代码来源:ChatWindow.cpp

示例6: handleKeyBackspace

void GenericCodeEditor::handleKeyBackspace(QKeyEvent * event, QTextCursor & textCursor, bool & updateCursor)
{
    if (event->modifiers() & Qt::META) {
        textCursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
        textCursor.removeSelectedText();
    } else {
        if ( !overwriteMode()
             || (textCursor.positionInBlock() == 0)
             || textCursor.hasSelection() ) {
            QPlainTextEdit::keyPressEvent(event);
        } else {
            // in overwrite mode, backspace should insert a space
            textCursor.beginEditBlock();
            textCursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
            QString selectedText = textCursor.selectedText();
            if (selectedText == QStringLiteral(" ") ||
                selectedText == QStringLiteral("\t") ) {
                textCursor.clearSelection();
            } else {
                textCursor.insertText(QString(QChar(' ')));
                textCursor.movePosition(QTextCursor::PreviousCharacter);
            }
            textCursor.endEditBlock();
        }
        updateCursor = true;
    }
}
开发者ID:ARTisERR0R,项目名称:supercollider,代码行数:27,代码来源:editor.cpp

示例7: increaseSelectedTextIndention

/**
 * @brief Increases (or decreases) the indention of the selected text (if there is a text selected) in the noteTextEdit
 * @return
 */
bool QMarkdownTextEdit::increaseSelectedTextIndention( bool reverse )
{
    QTextCursor c = this->textCursor();
    QString selectedText = c.selectedText();

    if ( selectedText != "" )
    {
        // we need this strange newline character we are getting in the selected text for newlines
        QString newLine = QString::fromUtf8( QByteArray::fromHex( "e280a9" ) );
        QString newText;

        if ( reverse )
        {
            // unindent text
            newText = selectedText.replace( newLine + "\t", "\n" );

            // remove leading \t
            newText.replace( QRegularExpression( "^\\t" ), "" );
        }
        else
        {
            // indent text
            newText = selectedText.replace( newLine, "\n\t" ).prepend( "\t" );

            // remove trailing \t
            newText.replace( QRegularExpression( "\\t$" ), "" );
        }

        // insert the new text
        c.insertText( newText );

        // update the selection to the new text
        c.setPosition( c.position() - newText.size(), QTextCursor::KeepAnchor );
        this->setTextCursor( c );

        return true;
    }
    // if nothing was selected but we want to reverse the indention check if there is a \t in front or after the cursor and remove it if so
    else if ( reverse )
    {
        int pos = c.position();
        // check for \t in front of cursor
        c.setPosition( pos - 1, QTextCursor::KeepAnchor );
        if ( c.selectedText() != "\t" )
        {
            // (select to) check for \t after the cursor
            c.setPosition( pos );
            c.setPosition( pos + 1, QTextCursor::KeepAnchor );
        }

        if ( c.selectedText() == "\t" )
        {
            c.removeSelectedText();
        }

        return true;
    }

    return false;
}
开发者ID:brillywu,项目名称:qmarkdowntextedit,代码行数:64,代码来源:qmarkdowntextedit.cpp

示例8: completeTagText

void CodeEditor::completeTagText(const QString &text)
{
    textCursor().beginEditBlock();
    QString adding_text;
    QTextCursor editingTextCursor = textCursor();

    editingTextCursor.setPosition(textCursor().selectionStart());
    editingTextCursor.movePosition( QTextCursor::EndOfWord, QTextCursor::MoveAnchor );
    editingTextCursor.movePosition( QTextCursor::StartOfWord, QTextCursor::KeepAnchor );
    editingTextCursor.removeSelectedText();
    adding_text = text;

    adding_text += ">";
    adding_text += "</";
    adding_text += text;
    adding_text += ">";

    editingTextCursor.insertText(adding_text);
    editingTextCursor.movePosition( QTextCursor::PreviousWord, QTextCursor::MoveAnchor );
    editingTextCursor.movePosition( QTextCursor::PreviousWord, QTextCursor::MoveAnchor );
    editingTextCursor.movePosition( QTextCursor::PreviousWord, QTextCursor::MoveAnchor );
    editingTextCursor.movePosition( QTextCursor::Right, QTextCursor::MoveAnchor );
    setTextCursor(editingTextCursor);

    textCursor().endEditBlock();
}
开发者ID:Shando,项目名称:Rockete,代码行数:26,代码来源:CodeEditor.cpp

示例9: deleteTab

void CodeEditor::deleteTab()
{
    QString deletion = "    ";

    QTextCursor cursor = textCursor();
    if (cursor.selectionEnd() - cursor.selectionStart() <= 0) {
        //delete 4 spaces (tab)
        cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, deletion.length());
        QString selected = cursor.selectedText();
        if (selected.startsWith(deletion))
            cursor.deletePreviousChar();
    } else {
        QTextBlock firstBlock = document()->findBlock(cursor.selectionStart());
        QTextBlock lastBlock = document()->findBlock(cursor.selectionEnd() - 1);

        cursor.setPosition(firstBlock.position());
        cursor.beginEditBlock();
        do {
            if (cursor.block().text().startsWith(deletion)) {
                cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, deletion.length());
                cursor.removeSelectedText();
            }
        } while (cursor.movePosition(QTextCursor::NextBlock) && cursor.position() <= lastBlock.position());
        cursor.endEditBlock();
    }
}
开发者ID:Megaxela,项目名称:SASM,代码行数:26,代码来源:codeeditor.cpp

示例10: removeMark

void LrcEditor::removeMark()
{
	QTextCursor cursor = textCursor();
	QString strText = cursor.block().text();

	if (strText.isEmpty())
		return ;

	const QRegExp exp("^\\[\\d+:\\d+\\.\\d+\\]");

	int index = exp.indexIn(strText);
	// no time tags
	if (index == -1)
		return ;

	strText.remove(index, exp.matchedLength());

	cursor.beginEditBlock();

	cursor.select(QTextCursor::LineUnderCursor);
	cursor.removeSelectedText();
	cursor.insertText(strText);

	cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);

	cursor.endEditBlock();

	setTextCursor(cursor);
}
开发者ID:timxx,项目名称:lyricsx,代码行数:29,代码来源:lrceditor.cpp

示例11: setKey

template<> bool
QConsoleWidget::_pf<bool, SelectKeyPressedAll>(
        QConsoleWidget * thisp,
        QKeyEvent * e) {

    auto resetSelect = [](QConsoleWidget * _thisp)->void{
        QTextCursor textCursor = _thisp->textCursor();
        auto epos = textCursor.selectionEnd();
        textCursor.setPosition( _thisp->promptEndPos_);
        textCursor.setPosition( epos, QTextCursor::KeepAnchor);
        _thisp->setTextCursor(textCursor);
    };

    auto key_ = e->key();

    switch (key_)
    {
    case Qt::Key_Shift:
    case Qt::Key_Control:
    case Qt::Key_Meta:
    case Qt::Key_Alt:
    case Qt::Key_CapsLock:
    case Qt::Key_NumLock:
    case Qt::Key_ScrollLock:
    case Qt::Key_Up:
    case Qt::Key_Down:
    case Qt::Key_Left:
    case Qt::Key_Right:
    case Qt::Key_PageDown:
    case Qt::Key_PageUp:
    case Qt::Key_Home:
    case Qt::Key_End:return false;
    }

    if (e->modifiers() & Qt::ControlModifier) {
        switch (key_)
        {
        case Qt::Key_C:
        case Qt::Key_A:return false;
        case Qt::Key_X:/*剪贴*/ {
            class EventKey :public QKeyEvent {
            public:
                void setKey() { k = Qt::Key_C; }
            };
            EventKey * fk = (EventKey*)(e);
            fk->setKey();
            thisp->TP::keyPressEvent(fk);
            resetSelect(thisp);
            QTextCursor textCursor = thisp->textCursor();
            textCursor.removeSelectedText();
            thisp->setTextCursor(textCursor);
            return true;
        }
        }
    }

    resetSelect(thisp);

    return false;
}
开发者ID:ngzHappy,项目名称:QtLuaConsole,代码行数:60,代码来源:QConsoleWidget.cpp

示例12: insertCssProperty

void StyleSheetEditorDialog::insertCssProperty(const QString &name, const QString &value)
{
    if (!value.isEmpty()) {
        QTextCursor cursor = m_editor->textCursor();
        if (!name.isEmpty()) {
            cursor.beginEditBlock();
            cursor.removeSelectedText();
            cursor.movePosition(QTextCursor::EndOfLine);

            // Simple check to see if we're in a selector scope
            const QTextDocument *doc = m_editor->document();
            const QTextCursor closing = doc->find(QLatin1String("}"), cursor, QTextDocument::FindBackward);
            const QTextCursor opening = doc->find(QLatin1String("{"), cursor, QTextDocument::FindBackward);
            const bool inSelector = !opening.isNull() && (closing.isNull() ||
                                                          closing.position() < opening.position());
            QString insertion;
            if (m_editor->textCursor().block().length() != 1)
                insertion += QLatin1Char('\n');
            if (inSelector)
                insertion += QLatin1Char('\t');
            insertion += name;
            insertion += QLatin1String(": ");
            insertion += value;
            insertion += QLatin1Char(';');
            cursor.insertText(insertion);
            cursor.endEditBlock();
        } else {
            cursor.insertText(value);
        }
    }
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:31,代码来源:stylesheeteditor.cpp

示例13: handleCompleteDrugName

void DrugInputEdit::handleCompleteDrugName(QString addName) {
    QTextCursor tc = textCursor();
    tc.select(QTextCursor::LineUnderCursor);
    tc.removeSelectedText();
    tc.insertText(addName + "\n");
    setTextCursor(tc);
}
开发者ID:DesiOtaku,项目名称:QDrugList,代码行数:7,代码来源:druginputedit.cpp

示例14: replaceWordsInCurrentEditor

void SpellCheckerCore::replaceWordsInCurrentEditor(const WordList &wordsToReplace, const QString &replacementWord)
{
    if(wordsToReplace.count() == 0) {
        Q_ASSERT(wordsToReplace.count() != 0);
        return;
    }
    if(d->currentEditor == NULL) {
        Q_ASSERT(d->currentEditor != NULL);
        return;
    }
    TextEditor::TextEditorWidget* editorWidget = qobject_cast<TextEditor::TextEditorWidget*>(d->currentEditor->widget());
    if(editorWidget == NULL) {
        Q_ASSERT(editorWidget != NULL);
        return;
    }

    QTextCursor cursor = editorWidget->textCursor();
    /* Iterate the words and replace all one by one */
    foreach(const Word& wordToReplace, wordsToReplace) {
        editorWidget->gotoLine(wordToReplace.lineNumber, wordToReplace.columnNumber - 1);
        int wordStartPos = editorWidget->textCursor().position();
        editorWidget->gotoLine(wordToReplace.lineNumber, wordToReplace.columnNumber + wordToReplace.length - 1);
        int wordEndPos = editorWidget->textCursor().position();

        cursor.beginEditBlock();
        cursor.setPosition(wordStartPos);
        cursor.setPosition(wordEndPos, QTextCursor::KeepAnchor);
        cursor.removeSelectedText();
        cursor.insertText(replacementWord);
        cursor.endEditBlock();
    }
开发者ID:Typz,项目名称:SpellChecker-Plugin,代码行数:31,代码来源:spellcheckercore.cpp

示例15: tabComplete

void QtChatWindow::tabComplete() {
	if (!completer_) {
		return;
	}

	QTextCursor cursor;
	if (tabCompleteCursor_.hasSelection()) {
		cursor = tabCompleteCursor_;
	}
	else {
		cursor = input_->textCursor();
		while(cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor) && cursor.document()->characterAt(cursor.position() - 1) != ' ') { }
	}
	QString root = cursor.selectedText();
	if (root.isEmpty()) {
		return;
	}
	QString suggestion = P2QSTRING(completer_->completeWord(Q2PSTRING(root)));
	if (root == suggestion) {
		return;
	}
	tabCompletion_ = true;
	cursor.beginEditBlock();
	cursor.removeSelectedText();
	int oldPosition = cursor.position();

	cursor.insertText(suggestion);
	tabCompleteCursor_ = cursor;
	tabCompleteCursor_.setPosition(oldPosition, QTextCursor::KeepAnchor);

	cursor.endEditBlock();
	tabCompletion_ = false;
}
开发者ID:jyhong836,项目名称:swift,代码行数:33,代码来源:QtChatWindow.cpp


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