本文整理汇总了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);
}
示例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);
}