// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \page creator-preferences-cpp-code-style.html
    \previouspage creator-reference.html

    \ingroup creator-reference-preferences-cpp

    \title C++ Code Style

    \brief Set global code style for C++ files.

    \QC uses the Clang \l{https://clang.llvm.org/docs/LibFormat.html}{LibFormat}
    library to automatically format and indent C++ code. It enforces a coding
    style for a project or the whole organization.

    To specify global indentation settings for the C++ editor:

    \list 1
        \li Select \preferences > \uicontrol {C++}.
            \image qtcreator-code-style-clang-format-global.webp {Code Style preferences}
        \li In \uicontrol {Formatting mode}, select:
            \list
                \li \uicontrol {Indenting Only} to only indent code.
                \li \uicontrol {Full Formatting} to use the \key {Ctrl+I}
                    keyboard shortcut to format code instead of indenting.
                \li \uicontrol Disable to turn off ClangFormat.
            \endlist
        \li To apply the formatting while you type, select
            \uicontrol {Format while typing}.
        \li To apply the formatting to the edited code when you save the file,
            select \uicontrol {Format edited code on file save}.
        \li To change the ClangFormat style globally for all projects,
            select \uicontrol {Override ClangFormat configuration file}.
        \li In the \uicontrol {Current settings} field, select the settings to
            modify and click \uicontrol Copy.
        \li Give a name to the settings and click \uicontrol OK.
        \li Click \uicontrol Edit to set
            \l{https://clang.llvm.org/docs/ClangFormatStyleOptions.html}
            {ClangFormat Style Options}.
    \endlist

    In the other tabs, you can specify how to:

    \list
        \li Interpret the \key Tab and \key Backspace key presses.
        \li Indent the contents of classes, functions, blocks, and namespaces.
        \li Indent braces in classes, namespaces, enums, functions, and blocks.
        \li Control switch statements and their contents.
        \li Align continuation lines.
        \li Bind pointers (*) and references (&) in types and declarations to
            identifiers, type names, or left or right \c const or \c volatile
            keywords.
        \li Name getter functions.
    \endlist

    Use the live preview to see how the preferences change the indentation.

    \section1 Specifying Settings for Content

    You can indent public, protected, and private statements and declarations
    related to them within classes.

    You can also indent statements within functions and blocks and declarations
    within namespaces.

    \image qtcreator-code-style-content.png {Content preferences}

    \section1 Specifying Settings for Braces

    You can indent class, namespace, enum and function declarations and code
    blocks.

    \image qtcreator-code-style-braces.png {Braces preferences}

    \section1 Specifying Settings for Switch Statements

    You can indent case or default statements, or statements or blocks related
    to them within switch statements.

    \image qtcreator-code-style-switch.png {Switch preferences}

    \section1 Specifying Alignment

    To align continuation lines to tokens after assignments, such as \c = or
    \c +=, select the \uicontrol {Align after assignments} check box. You can
    specify additional settings for aligning continuation lines in the
    \uicontrol General tab.

    You can also add spaces to conditional statements, so that they are not
    aligned with the following line. Usually, this only affects \c if
    statements.

    \image qtcreator-code-style-alignment.png {Alignment preferences}

    \section1 Binding Pointers and References

    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,
    select the check boxes in the \uicontrol {Pointers and References} tab.

    The \c * and \c & characters are automatically bound to identifiers of
    pointers to functions and pointers to arrays.

    \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

    You can create \c {.clang-format} files that have the configuration
    options of a certain predefined style from the command line. For example,
    to create a format file for the LLVM style, enter the following command:

    \badcode
    clang-format -style=llvm -dump-config > .clang-format
    \endcode

    \sa {Indent text or code}, {Behavior}, {Qt Quick Code Style}, {Nim}
*/
