美化程序
保存源代码文件时自动应用缩进和样式。使用预定义样式或定义自己的样式。
指定美化文件的设置:
- 转到首选项>Beautifier >General 。
- 选择Automatic formatting on file save ,在保存文件时使用Tool 字段中选择的工具自动美化文件。
- 在Restrict to MIME types 中,定义要美化的文件的 MIME 类型,用分号分隔。将该字段留空可将工具应用于所有文件。
此设置仅在保存时自动美化文件时应用。要在选择菜单项格式化当前打开的文件时限制 MIME 类型,请在工具特定选项卡中指定此选项。
- 选择Restrict to files contained in the current project 可仅美化属于当前项目的文件。
- 转到Artistic Style 、ClangFormat 或Uncrustify ,为要使用的工具指定设置。
- 在Configuration 中,在Artistic Style command 、ClangFormat command 或Uncrustify command 中指定工具可执行文件的路径。
- 在Restrict to MIME types 中,定义要美化的文件的 MIME 类型。选择菜单项格式化当前打开的文件时,将应用此设置。
- 在Options 中,选择定义要在源文件中使用的样式的配置文件。如果您选择了多个选项,它们将自上而下应用。可用选项取决于工具。
美化工具选项
要设置以下选项,必须安装其中一种工具。
选项 | 值 |
---|---|
Use file *.astylerc defined in project files Use file uncrustify.cfg defined in project files | 使用项目文件中定义的配置文件作为所选工具的配置文件。 |
Use specific config file Use file specific uncrustify.cfg | 用作所选工具配置文件的文件。 |
Use file uncrustify.cfg in <$HOME> Use file .astylerc or acstylerc in <$HOME> | 使用用户主目录中的指定文件作为所选工具的配置文件。 |
Use customized style | 设置自己的代码风格。 |
Format entire file if no text was selected | 当编辑器中未选中文本并选择Format Selected Text 时,格式化整个文件。 |
使用预定义的 ClangFormat 样式
要使用预定义的 ClangFormat 样式,请访问ClangFormat 并选择Use predefined style 中的样式。
选择File ,从与源文件位于同一目录或其父目录中的.clang-format
或_clang-format
文件加载样式配置。
在Fallback style 中,选择在样式配置文件不可用时使用的后备样式。选择Default 可使用默认样式。选择None 可跳过格式化。
定义样式
要定义自己的样式,请选择Use customized style ,然后选择Add 。
在Add Configuration 对话框中设置代码样式。它提供语法高亮、自动完成和上下文相关帮助。
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.