From 19db6c98267d6afd4e27d727d5582541947ec43b Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Mon, 5 Jul 2010 12:56:37 +0200 Subject: 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. --- src/plugins/cpptools/cppcodeformatter.h | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/plugins/cpptools/cppcodeformatter.h') diff --git a/src/plugins/cpptools/cppcodeformatter.h b/src/plugins/cpptools/cppcodeformatter.h index 75a9c31095..72d1fe095e 100644 --- a/src/plugins/cpptools/cppcodeformatter.h +++ b/src/plugins/cpptools/cppcodeformatter.h @@ -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 &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 initialState(); - QPointer m_document; - QStack m_beginState; QStack m_currentState; + QStack m_newStates; QList 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 -- cgit v1.2.1