aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Sokolovskii <artem.sokolovskii@qt.io>2023-05-08 11:39:33 +0200
committerArtem Sokolovskii <artem.sokolovskii@qt.io>2023-05-12 07:49:35 +0000
commitef06d8925578a43c9c45832b38839755d5e59a7d (patch)
tree277b77577ada0568297cadbe20537773d95cc679
parent979f938aa5003d52b4e0ff275180219c1c82b9e3 (diff)
ClangFormat: Improve conversion from and to ClangFormat style
Improved conversion from ClangFormat style settings to CppCode style settings and the other way around. Task-number: QTCREATORBUG-29069 Change-Id: If4f75259f7fe77397fc144a83370749a49d25297 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--src/plugins/clangformat/clangformatfile.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/plugins/clangformat/clangformatfile.cpp b/src/plugins/clangformat/clangformatfile.cpp
index 7023645cc8..f0c4809913 100644
--- a/src/plugins/clangformat/clangformatfile.cpp
+++ b/src/plugins/clangformat/clangformatfile.cpp
@@ -169,6 +169,12 @@ CppEditor::CppCodeStyleSettings ClangFormatFile::toCppCodeStyleSettings(
settings.bindStarToRightSpecifier = style.PointerAlignment == FormatStyle::PAS_Right;
}
+ settings.extraPaddingForConditionsIfConfusingAlign = style.BreakBeforeBinaryOperators
+ == FormatStyle::BOS_All;
+ settings.alignAssignments = style.BreakBeforeBinaryOperators == FormatStyle::BOS_All
+ || style.BreakBeforeBinaryOperators
+ == FormatStyle::BOS_NonAssignment;
+
return settings;
}
@@ -188,6 +194,9 @@ void ClangFormatFile::fromCppCodeStyleSettings(const CppEditor::CppCodeStyleSett
if (settings.indentClassBraces || settings.indentEnumBraces || settings.indentBlockBraces
|| settings.indentFunctionBraces)
m_style.BreakBeforeBraces = FormatStyle::BS_Whitesmiths;
+ else
+ m_style.BreakBeforeBraces = FormatStyle::BS_Custom;
+
m_style.IndentCaseLabels = settings.indentSwitchLabels;
#if LLVM_VERSION_MAJOR >= 11
@@ -196,11 +205,12 @@ void ClangFormatFile::fromCppCodeStyleSettings(const CppEditor::CppCodeStyleSett
|| settings.indentControlFlowRelativeToSwitchLabels;
#endif
- if (settings.alignAssignments)
- m_style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
-
if (settings.extraPaddingForConditionsIfConfusingAlign)
m_style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
+ else if (settings.alignAssignments)
+ m_style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
+ else
+ m_style.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
m_style.DerivePointerAlignment = settings.bindStarToIdentifier || settings.bindStarToTypeName
|| settings.bindStarToLeftSpecifier