Doc: Describe changes to ClangFormat preferences

Task-number: QTCREATORBUG-30209
Change-Id: Iff7587cca92c016f2f6ff5f40150d620f623a9b2
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io>
This commit is contained in:
Leena Miettinen
2024-02-06 19:02:24 +01:00
parent 0d40cc5093
commit 8869fefb72
11 changed files with 56 additions and 64 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2023 The Qt Company Ltd. // Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*! /*!
@@ -18,30 +18,39 @@
To specify global indentation settings for the C++ editor: To specify global indentation settings for the C++ editor:
\list 1 \list 1
\li Select \preferences > \uicontrol {C++}. \li Go to \preferences > \uicontrol {C++}.
\image qtcreator-code-style-clang-format-global.webp {Code Style preferences} \image qtcreator-code-style-clang-format-global.webp {Code Style preferences}
\li In \uicontrol {Formatting mode}, select: \li In \uicontrol {Formatting mode}, select:
\list \list
\li \uicontrol {Indenting Only} to only indent code. \li \uicontrol {Indenting Only} to only indent code.
\li \uicontrol {Full Formatting} to use the \key {Ctrl+I} \li \uicontrol {Full Formatting} to use the \key {Ctrl+I}
keyboard shortcut to format code instead of indenting. keyboard shortcut to format code instead of indenting.
\li \uicontrol Disable to turn off ClangFormat. \li \uicontrol {Use Built-In Indenter} to turn off ClangFormat.
\endlist \endlist
\li Select \uicontrol {Ignore files greater than} to make parsing faster
by ignoring big files. Specify the maximum size of files to parse.
\li To apply the formatting while you type, select \li To apply the formatting while you type, select
\uicontrol {Format while typing}. \uicontrol {Format while typing}.
\li To apply the formatting to the edited code when you save the file, \li To apply the formatting to the edited code when you save the file,
select \uicontrol {Format edited code on file save}. select \uicontrol {Format edited code on file save}.
\li To change the ClangFormat style globally for all projects, \li To change the ClangFormat style globally for all projects,
select \uicontrol {Override ClangFormat configuration file}. select \uicontrol {Use custom settings}.
\li In the \uicontrol {Current settings} field, select the settings to \li In \uicontrol {Custom settings}, select the settings to change, and
modify and click \uicontrol Copy. then select \uicontrol Copy.
\li Give a name to the settings and click \uicontrol OK. \li Give a name to the settings, and select \uicontrol OK.
\li Click \uicontrol Edit to set \li In \uicontrol ClangFormat, edit the
\l{https://clang.llvm.org/docs/ClangFormatStyleOptions.html} \l{https://clang.llvm.org/docs/ClangFormatStyleOptions.html}
{ClangFormat Style Options}. {ClangFormat Style Options}. The live preview shows how the
preferences change the indentation.
If you enter invalid values, you see warning messages.
\endlist \endlist
In the other tabs, you can specify how to: \section1 Using Built-In Indenter
\image qtcreator-code-style-built-in-indenter.webp {Code Style preferences for built-in indenter}
If you select \uicontrol {Use Built-In Indenter} in
\uicontrol {Formatting mode}, you can specify how to:
\list \list
\li Interpret the \key Tab and \key Backspace key presses. \li Interpret the \key Tab and \key Backspace key presses.
@@ -52,12 +61,9 @@
\li Bind pointers (*) and references (&) in types and declarations to \li Bind pointers (*) and references (&) in types and declarations to
identifiers, type names, or left or right \c const or \c volatile identifiers, type names, or left or right \c const or \c volatile
keywords. keywords.
\li Name getter functions.
\endlist \endlist
Use the live preview to see how the preferences change the indentation. \section2 Specifying Settings for Content
\section1 Specifying Settings for Content
You can indent public, protected, and private statements and declarations You can indent public, protected, and private statements and declarations
related to them within classes. related to them within classes.
@@ -67,24 +73,24 @@
\image qtcreator-code-style-content.png {Content preferences} \image qtcreator-code-style-content.png {Content preferences}
\section1 Specifying Settings for Braces \section2 Specifying Settings for Braces
You can indent class, namespace, enum and function declarations and code You can indent class, namespace, enum and function declarations and code
blocks. blocks.
\image qtcreator-code-style-braces.png {Braces preferences} \image qtcreator-code-style-braces.png {Braces preferences}
\section1 Specifying Settings for Switch Statements \section2 Specifying Settings for Switch Statements
You can indent case or default statements, or statements or blocks related You can indent case or default statements, or statements or blocks related
to them within switch statements. to them within switch statements.
\image qtcreator-code-style-switch.png {Switch preferences} \image qtcreator-code-style-switch.png {Switch preferences}
\section1 Specifying Alignment \section2 Specifying Alignment
To align continuation lines to tokens after assignments, such as \c = or To align continuation lines to tokens after assignments, such as \c = or
\c +=, select the \uicontrol {Align after assignments} check box. You can \c +=, select \uicontrol {Align after assignments}. You can
specify additional settings for aligning continuation lines in the specify additional settings for aligning continuation lines in the
\uicontrol General tab. \uicontrol General tab.
@@ -94,7 +100,7 @@
\image qtcreator-code-style-alignment.png {Alignment preferences} \image qtcreator-code-style-alignment.png {Alignment preferences}
\section1 Binding Pointers and References \section2 Binding Pointers and References
To bind pointers (\c *) and references (\c &) in types and declarations to To bind pointers (\c *) and references (\c &) in types and declarations to
identifiers, type names, or left or right \c const or \c volatile keywords, identifiers, type names, or left or right \c const or \c volatile keywords,
@@ -105,15 +111,6 @@
\image qtcreator-pointers-references.png {Pointers and References preferences} \image qtcreator-pointers-references.png {Pointers and References preferences}
\section1 Creating Project-Specific ClangFormat Files
To override the \c {.clang-format} file for a particular project, create a
copy of the built-in style and edit its settings by selecting
\uicontrol Projects > \uicontrol {Project Settings} >
\uicontrol {Code Style} > \uicontrol Copy > \uicontrol Edit >
\uicontrol {ClangFormat} >
\uicontrol {Override ClangFormat configuration file}.
\section1 Creating ClangFormat Files from Command Line \section1 Creating ClangFormat Files from Command Line
You can create \c {.clang-format} files that have the configuration You can create \c {.clang-format} files that have the configuration
@@ -124,5 +121,6 @@
clang-format -style=llvm -dump-config > .clang-format clang-format -style=llvm -dump-config > .clang-format
\endcode \endcode
\sa {Indent text or code}, {Behavior}, {Qt Quick Code Style}, {Nim} \sa {Indent text or code}, {Specify code style}, {Behavior},
{Qt Quick Code Style}, {Nim}
*/ */

View File

@@ -16,11 +16,11 @@
To specify preferences for the Nim editor (experimental): To specify preferences for the Nim editor (experimental):
\list 1 \list 1
\li Select \preferences > \uicontrol Nim. \li Go to \preferences > \uicontrol Nim.
\li In the \uicontrol {Current settings} field, select the settings to \li In \uicontrol {Custom settings}, select the settings to
modify and click \uicontrol Copy. modify, and then select \uicontrol Copy.
\image qtcreator-preferences-nim-code-style.webp {Nim Code Style preferences} \image qtcreator-preferences-nim-code-style.webp {Nim Code Style preferences}
\li Give a name to the settings and click \uicontrol OK. \li Give a name to the settings, and select \uicontrol OK.
\li Specify how to interpret the \key Tab key presses and how to align \li Specify how to interpret the \key Tab key presses and how to align
continuation lines. continuation lines.
\li Select \uicontrol OK to save the settings. \li Select \uicontrol OK to save the settings.
@@ -36,7 +36,7 @@
completion. completion.
To use Nimsuggest, you must install it on the development PC and enter the To use Nimsuggest, you must install it on the development PC and enter the
path to the tool executable in the \uicontrol Path field. path to the tool executable in \uicontrol Path.
\image qtcreator-preferences-nim-tools.webp \image qtcreator-preferences-nim-tools.webp

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2023 The Qt Company Ltd. // Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
// ********************************************************************** // **********************************************************************
@@ -19,16 +19,15 @@
and editor the file opens in. \QC opens C++ files in \uicontrol Edit mode and editor the file opens in. \QC opens C++ files in \uicontrol Edit mode
in the C++ code editor and QML files in the Qt Quick editor. in the C++ code editor and QML files in the Qt Quick editor.
You can specify indentation for: Specify indentation for:
\list \list
\li C++ files \li C++ files
\li QML files \li QML files
\li Nim files \li Nim files
\li Other text files
\endlist \endlist
You can specify code style either globally or separately for each project. Specify code style either globally or separately for each project.
You can specify several sets of code style settings and easily switch between You can specify several sets of code style settings and easily switch between
them. In addition, you can import and export code style settings. them. In addition, you can import and export code style settings.
@@ -36,31 +35,30 @@
\list 1 \list 1
\li Select \uicontrol Projects > \uicontrol {Project Settings} > \li Go to \uicontrol Projects > \uicontrol {Project Settings} >
\uicontrol {Code Style}. \uicontrol {Code Style}.
\image qtcreator-code-style-clang-format-project.webp {Code Style settings in Projects mode} \image qtcreator-code-style-clang-format-project.webp {Code Style settings in Projects mode}
\li In the \uicontrol Language field, select \uicontrol C++, \li In \uicontrol Language, select \uicontrol C++,
\uicontrol {Qt Quick}, or \uicontrol Nim. \uicontrol {Qt Quick}, or \uicontrol Nim.
\li Deselect the \uicontrol {Use global settings} check box. \li For C++, clear \uicontrol {Use global settings} to use the
\c {.clang-format} file for the project.
\li In the \uicontrol {Current settings} field, select the settings to modify \li To override the project's \c {.clang-format} file,
and click \uicontrol Copy. select \uicontrol {Use custom settings}.
\li Give a name to the settings and click \uicontrol OK.
\li Click \uicontrol Edit to specify a code style for the project.
\li In \uicontrol {Custom settings}, select the settings to use for the
project.
\endlist \endlist
In rare cases, ClangFormat can trip over a code construct and In rare cases, ClangFormat can trip over a code construct and
trigger a \QC crash. If that happens for your project, select trigger a \QC crash. If that happens for your project, select
\uicontrol Disable as the formatting mode to switch \uicontrol {Use Built-In Indenter} in \uicontrol {Formatting mode} to
ClangFormat off for the project. If you can reproduce the crash, turn off ClangFormat for the project. If you can reproduce the crash,
please select \uicontrol Help > \uicontrol {Report Bug} to report go to \uicontrol Help > \uicontrol {Report Bug} to report
the bug and and attach the code that triggers the crash. the bug and attach the code that triggers the crash to the bug report.
\sa {Indent text or code}, {Edit MIME types}, {C++ Code Style}, \sa {Indent text or code}, {Edit MIME types}, {C++ Code Style},
{Qt Quick Code Style}, {Nim} {Qt Quick Code Style}, {Nim}

View File

@@ -19,20 +19,16 @@
To specify QML code style globally: To specify QML code style globally:
\list 1 \list 1
\li Select \preferences > \uicontrol {Qt Quick}. \li Go to \preferences > \uicontrol {Qt Quick} > \uicontrol {Code Style}.
\li In the \uicontrol {Current settings} field, select the settings to \li In \uicontrol {Custom settings}, select the settings to
modify and click \uicontrol Copy. modify, and then select \uicontrol Copy.
\image qtcreator-options-code-style-qml.png {QML Code Style preferences} \image qtcreator-preferences-qtquick-code-style.webp {Qt Quick Code Style preferences}
\li Give a name to the settings and click \uicontrol OK. \li Give a name to the settings, and select \uicontrol OK.
\li Click \uicontrol Edit to specify code style settings for the project. \li Specify how to interpret the \key Tab key presses and how to align
\image qtcreator-code-style-settings-edit-qtquick.png {Edit Code Style dialog}
\endlist
You can specify how to interpret the \key Tab key presses and how to align
continuation lines. continuation lines.
\li In \uicontrol {Line length}, set the maximum line length for
In \uicontrol {Line length}, you can adjust the maximum line length for
code lines. code lines.
\endlist
To override the global preferences for a particular project, select To override the global preferences for a particular project, select
\uicontrol Projects > \uicontrol {Code Style}. \uicontrol Projects > \uicontrol {Code Style}.