本文整理汇总了C++中TextEditor::changeTextCursor方法的典型用法代码示例。如果您正苦于以下问题:C++ TextEditor::changeTextCursor方法的具体用法?C++ TextEditor::changeTextCursor怎么用?C++ TextEditor::changeTextCursor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextEditor
的用法示例。
在下文中一共展示了TextEditor::changeTextCursor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: replaceAll
void FindDialog::replaceAll() {
TextEditor *current = m_parent->m_activeEditor;
QTextDocument *doc = current->getTextDocument();
QTextCursor start = current->textCursor();
QTextCursor result, last;
int noOccurrences = 0, startPos = -1, endPos = -1;
m_searching = false;
// search within a selection
if (start.hasSelection() && searchSelection()) {
startPos = start.selectionStart();
endPos = start.selectionEnd();
// get rid of selection
if (findBackwards())
start.setPosition(endPos);
else start.setPosition(startPos);
} else start.movePosition(QTextCursor::Start);
start.beginEditBlock();
result = start;
do {
last = result;
result = replace(result, doc, startPos, endPos);
if (result.isNull())
break;
// disallow infinite replacements of similar terms ('life' w/ 'LIFE')
result.setPosition(result.selectionEnd());
++noOccurrences;
} while(true);
start.endEditBlock();
if (noOccurrences <= 0) {
STATUS_BAR->showMessage(QString("%1 '%2' not found with the Options given").arg((regularExpression() ? QString("RegExp") : QString("String")), getSearchString()));
} else {
current->changeTextCursor(last);
STATUS_BAR->showMessage(QString("Replaced %1 occurence%2.").arg(QString::number(noOccurrences), (noOccurrences != 1 ? QString("s") : QString(""))));
}
updateReplace(true);
}
示例2: accept
void FindDialog::accept() {
TextEditor *current = m_parent->m_activeEditor;
QTextDocument *doc = current->getTextDocument();
QTextCursor start = current->textCursor();
QTextCursor result;
int startPos = -1, endPos = -1;
// see if we're supposed to search within a selection
if (start.hasSelection() && searchSelection()) {
startPos = start.selectionStart();
endPos = start.selectionEnd();
// get rid of selection
if (findBackwards())
start.setPosition(endPos);
else start.setPosition(startPos);
} else if (!fromCursor() && !m_searching)
start.movePosition(QTextCursor::Start);
if (isFind()) {
result = find(start, doc);
// test if result was outside of selection
if (!result.isNull() &&
((endPos > 0 && result.selectionEnd() > endPos) ||
(startPos > 0 && result.selectionStart() < startPos)))
result = QTextCursor(); // null cursor
} else result = replace(start, doc, endPos);
if (result.isNull()) {
STATUS_BAR->showMessage(QString("%1 '%2' not found with the Options given").arg((regularExpression() ? QString("RegExp") : QString("String")), getSearchString()));
m_searching = false;
updateReplace(isReplace());
} else {
current->changeTextCursor(result);
STATUS_BAR->clearMessage();
m_searching = true;
updateReplace(isReplace());
}
}