forked from qt-creator/qt-creator
		
	C++ indenter: Add more functions to manage the indenter state.
This commit is contained in:
		@@ -455,6 +455,8 @@ void CodeFormatter::updateStateUntil(const QTextBlock &endBlock)
 | 
			
		||||
{
 | 
			
		||||
    QStack<State> previousState = initialState();
 | 
			
		||||
    QTextBlock it = endBlock.document()->firstBlock();
 | 
			
		||||
 | 
			
		||||
    // find the first block that needs recalculation
 | 
			
		||||
    for (; it.isValid() && it != endBlock; it = it.next()) {
 | 
			
		||||
        TextBlockUserData *userData = BaseTextDocumentLayout::userData(it);
 | 
			
		||||
        CppCodeFormatterData *cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData());
 | 
			
		||||
@@ -469,10 +471,47 @@ void CodeFormatter::updateStateUntil(const QTextBlock &endBlock)
 | 
			
		||||
 | 
			
		||||
        previousState = cppData->m_endState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (it == endBlock)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    // update everthing until endBlock
 | 
			
		||||
    for (; it.isValid() && it != endBlock; it = it.next()) {
 | 
			
		||||
        //qDebug() << "recalc line" << it.blockNumber() + 1;
 | 
			
		||||
        recalculateStateAfter(it);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // invalidate everything below by marking the state in endBlock as invalid
 | 
			
		||||
    TextBlockUserData *userData = BaseTextDocumentLayout::userData(endBlock);
 | 
			
		||||
    CppCodeFormatterData *cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData());
 | 
			
		||||
    if (cppData)
 | 
			
		||||
        cppData->setBlockRevision(-1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CodeFormatter::updateLineStateChange(const QTextBlock &block)
 | 
			
		||||
{
 | 
			
		||||
    if (!block.isValid())
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    QStack<State> oldEndState;
 | 
			
		||||
 | 
			
		||||
    TextBlockUserData *userData = BaseTextDocumentLayout::userData(block);
 | 
			
		||||
    CppCodeFormatterData *cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData());
 | 
			
		||||
    if (cppData)
 | 
			
		||||
        oldEndState = cppData->m_endState;
 | 
			
		||||
 | 
			
		||||
    recalculateStateAfter(block);
 | 
			
		||||
 | 
			
		||||
    if (oldEndState.isEmpty() || oldEndState != cppData->m_endState) {
 | 
			
		||||
        // invalidate everything below by marking the next block's state as invalid
 | 
			
		||||
        QTextBlock next = block.next();
 | 
			
		||||
        if (!next.isValid())
 | 
			
		||||
            return;
 | 
			
		||||
 | 
			
		||||
        userData = BaseTextDocumentLayout::userData(next);
 | 
			
		||||
        cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData());
 | 
			
		||||
        if (cppData)
 | 
			
		||||
            cppData->setBlockRevision(-1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CodeFormatter::State CodeFormatter::state(int belowTop) const
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,13 @@ public:
 | 
			
		||||
    CodeFormatter();
 | 
			
		||||
    virtual ~CodeFormatter();
 | 
			
		||||
 | 
			
		||||
    // updates all states up until block if necessary
 | 
			
		||||
    // it is safe to call indentFor on block afterwards
 | 
			
		||||
    void updateStateUntil(const QTextBlock &block);
 | 
			
		||||
 | 
			
		||||
    // calculates the state change introduced by changing a single line
 | 
			
		||||
    void updateLineStateChange(const QTextBlock &block);
 | 
			
		||||
 | 
			
		||||
    int indentFor(const QTextBlock &block);
 | 
			
		||||
 | 
			
		||||
    void setTabSize(int tabSize);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user