aboutsummaryrefslogtreecommitdiffstats
path: root/doc/qtcreator/src/editors/creator-code-indentation.qdoc
blob: 841f5c5b774bfd08dde83262a530715a3ab876e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Creator documentation.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
**
****************************************************************************/

/*!
    \previouspage creator-completing-code.html
    \page creator-indenting-code.html
    \nextpage qt-quick-toolbars.html

    \title Indenting Text or Code

    When you type text or code, it is indented automatically according to the
    selected text editor or code style options. Select a block to indent it when
    you press \key Tab. Press \key {Shift+Tab} to decrease the indentation. You
    can disable automatic indentation.

    You can specify indentation for:

    \list
        \if defined(qtcreator)
        \li C++ files
        \endif
        \li QML files
        \if defined(qtcreator)
        \li Nim files
        \endif
        \li Other text files
    \endlist

    You can also specify indentation separately for each project. You can
    specify several sets of code style settings and easily switch between them.
    In addition, you can import and export code style settings.

    \if defined(qtcreator)
    \section1 Indenting C++ Files

    To specify indentation settings for the C++ editor:

    \list 1
        \li Select \uicontrol Tools > \uicontrol Options > \uicontrol {C++}.
        \li In the \uicontrol {Current settings} field, select the settings to
            modify and click \uicontrol Copy.
            \image qtcreator-options-code-style-cpp.png "C++ Code Style options"
        \li Give a name to the settings and click \uicontrol OK.
        \li Click \uicontrol Edit to specify code style settings for the project.
            \image qtcreator-code-style-settings-edit-cpp.png "Edit Code Style Settings dialog"
    \endlist

    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

    You can use the live preview to see how the options change the indentation.

    To specify different settings for a particular project, select
    \uicontrol Projects > \uicontrol {Code Style Settings}.

    \include creator-clangformat.qdocinc clang format
    \endif

    \section1 Indenting QML Files

    To specify settings for the Qt Quick editor:

    \list 1
        \li Select \uicontrol Tools > \uicontrol Options >
            \uicontrol {Qt Quick}.
        \li In the \uicontrol {Current settings} field, select the settings to
            modify and click \uicontrol Copy.
            \image qtcreator-options-code-style-qml.png "QML Code Style options"
        \li Give a name to the settings and click \uicontrol OK.
        \li Click \uicontrol Edit to specify code style settings for the project.
            \image qtcreator-code-style-settings-edit-qtquick.png "Edit Code Style Settings dialog"
    \endlist

    You can specify how to interpret the \key Tab key presses and how to align
    continuation lines.

    To specify different settings for a particular project, select
    \uicontrol Projects > \uicontrol {Code Style Settings}.

    \if defined(qtcreator)
    \section1 Indenting Nim Files

    To specify settings for the Nim editor (experimental):

    \list 1
        \li Select \uicontrol Tools > \uicontrol Options > \uicontrol Nim.
        \li In the \uicontrol {Current settings} field, select the settings to
            modify and click \uicontrol Copy.
            \image qtcreator-options-code-style-nim.png "Nim Code Style options"
        \li Give a name to the settings and click \uicontrol OK.
        \li Click \uicontrol Edit to specify code style settings for the project.
            \image qtcreator-code-style-settings-edit-nim.png "Edit Code Style Settings dialog"
    \endlist

    You can specify how to interpret the \key Tab key presses and how to align
    continuation lines.

    To specify different settings for a particular project, select
    \uicontrol Projects > \uicontrol {Code Style}.
    \endif

    \section1 Indenting Other Text Files

    To specify indentation settings for text files that do not contain C++ or
    QML code (such as Python code files), select \uicontrol Tools >
    \uicontrol Options > \uicontrol {Text Editor} > \uicontrol Behavior.

    \image qtcreator-indentation.png "Text Editor Behavior options"

    To specify different settings for a particular project, select
    \uicontrol Projects > \uicontrol Editor.

    You can specify how to interpret the \key Tab and \key Backspace key
    presses and how to align continuation lines.

    \section1 Specifying Tab Settings

    You can specify tab settings at the following levels:

    \list
        \if defined(qtcreator)
        \li For all C++ files
        \endif
        \li For all QML files
        \li For all other text files
        \if defined(qtcreator)
        \li For C++ files in a project
        \endif
        \li For QML files in a project
        \li For other text files in a project
    \endlist

    \section2 Specifying Tabs and Indentation

    You can specify tab policy and tab size in the
    \uicontrol {Tabs and Indentation} group. In the \uicontrol {Tab policy}
    field, select whether to use only spaces or only tabs for indentation,
    or to use a mixture of them.

    By default, the tab length in code editor is 8 spaces and the indent size is
    4 spaces. You can specify the tab length and indent size separately for each
    project and for different types of files.

    You can have continuation lines aligned with the previous line. In the
    \uicontrol {Align continuation lines} field, select
    \uicontrol {Not at all} to disable automatic alignment and indent
    continuation lines to the logical depth. To always use spaces for alignment,
    select \uicontrol {With Spaces}. To follow the \uicontrol {Tab policy},
    select \uicontrol {With Regular Indent}.

    \section1 Specifying Typing Options

    When you type text or code, it is indented automatically according to the
    selected text editor or code style options. To specify typing options,
    select \uicontrol Tools > \uicontrol Options > \uicontrol {Text Editor} >
    \uicontrol Behavior > \uicontrol Typing.

    To disable automatic indentation,  deselect the
    \uicontrol {Enable automatic indentation} check box.

    You can specify how the indentation is decreased when you press
    \uicontrol Backspace in the \uicontrol {Backspace indentation} field. To go
    back one space at a time, select \uicontrol None. To decrease indentation
    in leading white space by one level, select
    \uicontrol {Follows Previous Indents}. To move back one tab length if the
    character to the left of the cursor is a space, select
    \uicontrol Unindents.

    You can specify whether the \key Tab key automatically indents text when you
    press it. To automatically indent text, select \uicontrol Always in the
    \uicontrol {Tab key performs auto-indent} field. To only indent text when
    the cursor is located within leading white space, select \uicontrol {In
    Leading White Space}.

    \if defined(qtcreator)
    \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 options"

    \section1 Specifying Settings for Braces

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

    \image qtcreator-code-style-braces.png "Braces options"

    \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 options"

    \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 options"

    \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 options"

    \section1 Naming Getters

    To prefer getter names without the string \e get, select the
    \uicontrol {Prefer getter names without "get"} check box in the
    \uicontrol {Getter and Setter} tab.

    \image qtcreator-code-style-getter-setter.png
    \endif
*/