From cd5afa376f4a11e373ad11fce8815a5656857dc9 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sat, 15 Nov 2025 01:22:32 +0300 Subject: [PATCH 1/4] Add clang-format configuration --- .clang-format | 174 ++++++++++++++++++++++++++++++++++++++++++++ run-clang-format.sh | 27 +++++++ 2 files changed, 201 insertions(+) create mode 100644 .clang-format create mode 100755 run-clang-format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..57f97e965 --- /dev/null +++ b/.clang-format @@ -0,0 +1,174 @@ +Language: Cpp +IndentWidth: 2 +UseTab: Never +ColumnLimit: 120 +SortIncludes: false +AccessModifierOffset: -2 +ReflowComments: false +ConstructorInitializerIndentWidth: 2 +ContinuationIndentWidth: 2 +AllowShortFunctionsOnASingleLine: None +BreakBeforeBraces: Custom +BraceWrapping: + AfterExternBlock: true + AfterClass: true + AfterFunction: true + AfterNamespace: false + AfterEnum: false + AfterCaseLabel: false + AfterControlStatement: Never + AfterStruct: false + AfterUnion: false + BeforeLambdaBody: false + BeforeElse: false + BeforeCatch: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: false + SplitEmptyNamespace: true +PPIndentWidth: 2 +FixNamespaceComments: false +# ?????? +IndentPPDirectives: BeforeHash +SpaceBeforeParens: Custom +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +# ?? +#SpacesBeforeTrailingComments: -1 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +IndentCaseBlocks: false +IndentCaseLabels: false +AlignAfterOpenBracket: DontAlign +BreakConstructorInitializers: BeforeComma +AlwaysBreakTemplateDeclarations: true +NamespaceIndentation: None +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: true + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignEscapedNewlines: DontAlign +AlignOperands: Align +AlignTrailingComments: false +# ?? +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: true +# AllowShortIfStatementsOnASingleLine: Nevers +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: After +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeConceptDeclarations: Always +BreakBeforeTernaryOperators: true +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +CompactNamespaces: false +Cpp11BracedListStyle: true +PointerAlignment: Right +QualifierAlignment: Leave +ReferenceAlignment: Pointer +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Leave +MaxEmptyLinesToKeep: 1 +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +Macros: + - >- + PyObject_HEAD_INIT(type)={ + { 0xFFFFFFFF }, + (type) + }, + - >- + PyVarObject_HEAD_INIT(type, size)={ + { + { 0xFFFFFFFF }, + (type) + }, + (size) + }, +ForEachMacros: + - foreach + - Q_FOREACH +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION + - Q_OBJECT + - PyObject_HEAD +IndentAccessModifiers: false +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentRequiresClause: true +IndentWrappedFunctionNames: false +InsertBraces: false +InsertTrailingCommas: None +KeepEmptyLinesAtTheStartOfBlocks: true +# ??? +LambdaBodyIndentation: OuterScope +PackConstructorInitializers: BinPack +RemoveBracesLLVM: false +RequiresClausePosition: OwnLine +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortUsingDeclarations: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Latest diff --git a/run-clang-format.sh b/run-clang-format.sh new file mode 100755 index 000000000..4b41b19dc --- /dev/null +++ b/run-clang-format.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -xeuo pipefail +which -a clang-format-20 > /dev/null \ + || (echo -e "20.0.0\n$(clang-format${1+-$1} --version | grep -Eo '([0-9]+\.[0-9]+\.[0-9]+)')" | sort -CV ) \ + || { echo "use '${0} ' to call exact proper version" ; exit 1 ; } + +IGNORED_DIRS=( + "./generated_cpp_50" + "./generated_cpp_511" + "./generated_cpp_515" + "./generated_cpp_53" + "./generated_cpp_54" + "./generated_cpp_56" + "./examples" + "./generator/simplecpp" + "./build" +) + +IGNORE_CMD="" + +for DIR in "${IGNORED_DIRS[@]}"; do + IGNORE_CMD+=" -path $DIR -o" +done + +IGNORE_CMD=${IGNORE_CMD% -o} + +find . \( $IGNORE_CMD \) -prune -o -name '*.cpp' -print0 -o -name '*.h' -print0 | xargs -0 clang-format-20 --style=file -i From 6cd6596e33c822ff42683360c9c10cdc31b09862 Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Sun, 16 Nov 2025 04:57:12 +0300 Subject: [PATCH 2/4] Fix some issues --- .clang-format | 5 ++--- run-clang-format.sh | 5 ----- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.clang-format b/.clang-format index 57f97e965..7347d5acb 100644 --- a/.clang-format +++ b/.clang-format @@ -55,8 +55,7 @@ SpaceBeforeRangeBasedForLoopColon: true SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false SpaceInEmptyParentheses: false -# ?? -#SpacesBeforeTrailingComments: -1 +SpacesBeforeTrailingComments: 1 SpacesInAngles: Never SpacesInConditionalStatement: false SpacesInContainerLiterals: true @@ -120,7 +119,7 @@ BreakInheritanceList: BeforeColon BreakStringLiterals: true CompactNamespaces: false Cpp11BracedListStyle: true -PointerAlignment: Right +PointerAlignment: Left QualifierAlignment: Leave ReferenceAlignment: Pointer DerivePointerAlignment: false diff --git a/run-clang-format.sh b/run-clang-format.sh index 4b41b19dc..45e914b98 100755 --- a/run-clang-format.sh +++ b/run-clang-format.sh @@ -5,12 +5,7 @@ which -a clang-format-20 > /dev/null \ || { echo "use '${0} ' to call exact proper version" ; exit 1 ; } IGNORED_DIRS=( - "./generated_cpp_50" - "./generated_cpp_511" "./generated_cpp_515" - "./generated_cpp_53" - "./generated_cpp_54" - "./generated_cpp_56" "./examples" "./generator/simplecpp" "./build" From 74ea9718fd242908757cbfbb483af6fc0a6aa27f Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Mon, 17 Nov 2025 22:44:41 +0300 Subject: [PATCH 3/4] Add comments to Python structures to avoid wrapping on a single line when formatting with clang-format --- src/PythonQt.cpp | 18 +++++++++--------- src/PythonQtBoolResult.cpp | 10 +++++----- src/PythonQtClassWrapper.cpp | 2 +- src/PythonQtImporter.cpp | 8 ++++---- src/PythonQtInstanceWrapper.cpp | 2 +- src/PythonQtProperty.cpp | 2 +- src/PythonQtSignal.cpp | 8 ++++---- src/PythonQtSlot.cpp | 8 ++++---- src/PythonQtSlotDecorator.cpp | 2 +- src/PythonQtStdIn.cpp | 2 +- src/PythonQtStdOut.cpp | 2 +- 11 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index e5c4a93a6..c75b92c41 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -1819,15 +1819,15 @@ static PyMethodDef PythonQtMethods[] = { }; static PyModuleDef PythonQtModuleDef = { - PyModuleDef_HEAD_INIT, - "", - nullptr, - -1, - PythonQtMethods, - nullptr, - nullptr, - nullptr, - nullptr + PyModuleDef_HEAD_INIT, /* m_base */ + "", /* m_name */ + nullptr, /* m_doc */ + -1, /* m_size */ + PythonQtMethods, /* m_methods */ + nullptr, /* m_slots */ + nullptr, /* m_traverse */ + nullptr, /* m_clear */ + nullptr /* m_free */ }; void PythonQt::initPythonQtModule(bool redirectStdOut, const QByteArray& pythonQtModuleName) diff --git a/src/PythonQtBoolResult.cpp b/src/PythonQtBoolResult.cpp index 09051b169..09d685a64 100644 --- a/src/PythonQtBoolResult.cpp +++ b/src/PythonQtBoolResult.cpp @@ -103,15 +103,15 @@ static PyNumberMethods PythonQtBoolResult_as_number = { }; PyTypeObject PythonQtBoolResult_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "BoolResult", - sizeof(PythonQtBoolResultObject), - 0, + PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/ + "BoolResult", /* tp_name */ + sizeof(PythonQtBoolResultObject), /* tp_basicsize */ + 0, /* tp_itemsize */ nullptr, /* tp_dealloc */ 0, /* tp_vectorcall_offset */ nullptr, /* tp_getattr */ nullptr, /* tp_setattr */ - nullptr, + nullptr, /* tp_as_async */ (reprfunc)PythonQtBoolResult_repr, /* tp_repr */ &PythonQtBoolResult_as_number, /* tp_as_number */ nullptr, /* tp_as_sequence */ diff --git a/src/PythonQtClassWrapper.cpp b/src/PythonQtClassWrapper.cpp index 8b659d696..c5ffde6e4 100644 --- a/src/PythonQtClassWrapper.cpp +++ b/src/PythonQtClassWrapper.cpp @@ -594,7 +594,7 @@ static PyObject * PythonQtClassWrapper_repr(PyObject * obj) */ PyTypeObject PythonQtClassWrapper_Type = { - PyVarObject_HEAD_INIT(nullptr, 0) + PyVarObject_HEAD_INIT(nullptr, 0) /*tp_base*/ "PythonQt.PythonQtClassWrapper", /*tp_name*/ sizeof(PythonQtClassWrapper), /*tp_basicsize*/ 0, /*tp_itemsize*/ diff --git a/src/PythonQtImporter.cpp b/src/PythonQtImporter.cpp index 56d468807..4ef17937a 100644 --- a/src/PythonQtImporter.cpp +++ b/src/PythonQtImporter.cpp @@ -495,9 +495,9 @@ Create a new PythonQtImporter instance. 'path' must be a valid path on disk/or i #define DEFERRED_ADDRESS(ADDR) nullptr PyTypeObject PythonQtImporter_Type = { - PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) - "PythonQtImport.PythonQtImporter", - sizeof(PythonQtImporter), + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) /*tp_base*/ + "PythonQtImport.PythonQtImporter", /* tp_name */ + sizeof(PythonQtImporter), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)PythonQtImporter_dealloc, /* tp_dealloc */ 0, /* tp_vectorcall_offset */ @@ -878,7 +878,7 @@ PyDoc_STRVAR(mlabimport_doc, "Imports python files into PythonQt, completely replaces internal python import"); static struct PyModuleDef PythonQtImport_def = { - PyModuleDef_HEAD_INIT, + PyModuleDef_HEAD_INIT, /* m_base */ "PythonQtImport", /* m_name */ mlabimport_doc, /* m_doc */ -1, /* m_size */ diff --git a/src/PythonQtInstanceWrapper.cpp b/src/PythonQtInstanceWrapper.cpp index 480ff9962..639333808 100644 --- a/src/PythonQtInstanceWrapper.cpp +++ b/src/PythonQtInstanceWrapper.cpp @@ -903,7 +903,7 @@ static PyNumberMethods PythonQtInstanceWrapper_as_number = { }; PyTypeObject PythonQtInstanceWrapper_Type = { - PyVarObject_HEAD_INIT(&PythonQtClassWrapper_Type, 0) + PyVarObject_HEAD_INIT(&PythonQtClassWrapper_Type, 0) /*tp_base*/ "PythonQt.PythonQtInstanceWrapper", /*tp_name*/ sizeof(PythonQtInstanceWrapper), /*tp_basicsize*/ 0, /*tp_itemsize*/ diff --git a/src/PythonQtProperty.cpp b/src/PythonQtProperty.cpp index 9b036070b..6c3ea198b 100644 --- a/src/PythonQtProperty.cpp +++ b/src/PythonQtProperty.cpp @@ -194,7 +194,7 @@ PyDoc_STRVAR(PythonQtProperty_doc, " constant=False, final=False, notify=None) -> Property\n"); PyTypeObject PythonQtProperty_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/ "PythonQt.QtCore.Property", /*tp_name*/ sizeof(PythonQtProperty), /*tp_basicsize*/ 0, /*tp_itemsize*/ diff --git a/src/PythonQtSignal.cpp b/src/PythonQtSignal.cpp index 554f25277..7b9bba135 100644 --- a/src/PythonQtSignal.cpp +++ b/src/PythonQtSignal.cpp @@ -394,10 +394,10 @@ PyDoc_STRVAR(PythonQtSignalFunction_doc, "Signal(*types) -> Signal\n"); PyTypeObject PythonQtSignalFunction_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "QtCore.Signal", - sizeof(PythonQtSignalFunctionObject), - 0, + PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/ + "QtCore.Signal", /* tp_name */ + sizeof(PythonQtSignalFunctionObject), /* tp_basicsize */ + 0, /* tp_itemsize */ (destructor)meth_dealloc, /* tp_dealloc */ 0, /* tp_vectorcall_offset */ nullptr, /* tp_getattr */ diff --git a/src/PythonQtSlot.cpp b/src/PythonQtSlot.cpp index d3ea52810..37ca34af7 100644 --- a/src/PythonQtSlot.cpp +++ b/src/PythonQtSlot.cpp @@ -813,10 +813,10 @@ meth_descr_get(PyObject *descr, PyObject *obj, PyObject* type) } PyTypeObject PythonQtSlotFunction_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "builtin_qt_slot", - sizeof(PythonQtSlotFunctionObject), - 0, + PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/ + "builtin_qt_slot", /* tp_itemsize */ + sizeof(PythonQtSlotFunctionObject), /* tp_basicsize */ + 0, /* tp_itemsize */ (destructor)meth_dealloc, /* tp_dealloc */ 0, /* tp_vectorcall_offset */ nullptr, /* tp_getattr */ diff --git a/src/PythonQtSlotDecorator.cpp b/src/PythonQtSlotDecorator.cpp index 96771bf3e..9cdf57f9f 100644 --- a/src/PythonQtSlotDecorator.cpp +++ b/src/PythonQtSlotDecorator.cpp @@ -127,7 +127,7 @@ PyDoc_STRVAR(PythonQtSlotDecorator_doc, "Slot(*types, result=type) -> Slot\n"); PyTypeObject PythonQtSlotDecorator_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(&PyType_Type, 0) /*tp_base*/ "PythonQt.QtCore.Slot", /*tp_name*/ sizeof(PythonQtSlotDecorator), /*tp_basicsize*/ 0, /*tp_itemsize*/ diff --git a/src/PythonQtStdIn.cpp b/src/PythonQtStdIn.cpp index 056127b28..ae881990b 100644 --- a/src/PythonQtStdIn.cpp +++ b/src/PythonQtStdIn.cpp @@ -86,7 +86,7 @@ static PyMemberDef PythonQtStdInRedirect_members[] = { }; PyTypeObject PythonQtStdInRedirectType = { - PyVarObject_HEAD_INIT(nullptr, 0) + PyVarObject_HEAD_INIT(nullptr, 0) /*tp_base*/ "PythonQtStdInRedirect", /*tp_name*/ sizeof(PythonQtStdInRedirect), /*tp_basicsize*/ 0, /*tp_itemsize*/ diff --git a/src/PythonQtStdOut.cpp b/src/PythonQtStdOut.cpp index 4d332a0c8..181510b92 100644 --- a/src/PythonQtStdOut.cpp +++ b/src/PythonQtStdOut.cpp @@ -114,7 +114,7 @@ static PyMemberDef PythonQtStdOutRedirect_members[] = { }; PyTypeObject PythonQtStdOutRedirectType = { - PyVarObject_HEAD_INIT(nullptr, 0) + PyVarObject_HEAD_INIT(nullptr, 0) /*tp_base*/ "PythonQtStdOutRedirect", /*tp_name*/ sizeof(PythonQtStdOutRedirect), /*tp_basicsize*/ 0, /*tp_itemsize*/ From 067c385e8d0e9728934c76002807e4039d491efd Mon Sep 17 00:00:00 2001 From: MinyazevR Date: Mon, 17 Nov 2025 23:27:25 +0300 Subject: [PATCH 4/4] Consider all the requirements for code formatting --- .clang-format | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/.clang-format b/.clang-format index 7347d5acb..c8a92dc59 100644 --- a/.clang-format +++ b/.clang-format @@ -7,7 +7,7 @@ AccessModifierOffset: -2 ReflowComments: false ConstructorInitializerIndentWidth: 2 ContinuationIndentWidth: 2 -AllowShortFunctionsOnASingleLine: None +AllowShortFunctionsOnASingleLine: Inline BreakBeforeBraces: Custom BraceWrapping: AfterExternBlock: true @@ -15,8 +15,8 @@ BraceWrapping: AfterFunction: true AfterNamespace: false AfterEnum: false - AfterCaseLabel: false - AfterControlStatement: Never + AfterCaseLabel: true + AfterControlStatement: MultiLine AfterStruct: false AfterUnion: false BeforeLambdaBody: false @@ -29,7 +29,6 @@ BraceWrapping: SplitEmptyNamespace: true PPIndentWidth: 2 FixNamespaceComments: false -# ?????? IndentPPDirectives: BeforeHash SpaceBeforeParens: Custom SpaceBeforeParensOptions: @@ -96,14 +95,13 @@ AlignConsecutiveMacros: PadOperators: false AlignEscapedNewlines: DontAlign AlignOperands: Align -AlignTrailingComments: false -# ?? +AlignTrailingComments: true AllowAllArgumentsOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: Empty AllowShortCaseLabelsOnASingleLine: false AllowShortEnumsOnASingleLine: true -# AllowShortIfStatementsOnASingleLine: Nevers +AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: All AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None @@ -128,20 +126,6 @@ EmptyLineAfterAccessModifier: Leave MaxEmptyLinesToKeep: 1 EmptyLineBeforeAccessModifier: LogicalBlock ExperimentalAutoDetectBinPacking: false -Macros: - - >- - PyObject_HEAD_INIT(type)={ - { 0xFFFFFFFF }, - (type) - }, - - >- - PyVarObject_HEAD_INIT(type, size)={ - { - { 0xFFFFFFFF }, - (type) - }, - (size) - }, ForEachMacros: - foreach - Q_FOREACH @@ -160,7 +144,6 @@ IndentWrappedFunctionNames: false InsertBraces: false InsertTrailingCommas: None KeepEmptyLinesAtTheStartOfBlocks: true -# ??? LambdaBodyIndentation: OuterScope PackConstructorInitializers: BinPack RemoveBracesLLVM: false