本文整理汇总了C++中QDocumentCursor::selectionEnd方法的典型用法代码示例。如果您正苦于以下问题:C++ QDocumentCursor::selectionEnd方法的具体用法?C++ QDocumentCursor::selectionEnd怎么用?C++ QDocumentCursor::selectionEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDocumentCursor
的用法示例。
在下文中一共展示了QDocumentCursor::selectionEnd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: searchReplaceFunction
QScriptValue searchReplaceFunction(QScriptContext *context, QScriptEngine *engine, bool replace){
QEditor *editor = qobject_cast<QEditor*>(context->thisObject().toQObject());
//read arguments
SCRIPT_REQUIRE(editor, "invalid object");
SCRIPT_REQUIRE(!replace || context->argumentCount()>=2, "at least two arguments are required");
SCRIPT_REQUIRE(context->argumentCount()>=1, "at least one argument is required");
SCRIPT_REQUIRE(context->argumentCount()<=4, "too many arguments");
SCRIPT_REQUIRE(context->argument(0).isString()||context->argument(0).isRegExp(), "first argument must be a string or regexp");
QDocumentSearch::Options flags = QDocumentSearch::Silent;
bool global = false, caseInsensitive = false;
QString searchFor;
if (context->argument(0).isRegExp()) {
flags |= QDocumentSearch::RegExp;
QRegExp r = context->argument(0).toRegExp();
searchFor = r.pattern();
caseInsensitive = r.caseSensitivity() == Qt::CaseInsensitive;
Q_ASSERT(caseInsensitive == context->argument(0).property("ignoreCase").toBool()); //check assumption about javascript core
global = context->argument(0).property("global").toBool();
} else searchFor = context->argument(0).toString();
QScriptValue handler;
QDocumentCursor scope = editor->document()->cursor(0,0,editor->document()->lineCount(),0);
int handlerCount = 0;
for (int i=1; i<context->argumentCount();i++)
if (context->argument(i).isString() || context->argument(i).isFunction()) handlerCount++;
SCRIPT_REQUIRE(handlerCount <= (replace?2:1), "too many string or function arguments");
for (int i=1; i<context->argumentCount();i++) {
QScriptValue a = context->argument(i);
if (a.isFunction()) {
SCRIPT_REQUIRE(!handler.isValid(), "Multiple callbacks");
handler = a;
} else if (a.isString()) {
if (!replace || handlerCount > 1) {
QString s = a.toString().toLower();
global = s.contains("g");
caseInsensitive = s.contains("i");
if (s.contains("w")) flags |= QDocumentSearch::WholeWords;
} else {
SCRIPT_REQUIRE(!handler.isValid(), "Multiple callbacks");
handler = a;
}
handlerCount--;
} else if (a.isNumber()) flags |= QDocumentSearch::Options((int)a.toNumber());
else if (a.isObject()) scope = cursorFromValue(a);
else SCRIPT_REQUIRE(false, "Invalid argument");
}
SCRIPT_REQUIRE(handler.isValid() || !replace, "No callback given");
if (!caseInsensitive) flags |= QDocumentSearch::CaseSensitive;
//search/replace
QDocumentSearch search(editor, searchFor, flags);
search.setScope(scope);
if (replace && handler.isString()) {
search.setReplaceText(handler.toString());
search.setOption(QDocumentSearch::Replace,true);
return search.next(false, global, false, false);
}
if (!handler.isValid())
return search.next(false,global,true,false);
int count=0;
while (search.next(false, false, true, false) && search.cursor().isValid()) {
count++;
QDocumentCursor temp = search.cursor();
QScriptValue cb = handler.call(QScriptValue(), QScriptValueList() << engine->newQObject(&temp));
if (replace && cb.isValid()){
QDocumentCursor tmp = search.cursor();
tmp.replaceSelectedText(cb.toString());
search.setCursor(tmp.selectionEnd());
}
if (!global) break;
}
return count;
}