aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cpptools
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2019-02-22 09:48:46 +0100
committerIvan Donchevskii <ivan.donchevskii@qt.io>2019-02-22 14:31:05 +0000
commit956543e462fcb965f3ad637ac1e38ff6c80c7f3c (patch)
treed2c04c3ed2b701e685f0e0e7b5fa78e99a93322e /src/plugins/cpptools
parentc6b58a063f1e3e92b3126511380416c6c6c299b4 (diff)
ClangFormat: Add the preview text editor to the settings
Allows the user to see how the current style applies to the code snippet. The action is triggered by the 'Apply' button. Change-Id: I820d989519cfdfb6e617ed6e8e9e5751be6619ea Reviewed-by: Marco Bubke <marco.bubke@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Diffstat (limited to 'src/plugins/cpptools')
-rw-r--r--src/plugins/cpptools/cppcodestylesettingspage.cpp166
-rw-r--r--src/plugins/cpptools/cpptoolsconstants.h158
2 files changed, 159 insertions, 165 deletions
diff --git a/src/plugins/cpptools/cppcodestylesettingspage.cpp b/src/plugins/cpptools/cppcodestylesettingspage.cpp
index 39517e6e353..981a0bda617 100644
--- a/src/plugins/cpptools/cppcodestylesettingspage.cpp
+++ b/src/plugins/cpptools/cppcodestylesettingspage.cpp
@@ -49,170 +49,6 @@
#include <QTextBlock>
#include <QTextStream>
-static const char *defaultCodeStyleSnippets[] = {
- "#include <math.h>\n"
- "\n"
- "class Complex\n"
- " {\n"
- "public:\n"
- " Complex(double re, double im)\n"
- " : _re(re), _im(im)\n"
- " {}\n"
- " double modulus() const\n"
- " {\n"
- " return sqrt(_re * _re + _im * _im);\n"
- " }\n"
- "private:\n"
- " double _re;\n"
- " double _im;\n"
- " };\n"
- "\n"
- "void bar(int i)\n"
- " {\n"
- " static int counter = 0;\n"
- " counter += i;\n"
- " }\n"
- "\n"
- "namespace Foo\n"
- " {\n"
- " namespace Bar\n"
- " {\n"
- " void foo(int a, int b)\n"
- " {\n"
- " for (int i = 0; i < a; i++)\n"
- " {\n"
- " if (i < b)\n"
- " bar(i);\n"
- " else\n"
- " {\n"
- " bar(i);\n"
- " bar(b);\n"
- " }\n"
- " }\n"
- " }\n"
- " } // namespace Bar\n"
- " } // namespace Foo\n"
- ,
- "#include <math.h>\n"
- "\n"
- "class Complex\n"
- " {\n"
- "public:\n"
- " Complex(double re, double im)\n"
- " : _re(re), _im(im)\n"
- " {}\n"
- " double modulus() const\n"
- " {\n"
- " return sqrt(_re * _re + _im * _im);\n"
- " }\n"
- "private:\n"
- " double _re;\n"
- " double _im;\n"
- " };\n"
- "\n"
- "void bar(int i)\n"
- " {\n"
- " static int counter = 0;\n"
- " counter += i;\n"
- " }\n"
- "\n"
- "namespace Foo\n"
- " {\n"
- " namespace Bar\n"
- " {\n"
- " void foo(int a, int b)\n"
- " {\n"
- " for (int i = 0; i < a; i++)\n"
- " {\n"
- " if (i < b)\n"
- " bar(i);\n"
- " else\n"
- " {\n"
- " bar(i);\n"
- " bar(b);\n"
- " }\n"
- " }\n"
- " }\n"
- " } // namespace Bar\n"
- " } // namespace Foo\n"
- ,
- "namespace Foo\n"
- "{\n"
- "namespace Bar\n"
- "{\n"
- "class FooBar\n"
- " {\n"
- "public:\n"
- " FooBar(int a)\n"
- " : _a(a)\n"
- " {}\n"
- " int calculate() const\n"
- " {\n"
- " if (a > 10)\n"
- " {\n"
- " int b = 2 * a;\n"
- " return a * b;\n"
- " }\n"
- " return -a;\n"
- " }\n"
- "private:\n"
- " int _a;\n"
- " };\n"
- "}\n"
- "}\n"
- ,
- "#include \"bar.h\"\n"
- "\n"
- "int foo(int a)\n"
- " {\n"
- " switch (a)\n"
- " {\n"
- " case 1:\n"
- " bar(1);\n"
- " break;\n"
- " case 2:\n"
- " {\n"
- " bar(2);\n"
- " break;\n"
- " }\n"
- " case 3:\n"
- " default:\n"
- " bar(3);\n"
- " break;\n"
- " }\n"
- " return 0;\n"
- " }\n"
- ,
- "void foo() {\n"
- " if (a &&\n"
- " b)\n"
- " c;\n"
- "\n"
- " while (a ||\n"
- " b)\n"
- " break;\n"
- " a = b +\n"
- " c;\n"
- " myInstance.longMemberName +=\n"
- " foo;\n"
- " myInstance.longMemberName += bar +\n"
- " foo;\n"
- "}\n"
- ,
- "int *foo(const Bar &b1, Bar &&b2, int*, int *&rpi)\n"
- "{\n"
- " int*pi = 0;\n"
- " int*const*const cpcpi = &pi;\n"
- " int*const*pcpi = &pi;\n"
- " int**const cppi = &pi;\n"
- "\n"
- " void (*foo)(char *s) = 0;\n"
- " int (*bar)[] = 0;\n"
- "\n"
- " return pi;\n"
- "}\n"
-};
-
using namespace TextEditor;
namespace CppTools {
@@ -270,7 +106,7 @@ CppCodeStylePreferencesWidget::CppCodeStylePreferencesWidget(QWidget *parent)
<< m_ui->previewTextEditBraces << m_ui->previewTextEditSwitch
<< m_ui->previewTextEditPadding << m_ui->previewTextEditPointerReferences;
for (int i = 0; i < m_previews.size(); ++i)
- m_previews[i]->setPlainText(QLatin1String(defaultCodeStyleSnippets[i]));
+ m_previews[i]->setPlainText(QLatin1String(Constants::DEFAULT_CODE_STYLE_SNIPPETS[i]));
decorateEditors(TextEditorSettings::fontSettings());
connect(TextEditorSettings::instance(), &TextEditorSettings::fontSettingsChanged,
diff --git a/src/plugins/cpptools/cpptoolsconstants.h b/src/plugins/cpptools/cpptoolsconstants.h
index 2e1aebfd432..781f5ebdf89 100644
--- a/src/plugins/cpptools/cpptoolsconstants.h
+++ b/src/plugins/cpptools/cpptoolsconstants.h
@@ -105,5 +105,163 @@ constexpr const char TIDY_DOCUMENTATION_URL_TEMPLATE[]
constexpr const char CLAZY_DOCUMENTATION_URL_TEMPLATE[]
= "https://github.com/KDE/clazy/blob/master/docs/checks/README-%1.md";
+static const char *DEFAULT_CODE_STYLE_SNIPPETS[]
+ = {"#include <math.h>\n"
+ "\n"
+ "class Complex\n"
+ " {\n"
+ "public:\n"
+ " Complex(double re, double im)\n"
+ " : _re(re), _im(im)\n"
+ " {}\n"
+ " double modulus() const\n"
+ " {\n"
+ " return sqrt(_re * _re + _im * _im);\n"
+ " }\n"
+ "private:\n"
+ " double _re;\n"
+ " double _im;\n"
+ " };\n"
+ "\n"
+ "void bar(int i)\n"
+ " {\n"
+ " static int counter = 0;\n"
+ " counter += i;\n"
+ " }\n"
+ "\n"
+ "namespace Foo\n"
+ " {\n"
+ " namespace Bar\n"
+ " {\n"
+ " void foo(int a, int b)\n"
+ " {\n"
+ " for (int i = 0; i < a; i++)\n"
+ " {\n"
+ " if (i < b)\n"
+ " bar(i);\n"
+ " else\n"
+ " {\n"
+ " bar(i);\n"
+ " bar(b);\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " } // namespace Bar\n"
+ " } // namespace Foo\n",
+ "#include <math.h>\n"
+ "\n"
+ "class Complex\n"
+ " {\n"
+ "public:\n"
+ " Complex(double re, double im)\n"
+ " : _re(re), _im(im)\n"
+ " {}\n"
+ " double modulus() const\n"
+ " {\n"
+ " return sqrt(_re * _re + _im * _im);\n"
+ " }\n"
+ "private:\n"
+ " double _re;\n"
+ " double _im;\n"
+ " };\n"
+ "\n"
+ "void bar(int i)\n"
+ " {\n"
+ " static int counter = 0;\n"
+ " counter += i;\n"
+ " }\n"
+ "\n"
+ "namespace Foo\n"
+ " {\n"
+ " namespace Bar\n"
+ " {\n"
+ " void foo(int a, int b)\n"
+ " {\n"
+ " for (int i = 0; i < a; i++)\n"
+ " {\n"
+ " if (i < b)\n"
+ " bar(i);\n"
+ " else\n"
+ " {\n"
+ " bar(i);\n"
+ " bar(b);\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " } // namespace Bar\n"
+ " } // namespace Foo\n",
+ "namespace Foo\n"
+ "{\n"
+ "namespace Bar\n"
+ "{\n"
+ "class FooBar\n"
+ " {\n"
+ "public:\n"
+ " FooBar(int a)\n"
+ " : _a(a)\n"
+ " {}\n"
+ " int calculate() const\n"
+ " {\n"
+ " if (a > 10)\n"
+ " {\n"
+ " int b = 2 * a;\n"
+ " return a * b;\n"
+ " }\n"
+ " return -a;\n"
+ " }\n"
+ "private:\n"
+ " int _a;\n"
+ " };\n"
+ "}\n"
+ "}\n",
+ "#include \"bar.h\"\n"
+ "\n"
+ "int foo(int a)\n"
+ " {\n"
+ " switch (a)\n"
+ " {\n"
+ " case 1:\n"
+ " bar(1);\n"
+ " break;\n"
+ " case 2:\n"
+ " {\n"
+ " bar(2);\n"
+ " break;\n"
+ " }\n"
+ " case 3:\n"
+ " default:\n"
+ " bar(3);\n"
+ " break;\n"
+ " }\n"
+ " return 0;\n"
+ " }\n",
+ "void foo() {\n"
+ " if (a &&\n"
+ " b)\n"
+ " c;\n"
+ "\n"
+ " while (a ||\n"
+ " b)\n"
+ " break;\n"
+ " a = b +\n"
+ " c;\n"
+ " myInstance.longMemberName +=\n"
+ " foo;\n"
+ " myInstance.longMemberName += bar +\n"
+ " foo;\n"
+ "}\n",
+ "int *foo(const Bar &b1, Bar &&b2, int*, int *&rpi)\n"
+ "{\n"
+ " int*pi = 0;\n"
+ " int*const*const cpcpi = &pi;\n"
+ " int*const*pcpi = &pi;\n"
+ " int**const cppi = &pi;\n"
+ "\n"
+ " void (*foo)(char *s) = 0;\n"
+ " int (*bar)[] = 0;\n"
+ "\n"
+ " return pi;\n"
+ "}\n"};
+
} // namespace Constants
} // namespace CppTools