forked from qt-creator/qt-creator
		
	C++ indenter: Make building custom styles easier, fix style issues.
Keep more information by using enter() instead of turnInto() when moving from a *_start to *_open.
This commit is contained in:
		@@ -28,9 +28,8 @@ public:
 | 
			
		||||
    CodeFormatter();
 | 
			
		||||
    virtual ~CodeFormatter();
 | 
			
		||||
 | 
			
		||||
    void setDocument(QTextDocument *document);
 | 
			
		||||
 | 
			
		||||
    int indentFor(const QTextBlock &block);
 | 
			
		||||
    void invalidateCache(QTextDocument *document);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    virtual void onEnter(int newState, int *indentDepth, int *savedIndentDepth) const = 0;
 | 
			
		||||
@@ -58,7 +57,8 @@ protected:
 | 
			
		||||
        member_init_open, // After ':' that starts a member initialization list.
 | 
			
		||||
 | 
			
		||||
        enum_start, // After 'enum'
 | 
			
		||||
        brace_list_open, // Open brace of an enum or static array list.
 | 
			
		||||
        enum_open, // Brace that opens a enum declaration.
 | 
			
		||||
        brace_list_open, // Open brace nested inside an enum or for a static array list.
 | 
			
		||||
 | 
			
		||||
        namespace_start, // after the namespace token, before the opening brace.
 | 
			
		||||
        namespace_open, // Brace that opens a C++ namespace block.
 | 
			
		||||
@@ -125,15 +125,14 @@ protected:
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    State state(int belowTop = 0) const;
 | 
			
		||||
    const QVector<State> &newStatesThisLine() const;
 | 
			
		||||
    int tokenIndex() const;
 | 
			
		||||
    int tokenIndexFromEnd() const;
 | 
			
		||||
    int tokenCount() const;
 | 
			
		||||
    const CPlusPlus::Token ¤tToken() const;
 | 
			
		||||
    const CPlusPlus::Token &tokenAt(int idx) const;
 | 
			
		||||
 | 
			
		||||
    bool isBracelessState(int type) const;
 | 
			
		||||
 | 
			
		||||
    void invalidateCache();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void requireStatesUntil(const QTextBlock &block);
 | 
			
		||||
    void recalculateStateAfter(const QTextBlock &block);
 | 
			
		||||
@@ -159,10 +158,9 @@ private:
 | 
			
		||||
private:
 | 
			
		||||
    static QStack<State> initialState();
 | 
			
		||||
 | 
			
		||||
    QPointer<QTextDocument> m_document;
 | 
			
		||||
 | 
			
		||||
    QStack<State> m_beginState;
 | 
			
		||||
    QStack<State> m_currentState;
 | 
			
		||||
    QStack<State> m_newStates;
 | 
			
		||||
 | 
			
		||||
    QList<CPlusPlus::Token> m_tokens;
 | 
			
		||||
    QString m_currentLine;
 | 
			
		||||
@@ -182,12 +180,10 @@ public:
 | 
			
		||||
 | 
			
		||||
    void setIndentSize(int size);
 | 
			
		||||
 | 
			
		||||
    enum CompoundStyle {
 | 
			
		||||
        QtStyle, // don't indent braces, add indent for contained statements
 | 
			
		||||
        WhitesmithsStyle, // add indent for braces, don't for the contained statements
 | 
			
		||||
        GnuStyle // add indent for braces and again for contained statements
 | 
			
		||||
    };
 | 
			
		||||
    void setCompoundStyle(CompoundStyle style);
 | 
			
		||||
    void setIndentSubstatementBraces(bool onOff);
 | 
			
		||||
    void setIndentSubstatementStatements(bool onOff);
 | 
			
		||||
    void setIndentDeclarationBraces(bool onOff);
 | 
			
		||||
    void setIndentDeclarationMembers(bool onOff);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    virtual void onEnter(int newState, int *indentDepth, int *savedIndentDepth) const;
 | 
			
		||||
@@ -195,7 +191,10 @@ protected:
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    int m_indentSize;
 | 
			
		||||
    CompoundStyle m_style;
 | 
			
		||||
    bool m_indentSubstatementBraces;
 | 
			
		||||
    bool m_indentSubstatementStatements;
 | 
			
		||||
    bool m_indentDeclarationBraces;
 | 
			
		||||
    bool m_indentDeclarationMembers;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace CppTools
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user