|
| 1 | +# Qt-style clang-format |
| 2 | +# Based on Qt coding style with slight modern C++ friendliness |
| 3 | + |
| 4 | +BasedOnStyle: LLVM |
| 5 | + |
| 6 | +Language: Cpp |
| 7 | +Standard: c++20 |
| 8 | + |
| 9 | +# ========================= |
| 10 | +# 缩进 & 基础排版 |
| 11 | +# ========================= |
| 12 | +IndentWidth: 4 |
| 13 | +TabWidth: 4 |
| 14 | +UseTab: Never |
| 15 | + |
| 16 | +ContinuationIndentWidth: 8 |
| 17 | +IndentCaseLabels: true |
| 18 | +IndentCaseBlocks: false |
| 19 | +IndentGotoLabels: false |
| 20 | + |
| 21 | +AccessModifierOffset: -4 |
| 22 | + |
| 23 | +# ========================= |
| 24 | +# 大括号风格(Qt 风格) |
| 25 | +# ========================= |
| 26 | +BreakBeforeBraces: Custom |
| 27 | +BraceWrapping: |
| 28 | + AfterClass: true |
| 29 | + AfterStruct: true |
| 30 | + AfterUnion: true |
| 31 | + AfterEnum: true |
| 32 | + AfterFunction: true |
| 33 | + AfterNamespace: true |
| 34 | + AfterControlStatement: false |
| 35 | + BeforeElse: true |
| 36 | + BeforeCatch: true |
| 37 | + IndentBraces: false |
| 38 | + |
| 39 | +# ========================= |
| 40 | +# 行宽 & 自动换行 |
| 41 | +# ========================= |
| 42 | +ColumnLimit: 100 |
| 43 | +AllowAllArgumentsOnNextLine: false |
| 44 | +AllowAllParametersOfDeclarationOnNextLine: false |
| 45 | +BinPackArguments: false |
| 46 | +BinPackParameters: false |
| 47 | + |
| 48 | +PenaltyBreakBeforeFirstCallParameter: 1 |
| 49 | + |
| 50 | +# ========================= |
| 51 | +# 指针 & 引用(Qt 习惯) |
| 52 | +# ========================= |
| 53 | +PointerAlignment: Right |
| 54 | +ReferenceAlignment: Right |
| 55 | +DerivePointerAlignment: false |
| 56 | + |
| 57 | +# ========================= |
| 58 | +# 空格规则 |
| 59 | +# ========================= |
| 60 | +SpaceBeforeParens: ControlStatements |
| 61 | +SpaceBeforeAssignmentOperators: true |
| 62 | +SpaceAfterCStyleCast: true |
| 63 | +SpaceBeforeRangeBasedForLoopColon: true |
| 64 | + |
| 65 | +SpacesInAngles: false |
| 66 | +SpacesInParentheses: false |
| 67 | +SpacesInSquareBrackets: false |
| 68 | +SpacesInCStyleCastParentheses: false |
| 69 | + |
| 70 | +# ========================= |
| 71 | +# if / for / while 格式 |
| 72 | +# ========================= |
| 73 | +AllowShortIfStatementsOnASingleLine: Never |
| 74 | +AllowShortLoopsOnASingleLine: false |
| 75 | +AllowShortFunctionsOnASingleLine: Inline |
| 76 | + |
| 77 | + |
| 78 | +# ========================= |
| 79 | +# include 排序(Qt 项目常用) |
| 80 | +# ========================= |
| 81 | +SortIncludes: true |
| 82 | +IncludeBlocks: Regroup |
| 83 | +IncludeCategories: |
| 84 | + - Regex: '^<Qt.*>' |
| 85 | + Priority: 1 |
| 86 | + - Regex: '^<Q.*>' |
| 87 | + Priority: 2 |
| 88 | + - Regex: '^<.*>' |
| 89 | + Priority: 3 |
| 90 | + - Regex: '^".*"' |
| 91 | + Priority: 4 |
| 92 | + |
| 93 | +# ========================= |
| 94 | +# 命名空间 |
| 95 | +# ========================= |
| 96 | +NamespaceIndentation: All |
| 97 | +CompactNamespaces: false |
| 98 | + |
| 99 | +# ========================= |
| 100 | +# 注释 |
| 101 | +# ========================= |
| 102 | +AlignTrailingComments: true |
| 103 | +ReflowComments: true |
| 104 | +KeepEmptyLinesAtTheStartOfBlocks: false |
| 105 | + |
| 106 | +# ========================= |
| 107 | +# 其他 Qt / 工程实践 |
| 108 | +# ========================= |
| 109 | +InsertTrailingCommas: Wrapped |
| 110 | +Cpp11BracedListStyle: true |
| 111 | +FixNamespaceComments: true |
0 commit comments