本文整理汇总了C++中QStringRef::position方法的典型用法代码示例。如果您正苦于以下问题:C++ QStringRef::position方法的具体用法?C++ QStringRef::position怎么用?C++ QStringRef::position使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStringRef
的用法示例。
在下文中一共展示了QStringRef::position方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eventFilter
bool Highlighter::eventFilter(QObject* watched, QEvent* event)
{
if (watched != m_text->viewport() || event->type() != QEvent::ContextMenu || !m_enabled) {
return QSyntaxHighlighter::eventFilter(watched, event);
} else {
// Check spelling of text block under mouse
QContextMenuEvent* context_event = static_cast<QContextMenuEvent*>(event);
m_start_cursor = m_text->cursorForPosition(context_event->pos());
QTextBlock block = m_start_cursor.block();
int cursor = m_start_cursor.position() - block.position();
bool under_mouse = false;
QStringRef word;
QVector<QStringRef> words = static_cast<BlockStats*>(block.userData())->misspelled();
for (int i = 0; i < words.count(); ++i) {
word = words.at(i);
int delta = cursor - word.position();
if (delta >= 0 && delta <= word.length()) {
under_mouse = true;
break;
}
}
if (!under_mouse) {
return false;
} else {
// Select misspelled word
m_cursor = m_start_cursor;
m_cursor.setPosition(word.position() + block.position());
m_cursor.setPosition(m_cursor.position() + word.length(), QTextCursor::KeepAnchor);
m_word = m_cursor.selectedText();
m_text->setTextCursor(m_cursor);
// List suggestions in context menu
QMenu* menu = new QMenu;
QStringList guesses = m_dictionary->suggestions(m_word);
if (!guesses.isEmpty()) {
foreach (const QString& guess, guesses) {
menu->addAction(guess);
}
} else {
示例2: nextToken
QStringRef ChessEngine::nextToken(const QStringRef& previous, bool untilEnd)
{
const QString* str = previous.string();
if (str == 0)
return QStringRef();
int i;
int start = -1;
int firstPos = previous.position() + previous.size();
for (i = firstPos; i < str->size(); i++)
{
if (str->at(i).isSpace())
{
if (start == -1)
continue;
break;
}
else if (start == -1)
{
start = i;
if (untilEnd)
{
int end = str->size();
while (str->at(--end).isSpace())
;
i = end + 1;
break;
}
}
}
if (start == -1)
return QStringRef();
return QStringRef(str, start, i - start);
}
示例3: parse
/*!
\internal
Parses \a pattern.
Allowed is f.ex.:
qt.core.io.debug FullText, QtDebugMsg
qt.core.* LeftFilter, all types
*.io.warning RightFilter, QtWarningMsg
*.core.* MidFilter
*/
void QLoggingRule::parse(const QStringRef &pattern)
{
QStringRef p;
// strip trailing ".messagetype"
if (pattern.endsWith(QLatin1String(".debug"))) {
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 6); // strlen(".debug")
messageType = QtDebugMsg;
} else if (pattern.endsWith(QLatin1String(".info"))) {
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 5); // strlen(".info")
messageType = QtInfoMsg;
} else if (pattern.endsWith(QLatin1String(".warning"))) {
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 8); // strlen(".warning")
messageType = QtWarningMsg;
} else if (pattern.endsWith(QLatin1String(".critical"))) {
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 9); // strlen(".critical")
messageType = QtCriticalMsg;
} else {
p = pattern;
}
if (!p.contains(QLatin1Char('*'))) {
flags = FullText;
} else {
if (p.endsWith(QLatin1Char('*'))) {
flags |= LeftFilter;
p = QStringRef(p.string(), p.position(), p.length() - 1);
}
if (p.startsWith(QLatin1Char('*'))) {
flags |= RightFilter;
p = QStringRef(p.string(), p.position() + 1, p.length() - 1);
}
if (p.contains(QLatin1Char('*'))) // '*' only supported at start/end
flags = 0;
}
category = p.toString();
}
示例4: tokenize
UrlParser::UrlTokenList UrlParser::tokenize(const QString &text, Flags flags)
{
UrlTokenList result;
static QRegExp linkRegExp("([a-zA-Z0-9\\-\\_\\.][email protected]([a-zA-Z0-9\\-\\_]+\\.)+[a-zA-Z]+)|"
"([a-z]+(\\+[a-z]+)?://|www\\.)"
"[\\w-]+(\\.[\\w-]+)*\\.\\w+"
"(:\\d+)?"
"(/[\\w\\+\\.\\[\\]!%\\$/\\(\\),:;@'&=~-]*"
"(\\?[\\w\\+\\.\\[\\]!%\\$/\\(\\),:;@\\'&=~-]*)?"
"(#[\\w\\+\\.\\[\\]!%\\$/\\\\\\(\\)\\|,:;@&=~-]*)?)?",
Qt::CaseInsensitive);
Q_ASSERT(linkRegExp.isValid());
QList<QPair<int, int> > tags;
int currentTag = 0;
if (flags & Html) {
enum TagParserState {
AtText,
AtTag,
AtSingleQuote,
AtDoubleQuote
};
TagParserState state = AtText;
int start = 0;
for (int i = 0; i < text.size(); ++i) {
QChar ch = text.at(i);
switch (state) {
case AtText:
if (ch == QLatin1Char('<')) {
state = AtTag;
start = i;
}
break;
case AtTag:
if (ch == QLatin1Char('>')) {
tags << qMakePair(start, i);
state = AtText;
} else if (ch == QLatin1Char('\'')) {
state = AtSingleQuote;
} else if (ch == QLatin1Char('\"')) {
state = AtDoubleQuote;
}
break;
case AtSingleQuote:
if (ch == QLatin1Char('\''))
state = AtTag;
break;
case AtDoubleQuote:
if (ch == QLatin1Char('\"'))
state = AtTag;
break;
}
}
}
int pos = 0;
int lastPos = 0;
while (((pos = linkRegExp.indexIn(text, pos)) != -1)) {
QString link = linkRegExp.cap(0);
while (currentTag < tags.size() && tags.at(currentTag).second < pos)
currentTag++;
if (currentTag < tags.size()) {
const QPair<int, int> &pair = tags.at(currentTag);
int left = qBound(pair.first, pos, pair.second);
int right = qBound(pair.first, pos + link.size(), pair.second);
if (left != right) {
pos += link.size();
continue;
}
}
UrlToken tok = { text.midRef(lastPos, pos - lastPos), QString() };
if (!tok.text.isEmpty()) {
if (!result.isEmpty() && result.last().url.isEmpty()) {
QStringRef tmp = result.last().text;
result.last().text = QStringRef(tmp.string(), tmp.position(), tmp.size() + tok.text.size());
} else {
result << tok;
}
}
tok.text = text.midRef(pos, link.size());
pos += link.size();
if (link.startsWith(QLatin1String("www."), Qt::CaseInsensitive))
link.prepend(QLatin1String("http://"));
else if(!link.contains(QLatin1String("//")))
link.prepend(QLatin1String("mailto:"));
tok.url = link;
result << tok;
lastPos = pos;
}
if (!result.isEmpty() && result.last().url.isEmpty()) {
result.last().text = text.midRef(result.last().text.position());
} else {
UrlToken tok = { text.midRef(lastPos), QString() };
result << tok;
}
return result;
}
示例5: check
void SpellChecker::check()
{
setDisabled(true);
QProgressDialog wait_dialog(tr("Checking spelling..."), tr("Cancel"), 0, m_total_blocks, this);
wait_dialog.setWindowTitle(tr("Please wait"));
wait_dialog.setValue(0);
wait_dialog.setWindowModality(Qt::WindowModal);
bool canceled = false;
forever {
// Update wait dialog
wait_dialog.setValue(m_checked_blocks);
if (wait_dialog.wasCanceled()) {
canceled = true;
break;
}
// Check current line
QTextBlock block = m_cursor.block();
QStringRef word = m_dictionary.check(block.text(), m_cursor.position() - block.position());
if (word.isNull()) {
if (block.next().isValid()) {
m_cursor.movePosition(QTextCursor::NextBlock);
++m_checked_blocks;
if (m_checked_blocks < m_total_blocks) {
continue;
} else {
break;
}
} else if (m_loop_available) {
wait_dialog.reset();
if (QMessageBox::question(this, QString(), tr("Continue checking at beginning of file?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) {
m_loop_available = false;
m_cursor.movePosition(QTextCursor::Start);
wait_dialog.setRange(0, m_total_blocks);
continue;
} else {
canceled = true;
break;
}
} else {
break;
}
}
// Select misspelled word
m_cursor.setPosition(word.position() + block.position());
m_cursor.setPosition(m_cursor.position() + word.length(), QTextCursor::KeepAnchor);
m_word = m_cursor.selectedText();
if (!m_ignored.contains(m_word)) {
wait_dialog.close();
setEnabled(true);
// Show misspelled word in context
QTextCursor cursor = m_cursor;
cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::MoveAnchor, 10);
int end = m_cursor.position() - cursor.position();
int start = end - m_word.length();
cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor, 21);
QString context = cursor.selectedText();
context.insert(end, "</span>");
context.insert(start, "<span style=\"color: red;\">");
context.replace("\n", "</p><p>");
context.replace("\t", "<span style=\"white-space: pre;\">\t</span>");
context = "<p>" + context + "</p>";
m_context->setHtml(context);
// Show suggestions
m_suggestion->clear();
m_suggestions->clear();
QStringList words = m_dictionary.suggestions(m_word);
if (!words.isEmpty()) {
foreach (const QString& word, words) {
m_suggestions->addItem(word);
}
m_suggestions->setCurrentRow(0);
}
示例6: check
void SpellChecker::check()
{
setDisabled(true);
QProgressDialog wait_dialog(tr("Checking spelling..."), tr("Cancel"), 0, m_document->document()->characterCount(), this);
wait_dialog.setWindowTitle(tr("Please wait"));
wait_dialog.setValue(0);
wait_dialog.setWindowModality(Qt::WindowModal);
forever {
// Update wait dialog
wait_dialog.setValue(m_cursor.position());
if (wait_dialog.wasCanceled()) {
m_document->setTextCursor(m_start_cursor);
reject();
}
// Check current line
QTextBlock block = m_cursor.block();
QStringRef word = m_dictionary->check(block.text(), m_cursor.position() - block.position());
if (word.isNull()) {
if (block.next().isValid()) {
m_cursor.movePosition(QTextCursor::NextBlock);
continue;
} else {
break;
}
}
// Select misspelled word
m_cursor.setPosition(word.position() + block.position());
m_cursor.setPosition(m_cursor.position() + word.length(), QTextCursor::KeepAnchor);
m_word = m_cursor.selectedText();
if (!m_ignored.contains(m_word)) {
wait_dialog.close();
setEnabled(true);
// Show misspelled word in context
QTextCursor cursor = m_cursor;
cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::MoveAnchor, 10);
int end = m_cursor.position() - cursor.position();
int start = end - m_word.length();
cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor, 21);
QString context = cursor.selectedText();
context.insert(end, "</span>");
context.insert(start, "<span style=\"color: red;\">");
context.replace("\n", "</p><p>");
context.replace("\t", "<span style=\"white-space: pre;\">\t</span>");
context = "<p>" + context + "</p>";
m_context->setHtml(context);
// Show suggestions
m_suggestion->clear();
m_suggestions->clear();
QStringList words = m_dictionary->suggestions(m_word);
if (!words.isEmpty()) {
foreach (const QString& word, words) {
m_suggestions->addItem(word);
}
m_suggestions->setCurrentRow(0);
}
示例7:
ProString::ProString(const QStringRef &str) :
m_string(*str.string()), m_offset(str.position()), m_length(str.size()), m_file(0), m_hash(0x80000000)
{
}