本文整理汇总了C++中TokenIterator::position方法的典型用法代码示例。如果您正苦于以下问题:C++ TokenIterator::position方法的具体用法?C++ TokenIterator::position怎么用?C++ TokenIterator::position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TokenIterator
的用法示例。
在下文中一共展示了TokenIterator::position方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cursorAt
QTextCursor ScCodeEditor::cursorAt(const TokenIterator it, int offset)
{
Q_ASSERT(it.isValid());
QTextCursor textCursor(textDocument());
textCursor.setPosition(it.position() + offset);
return textCursor;
}
示例2: selectionForPosition
QTextCursor ScCodeEditor::selectionForPosition( int position )
{
QTextBlock block( textDocument()->findBlock(position) );
if (!block.isValid())
return QTextCursor();
int positionInBlock = position - block.position();
TokenIterator it = TokenIterator( block, positionInBlock );
if (it.type() == Token::Unknown) {
// Token is invalid, or Token::Unknown (i.e. punctuations).
// Prefer token at previous position.
TokenIterator alternativeIt = TokenIterator( block, positionInBlock - 1 );
if (alternativeIt.isValid())
it = alternativeIt;
}
if (it.isValid()) {
switch (it->type) {
case Token::OpeningBracket:
case Token::ClosingBracket:
{
BracketPair match;
matchBracket(it, match);
if (match.first.isValid() && match.second.isValid()) {
int start = match.first.position();
int end = match.second.position() + 1;
QTextCursor selection(textDocument());
if (it == match.second) {
selection.setPosition(start);
selection.setPosition(end, QTextCursor::KeepAnchor);
} else {
selection.setPosition(end);
selection.setPosition(start, QTextCursor::KeepAnchor);
}
return selection;
}
break;
}
default:
QTextCursor selection( textDocument() );
selection.setPosition( it.position() );
selection.setPosition( selection.position() + it->length, QTextCursor::KeepAnchor );
return selection;
}
}
return QTextCursor();
}