本文整理汇总了C++中QTextBlock::previous方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextBlock::previous方法的具体用法?C++ QTextBlock::previous怎么用?C++ QTextBlock::previous使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextBlock
的用法示例。
在下文中一共展示了QTextBlock::previous方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: indentBlock
void Indenter::indentBlock(const QTextBlock &block,
const QChar &,
const TextEditor::TabSettings &settings,
int)
{
int indent;
QTextBlock previous = block.previous();
// Previous line ends on comma, ignore everything and follow the indent
if (previous.text().endsWith(',')) {
indent = previous.text().indexOf(QRegularExpression("\\S")) / settings.m_indentSize;
} else {
// Use the stored indent plus some bizarre heuristics that even myself remember how it works.
indent = block.userState() >> 20;
if (indent < 0) {
while (indent == -1 && previous.isValid()) {
indent = previous.userState() >> 20;
previous = previous.previous();
}
}
if (didBlockStart(block) && indent > 0)
indent--;
}
settings.indentLine(block, indent * settings.m_indentSize);
}
示例2: indentBlock
void CMakeIndenter::indentBlock(QTextDocument *doc, const QTextBlock &block, const QChar &typedChar, const TextEditor::TabSettings &tabSettings)
{
Q_UNUSED(doc)
Q_UNUSED(typedChar)
QTextBlock previousBlock = block.previous();
// find the next previous block that is non-empty (contains non-whitespace characters)
while (previousBlock.isValid() && lineIsEmpty(previousBlock.text()))
previousBlock = previousBlock.previous();
if (previousBlock.isValid()) {
const QString previousLine = previousBlock.text();
const QString currentLine = block.text();
int indentation = tabSettings.indentationColumn(previousLine);
if (lineStartsBlock(previousLine))
indentation += tabSettings.m_indentSize;
if (lineEndsBlock(currentLine))
indentation = qMax(0, indentation - tabSettings.m_indentSize);
// increase/decrease/keep the indentation level depending on if we have more opening or closing parantheses
indentation = qMax(0, indentation + tabSettings.m_indentSize * paranthesesLevel(previousLine));
tabSettings.indentLine(block, indentation);
} else {
// First line in whole document
tabSettings.indentLine(block, 0);
}
}
示例3: autoIndent
void KNoteEdit::autoIndent()
{
QTextCursor c = textCursor();
QTextBlock b = c.block();
QString string;
while ( ( b.previous().length() > 0 ) && string.trimmed().isEmpty() ) {
b = b.previous();
string = b.text();
}
if ( string.trimmed().isEmpty() ) {
return;
}
// This routine returns the whitespace before the first non white space
// character in string.
// It is assumed that string contains at least one non whitespace character
// ie \n \r \t \v \f and space
QString indentString;
const int len = string.length();
int i = 0;
while ( i < len && string.at( i ).isSpace() ) {
indentString += string.at( i++ );
}
if ( !indentString.isEmpty() ) {
c.insertText( indentString );
}
}
示例4: reverseFindLastEmptyBlock
QTextBlock reverseFindLastEmptyBlock(QTextBlock start)
{
if (start.position() > 0) {
start = start.previous();
while (start.position() > 0 && start.text().trimmed().isEmpty())
start = start.previous();
if (!start.text().trimmed().isEmpty())
start = start.next();
}
return start;
}
示例5: forceIndentWithExtraText
// Add extra text in case of the empty line or the line starting with ')'.
// Track such extra pieces of text in isInsideModifiedLine().
int forceIndentWithExtraText(QByteArray &buffer, const QTextBlock &block, bool secondTry)
{
const QString blockText = block.text();
int firstNonWhitespace = Utils::indexOf(blockText,
[](const QChar &ch) { return !ch.isSpace(); });
int utf8Offset = Utils::Text::utf8NthLineOffset(block.document(),
buffer,
block.blockNumber() + 1);
if (firstNonWhitespace > 0)
utf8Offset += firstNonWhitespace;
else
utf8Offset += blockText.length();
const bool closingParenBlock = firstNonWhitespace >= 0
&& blockText.at(firstNonWhitespace) == ')';
int extraLength = 0;
if (firstNonWhitespace < 0 || closingParenBlock) {
//This extra text works for the most cases.
QByteArray dummyText("a;a;");
// Search for previous character
QTextBlock prevBlock = block.previous();
bool prevBlockIsEmpty = prevBlock.position() > 0 && prevBlock.text().trimmed().isEmpty();
while (prevBlockIsEmpty) {
prevBlock = prevBlock.previous();
prevBlockIsEmpty = prevBlock.position() > 0 && prevBlock.text().trimmed().isEmpty();
}
if (closingParenBlock || prevBlock.text().endsWith(','))
dummyText = "&& a";
buffer.insert(utf8Offset, dummyText);
extraLength += dummyText.length();
}
if (secondTry) {
int nextLinePos = buffer.indexOf('\n', utf8Offset);
if (nextLinePos < 0)
nextLinePos = buffer.size() - 1;
if (nextLinePos > 0) {
// If first try was not successful try to put ')' in the end of the line to close possibly
// unclosed parentheses.
// TODO: Does it help to add different endings depending on the context?
buffer.insert(nextLinePos, ')');
extraLength += 1;
}
}
return extraLength;
}
示例6: formattingRangeStart
int formattingRangeStart(const QTextBlock ¤tBlock,
const QByteArray &buffer,
int documentRevision)
{
QTextBlock prevBlock = currentBlock.previous();
while ((prevBlock.position() > 0 || prevBlock.length() > 0)
&& prevBlock.revision() != documentRevision) {
// Find the first block with not matching revision.
prevBlock = prevBlock.previous();
}
if (prevBlock.revision() == documentRevision)
prevBlock = prevBlock.next();
return Utils::Text::utf8NthLineOffset(prevBlock.document(), buffer, prevBlock.blockNumber() + 1);
}
示例7: findOpeningMatch
static int findOpeningMatch(const QTextDocument *doc, int cursorPosition) {
QTextBlock block = doc->findBlock(cursorPosition);
TextBlockData *blockData =
reinterpret_cast<TextBlockData *>(block.userData());
if (!blockData->bracketPositions.isEmpty()) {
int depth = 1;
while (block.isValid()) {
blockData = reinterpret_cast<TextBlockData *>(block.userData());
if (blockData && !blockData->bracketPositions.isEmpty()) {
for (int c = blockData->bracketPositions.count() - 1; c >= 0; --c) {
int absPos = block.position() + blockData->bracketPositions.at(c);
if (absPos >= cursorPosition - 1) continue;
if (doc->characterAt(absPos) == '}') depth++;
else depth--;
if (depth == 0) return absPos;
}
}
block = block.previous();
}
}
return -1;
}
示例8: indentBlock
void CodeEditer::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar)
{
Q_UNUSED(typedChar);
// At beginning: Leave as is.
if (block == doc->begin())
return;
const QTextBlock previous = block.previous();
const QString previousText = previous.text();
// Empty line indicates a start of a new paragraph. Leave as is.
if (previousText.isEmpty() || previousText.trimmed().isEmpty())
return;
// Just use previous line.
// Skip non-alphanumerical characters when determining the indentation
// to enable writing bulleted lists whose items span several lines.
int i = 0;
while (i < previousText.size()) {
if (previousText.at(i).isLetterOrNumber() ||
previousText.at(i) == '{' ||
previousText.at(i) == '}' ||
previousText.at(i) == '#') {
//const TextEditor::TabSettings &ts = tabSettings();
indentLine(block, columnAt(previousText, i));
break;
}
++i;
}
}
示例9: findPreviousBlockOpenParenthesis
bool TextBlockUserData::findPreviousBlockOpenParenthesis(QTextCursor *cursor, bool checkStartPosition)
{
QTextBlock block = cursor->block();
int position = cursor->position();
int ignore = 0;
while (block.isValid()) {
Parentheses parenList = BaseTextDocumentLayout::parentheses(block);
if (!parenList.isEmpty() && !BaseTextDocumentLayout::ifdefedOut(block)) {
for (int i = parenList.count()-1; i >= 0; --i) {
Parenthesis paren = parenList.at(i);
if (paren.chr != QLatin1Char('{') && paren.chr != QLatin1Char('}')
&& paren.chr != QLatin1Char('+') && paren.chr != QLatin1Char('-')
&& paren.chr != QLatin1Char('[') && paren.chr != QLatin1Char(']'))
continue;
if (block == cursor->block()) {
if (position - block.position() <= paren.pos + (paren.type == Parenthesis::Closed ? 1 : 0))
continue;
if (checkStartPosition && paren.type == Parenthesis::Opened && paren.pos== cursor->position()) {
return true;
}
}
if (paren.type == Parenthesis::Closed) {
++ignore;
} else if (ignore > 0) {
--ignore;
} else {
cursor->setPosition(block.position() + paren.pos);
return true;
}
}
}
block = block.previous();
}
return false;
}
示例10: findPreviousOpenParenthesis
bool TextBlockUserData::findPreviousOpenParenthesis(QTextCursor *cursor, bool select, bool onlyInCurrentBlock)
{
QTextBlock block = cursor->block();
int position = cursor->position();
int ignore = 0;
while (block.isValid()) {
Parentheses parenList = BaseTextDocumentLayout::parentheses(block);
if (!parenList.isEmpty() && !BaseTextDocumentLayout::ifdefedOut(block)) {
for (int i = parenList.count()-1; i >= 0; --i) {
Parenthesis paren = parenList.at(i);
if (block == cursor->block() &&
(position - block.position() <= paren.pos + (paren.type == Parenthesis::Closed ? 1 : 0)))
continue;
if (paren.type == Parenthesis::Closed) {
++ignore;
} else if (ignore > 0) {
--ignore;
} else {
cursor->setPosition(block.position() + paren.pos, select ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor);
return true;
}
}
}
if (onlyInCurrentBlock)
return false;
block = block.previous();
}
return false;
}
示例11: getActiveStatement
QString QueryPanel::getActiveStatement(int block, int col) {
int from = 0, to = -1;
State st;
QTextBlock b = editor->document()->findBlockByNumber(block);
int scol = col;
while(b.isValid()) {
st.opaque = b.userState();
if(st.s.col != -1 && st.s.col < scol) {
from = b.position() + st.s.col + 1;
break;
}
scol = INT_MAX;
b = b.previous();
}
b = editor->document()->findBlockByNumber(block);
scol = col;
while(b.isValid()) {
st.opaque = b.userState();
if(st.s.col != -1 && st.s.col >= scol) {
to = b.position() + st.s.col;
break;
}
scol = 0;
b = b.next();
}
QString all = editor->document()->toPlainText();
if(to < 0)
to = all.length();
return all.mid(from,to);;
}
示例12: if
TokenIterator& operator --()
{
if(idx > 0)
{
--idx;
return *this;
}
else if( idx < 0 )
{
return *this;
}
idx = -1;
while( (blk = blk.previous()).isValid() )
{
data = static_cast<TextBlockData*>(blk.userData());
if(data)
idx = data->tokens.size() - 1;
if (idx < 0)
continue;
// we have a valid idx
break;
}
return *this;
}
示例13: searchPreviousMatch
int ShaderEdit::searchPreviousMatch( QTextBlock block, int start, QString close, QString open )
{
int skipNext = 0;
--start;
TextBlockData *data = (TextBlockData*)block.userData();
do {
if ( data ) {
for ( int i = start; i >= 0; --i ) {
ParenthesisInfo pi = data->parenthesis[i];
QString s = pi.character;
if ( s == open ) {
if ( skipNext > 0 )
--skipNext;
else
return block.position() + pi.position;
}
else if ( s == close )
++skipNext;
}
}
block = block.previous();
data = (TextBlockData*)block.userData();
if ( data )
start = data->parenthesis.count() - 1;
} while ( block.isValid() );
return -1;
}
示例14: indentBlock
void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
const TextEditor::TabSettings &tabSettings)
{
Q_UNUSED(doc)
CppTools::QtStyleCodeFormatter codeFormatter(tabSettings, codeStyleSettings());
codeFormatter.updateStateUntil(block);
int indent;
int padding;
codeFormatter.indentFor(block, &indent, &padding);
if (isElectricCharacter(typedChar)) {
// : should not be electric for labels
if (typedChar == QLatin1Char(':') && !colonIsElectric(block.text()))
return;
// only reindent the current line when typing electric characters if the
// indent is the same it would be if the line were empty
int newlineIndent;
int newlinePadding;
codeFormatter.indentForNewLineAfter(block.previous(), &newlineIndent, &newlinePadding);
if (tabSettings.indentationColumn(block.text()) != newlineIndent + newlinePadding)
return;
}
tabSettings.indentLine(block, indent + padding, padding);
}
示例15: insert_head
void MarkdownEdit::insert_head(const QString &tag, bool blockStart)
{
QTextCursor cur = m_ed->textCursor();
cur.beginEditBlock();
if (cur.hasSelection()) {
QTextBlock begin = m_ed->document()->findBlock(cur.selectionStart());
QTextBlock end = m_ed->document()->findBlock(cur.selectionEnd());
if (end.position() == cur.selectionEnd()) {
end = end.previous();
}
QTextBlock block = begin;
do {
if (block.text().length() > 0) {
if (blockStart) {
cur.setPosition(block.position());
} else {
QString text = block.text();
foreach(QChar c, text) {
if (!c.isSpace()) {
cur.setPosition(block.position()+text.indexOf(c));
break;
}
}
}
cur.insertText(tag);
}
block = block.next();
} while(block.isValid() && block.position() <= end.position());
} else {