本文整理汇总了C++中QTextBlock::userState方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextBlock::userState方法的具体用法?C++ QTextBlock::userState怎么用?C++ QTextBlock::userState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextBlock
的用法示例。
在下文中一共展示了QTextBlock::userState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);;
}
示例2: reformatBlocks
void DevHighlighter::reformatBlocks(int from, int charsRemoved, int charsAdded)
{
QTextBlock block = doc->findBlock(from);
if (!block.isValid())
return;
QTextBlock endBlock;
if (charsAdded > charsRemoved || charsAdded == charsRemoved)
endBlock = doc->findBlock(from + charsAdded);
else
endBlock = block;
bool forceHighlightOfNextBlock = false;
while (block.isValid() && (!(endBlock < block) || forceHighlightOfNextBlock) )
{
const int stateBeforeHighlight = block.userState();
reformatBlock(block);
forceHighlightOfNextBlock = (block.userState() != stateBeforeHighlight);
block = block.next();
}
formatChanges.clear();
}
示例3: _q_reformatBlocks
void QSyntaxHighlighterPrivate::_q_reformatBlocks(int from, int charsRemoved, int charsAdded)
{
Q_UNUSED(charsRemoved);
rehighlightPending = false;
QTextBlock block = doc->findBlock(from);
if (!block.isValid())
return;
int endPosition;
QTextBlock lastBlock = doc->findBlock(from + charsAdded);
if (lastBlock.isValid())
endPosition = lastBlock.position() + lastBlock.length();
else
endPosition = doc->docHandle()->length();
bool forceHighlightOfNextBlock = false;
while (block.isValid() && (block.position() < endPosition || forceHighlightOfNextBlock)) {
const int stateBeforeHighlight = block.userState();
reformatBlock(block);
forceHighlightOfNextBlock = (block.userState() != stateBeforeHighlight);
block = block.next();
}
formatChanges.clear();
}
示例4: 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);
}
示例5: resetHereDocStates
// Reset the header state of a here-doc to 7
// and the state of its body to 6.
void Highlighter::resetHereDocStates (QTextBlock block)
{
if (block.userState() == hereDocTempState)
{
block.setUserState (hereDocHeaderState);
block = block.next();
while (block.isValid() && block.userState() != 0)
{
block.setUserState (hereDocBodyState);
block = block.next();
}
}
}
示例6: braceDepth
int BaseTextDocumentLayout::braceDepth(const QTextBlock &block)
{
int state = block.userState();
if (state == -1)
return 0;
return state >> 8;
}
示例7: enforceFormatting
void ScriptFormatter::enforceFormatting( QQuickTextDocument* document ) { //The script doesn't quite look right when loaded from a file, so we call this function.
if( document != nullptr && document != NULL ) {
for( QTextBlock block = document->textDocument()->firstBlock(); block != document->textDocument()->end(); block = block.next() ) {
setParagraphType( document, ( ScriptFormatter::paragraphType ) block.userState(), block.position() );
}
}
}
示例8: setBraceDepth
void BaseTextDocumentLayout::setBraceDepth(QTextBlock &block, int depth)
{
int state = block.userState();
if (state == -1)
state = 0;
state = state & 0xff;
block.setUserState((depth << 8) | state);
}
示例9: appendFragment
int QTextCopyHelper::appendFragment(int pos, int endPos, int objectIndex)
{
QTextDocumentPrivate::FragmentIterator fragIt = src->find(pos);
const QTextFragmentData * const frag = fragIt.value();
Q_ASSERT(objectIndex == -1
|| (frag->size_array[0] == 1 && src->formatCollection()->format(frag->format).objectIndex() != -1));
int charFormatIndex;
if (forceCharFormat)
charFormatIndex = primaryCharFormatIndex;
else
charFormatIndex = convertFormatIndex(frag->format, objectIndex);
const int inFragmentOffset = qMax(0, pos - fragIt.position());
int charsToCopy = qMin(int(frag->size_array[0] - inFragmentOffset), endPos - pos);
QTextBlock nextBlock = src->blocksFind(pos + 1);
int blockIdx = -2;
if (nextBlock.position() == pos + 1) {
blockIdx = convertFormatIndex(nextBlock.blockFormat());
} else if (pos == 0 && insertPos == 0) {
dst->setBlockFormat(dst->blocksBegin(), dst->blocksBegin(), convertFormat(src->blocksBegin().blockFormat()).toBlockFormat());
dst->setCharFormat(-1, 1, convertFormat(src->blocksBegin().charFormat()).toCharFormat());
}
QString txtToInsert(originalText.constData() + frag->stringPosition + inFragmentOffset, charsToCopy);
if (txtToInsert.length() == 1
&& (txtToInsert.at(0) == QChar::ParagraphSeparator
|| txtToInsert.at(0) == QTextBeginningOfFrame
|| txtToInsert.at(0) == QTextEndOfFrame
)
) {
dst->insertBlock(txtToInsert.at(0), insertPos, blockIdx, charFormatIndex);
++insertPos;
} else {
if (nextBlock.textList()) {
QTextBlock dstBlock = dst->blocksFind(insertPos);
if (!dstBlock.textList()) {
// insert a new text block with the block and char format from the
// source block to make sure that the following text fragments
// end up in a list as they should
int listBlockFormatIndex = convertFormatIndex(nextBlock.blockFormat());
int listCharFormatIndex = convertFormatIndex(nextBlock.charFormat());
dst->insertBlock(insertPos, listBlockFormatIndex, listCharFormatIndex);
++insertPos;
}
}
dst->insert(insertPos, txtToInsert, charFormatIndex);
const int userState = nextBlock.userState();
if (userState != -1)
dst->blocksFind(insertPos).setUserState(userState);
insertPos += txtToInsert.length();
}
return charsToCopy;
}
示例10: prepareForAsyncUse
void AssistInterface::prepareForAsyncUse()
{
m_text = m_textDocument->toPlainText();
m_userStates.reserve(m_textDocument->blockCount());
for (QTextBlock block = m_textDocument->firstBlock(); block.isValid(); block = block.next())
m_userStates.append(block.userState());
m_textDocument = 0;
m_isAsync = true;
}
示例11: pcChanged
void TextEditor::pcChanged(ParseNode *pc, bool justRolledBack) {
ParseNode *old = m_pc;
// cerr << "\tpcChanged id:" << QThread::currentThreadId() << "\n";
if (old == pc)
return;
m_pc = pc;
// if (m_program->getStatus() != PAUSED)
// return;
if (old != NULL) {
QTextBlock *b = old->getTextBlock();
int state = b->userState();
if (state > 0)
b->setUserState(state & ~B_CURRENT_PC);
}
if (m_pc != NULL) {
QTextBlock *b = m_pc->getTextBlock();
// cerr << "b: " << b->text().toStdString() << endl;
int state = b->userState();
if (state < 0)
b->setUserState(B_CURRENT_PC);
else b->setUserState(state | B_CURRENT_PC);
if (!justRolledBack && b != NULL) {
QTextCursor c = textCursor();
c.setPosition(b->position());
setTextCursor(c);
ensureCursorVisible();
}
}
m_parent->updateLineNumbers(0);
// the 2 can be changed according to preferences later
// just be sure to also change the fading factors in paintEvent.
m_program->getLastXInstructions(Options::noPreviousXInstructions(), m_lastInstructions);
viewport()->update();
}
示例12: previousBlockState
int ExpressionUnderCursor::previousBlockState(const QTextBlock &block)
{
const QTextBlock prevBlock = block.previous();
if (prevBlock.isValid()) {
int state = prevBlock.userState();
if (state != -1)
return state;
}
return 0;
}
示例13: bottomLineStartsInMultilineComment
/*
Returns true if the start of the bottom line of yyProgram (and
potentially the whole line) is part of a C-style comment;
otherwise returns false.
*/
bool LineInfo::bottomLineStartsInMultilineComment()
{
QTextBlock currentLine = yyProgram.lastBlock().previous();
QTextBlock previousLine = currentLine.previous();
int startState = qMax(0, previousLine.userState()) & 0xff;
if (startState > 0)
return true;
return false;
}
示例14: parse
/**
* Parses a text document and builds the navigation tree for it
*/
void NavigationWidget::parse(QTextDocument *document) {
const QSignalBlocker blocker(this);
Q_UNUSED(blocker);
setDocument(document);
clear();
_lastHeadingItemList.clear();
for (int i = 0; i < document->blockCount(); i++) {
QTextBlock block = document->findBlockByNumber(i);
int elementType = block.userState();
// ignore all non headline types
if ((elementType < pmh_H1) || (elementType > pmh_H6)) {
continue;
}
QString text = block.text();
text.remove(QRegularExpression("^#+"))
.remove(QRegularExpression("#+$"))
.remove(QRegularExpression("^\\s+"))
.remove(QRegularExpression("^=+$"))
.remove(QRegularExpression("^-+$"));
if (text.isEmpty()) {
continue;
}
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0, text);
item->setData(0, Qt::UserRole, block.position());
item->setToolTip(0, tr("headline %1").arg(elementType - pmh_H1 + 1));
// attempt to find a suitable parent item for the element type
QTreeWidgetItem *lastHigherItem = findSuitableParentItem(elementType);
if (lastHigherItem == NULL) {
// if there wasn't a last higher level item then add the current
// item to the top level
addTopLevelItem(item);
} else {
// if there was a last higher level item then add the current
// item as child of that item
lastHigherItem->addChild(item);
}
_lastHeadingItemList[elementType] = item;
}
expandAll();
}
示例15: previousBlockState
int BackwardsScanner::previousBlockState(const QTextBlock &block)
{
const QTextBlock prevBlock = block.previous();
if (prevBlock.isValid()) {
int state = prevBlock.userState();
if (state != -1)
return state;
}
return 0;
}