summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcodeformatter.h
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-07-05 12:56:37 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2010-07-05 13:49:12 +0200
commit19db6c98267d6afd4e27d727d5582541947ec43b (patch)
treedb7dea90189f53a63968f8cbc7064ea255978611 /src/plugins/cpptools/cppcodeformatter.h
parent3100fc0b7edc7670ac9a95a2715b80a6d4a3be21 (diff)
downloadqt-creator-19db6c98267d6afd4e27d727d5582541947ec43b.tar.gz
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.
Diffstat (limited to 'src/plugins/cpptools/cppcodeformatter.h')
-rw-r--r--src/plugins/cpptools/cppcodeformatter.h29
1 files changed, 14 insertions, 15 deletions
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<State> &newStatesThisLine() const;
int tokenIndex() const;
- int tokenIndexFromEnd() const;
+ int tokenCount() const;
const CPlusPlus::Token &currentToken() 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