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


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

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


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

示例1:

void QEditorInputBinding::EditCommand::exec(QEditor *e)
{
	QDocumentCursor c = e->cursor();
	
	switch ( operation )
	{
		case ClearSelection :
			c.clearSelection();
			break;
			
		case SelectWord :
			c.select(QDocumentCursor::WordUnderCursor);
			break;
			
		case SelectLine :
			c.select(QDocumentCursor::LineUnderCursor);
			break;
			
		case SelectDocument :
			c.movePosition(1, QDocumentCursor::Start, QDocumentCursor::MoveAnchor);
			c.movePosition(1, QDocumentCursor::End, QDocumentCursor::KeepAnchor);
			break;
			
		case DeleteChar :
			c.deleteChar();
			break;
			
		case DeletePreviousChar :
			c.deletePreviousChar();
			break;
			
		case DeleteLine :
			c.eraseLine();
			break;
			
		case DeleteSelection :
			c.removeSelectedText();
			break;
			
		case InsertLine :
			c.insertLine();
			break;
			
		case InsertClipBoard :
			e->paste();
			return;
			
		default:
			
			break;
	}
	
	e->setCursor(c);
}
开发者ID:BrentBaccala,项目名称:CoCoA,代码行数:54,代码来源:qeditorinputbinding.cpp

示例2: insertAt

void CompletionWord::insertAt(QEditor* editor, QDocumentCursor cursor){
    QString savedSelection;
    int multilines=shownWord.count('\n');
    QVector<QDocumentLine> documentlines;

    if (cursor.hasSelection()) {
        savedSelection=cursor.selectedText();
        cursor.removeSelectedText();
    }
    QDocumentCursor selector=cursor;
    int curStart=cursor.columnNumber();
    QDocumentLine curLine=cursor.line();

    cursor.insertText(shownWord);

    if (multilines) {
        documentlines.resize(multilines+1);
        documentlines[0]=curLine;
        for (int i=1;i<documentlines.count()-1;i++) documentlines[i]=documentlines[i-1].next(); //todo: optimize
    }

    if (QDocument::formatFactory())
        for (int i=0;i<descriptiveParts.size();i++) {
            QFormatRange fr(descriptiveParts[i].first+curStart,descriptiveParts[i].second,QDocument::formatFactory()->id("temporaryCodeCompletion"));
            if (multilines) {
                QString temp= shownWord;
                temp.truncate(descriptiveParts[i].first);
                int linetoadd=temp.count('\n');
                if (linetoadd==0) curLine.addOverlay(fr);
                else if (linetoadd<documentlines.size()) {
                    fr.offset=temp.size()-temp.lastIndexOf('\n')-1;
                    documentlines[linetoadd].addOverlay(fr);
                }
            } else curLine.addOverlay(fr);
        }

    //place cursor/add \end
    int selectFrom=-1;
    int selectTo=-1;
    int deltaLine=0;
    if (shownWord.startsWith("\\begin")&&!multilines) {
        //int curColumnNumber=cursor.columnNumber();
        QString indent=curLine.indentation();
        int p=shownWord.indexOf("{");
        QString content="content...";
        if (editor->flag(QEditor::AutoIndent)){
            cursor.insertText( "\n"+indent+"\t"+content+"\n"+indent+"\\end"+shownWord.mid(p,shownWord.indexOf("}")-p+1));
            indent+="\t";
        } else
            cursor.insertText( "\n"+indent+content+"\n"+indent+"\\end"+shownWord.mid(p,shownWord.indexOf("}")-p+1));
        if (QDocument::formatFactory())
            for (int i=0;i<descriptiveParts.size();i++)
                curLine.next().addOverlay(QFormatRange(indent.size(),content.size(),QDocument::formatFactory()->id("temporaryCodeCompletion")));

        if (cursorPos==-1) {
            deltaLine=1;
            selectFrom=indent.length();
            selectTo=indent.length()+content.size();
        } else {
            selectFrom=anchorPos+curStart;
            selectTo=cursorPos+curStart;
        }
    } else if (cursorPos>-1) {
        if (multilines) { //todo: add support for selected multilines
            QString temp= shownWord;
            temp.truncate(cursorPos);
            deltaLine=temp.count('\n');
            if (!deltaLine) {
                selectFrom=anchorPos+curStart;
                selectTo=cursorPos+curStart;
            } else {
                selectTo=temp.size()-temp.lastIndexOf('\n')-1;
                selectFrom=anchorPos-cursorPos+selectTo;
            }
        } else {
            selectFrom=anchorPos+curStart;
            selectTo=cursorPos+curStart;
        }
    } else editor->setCursor(cursor); //place after insertion
    if (selectFrom!=-1){
        if (deltaLine>0) selector.movePosition(deltaLine,QDocumentCursor::Down,QDocumentCursor::MoveAnchor);
        selector.setColumnNumber(selectFrom);
        if (selectTo>selectFrom) selector.movePosition(selectTo-selectFrom,QDocumentCursor::Right,QDocumentCursor::KeepAnchor);
        else if (selectTo<selectFrom) selector.movePosition(selectFrom-selectTo,QDocumentCursor::Left,QDocumentCursor::KeepAnchor);
        editor->setCursor(selector);
    }
    if (!savedSelection.isEmpty() && cursorPos>0) editor->cursor().insertText(savedSelection);
}
开发者ID:svn2github,项目名称:texstudio,代码行数:88,代码来源:latexcompleter.cpp


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