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
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "cppcodestylepreferencesfactory.h"
#include "cppcodestylesettings.h"
#include "cppcodestylesettingspage.h"
#include "cppcodestylesnippets.h"
#include "cppeditorconstants.h"
#include "cppeditortr.h"
#include "cppqtstyleindenter.h"
#include <projectexplorer/project.h>
#include <texteditor/icodestylepreferencesfactory.h>
#include <texteditor/indenter.h>
#include <QLayout>
using namespace TextEditor;
namespace CppEditor {
class CppCodeStyleEditor final : public CodeStyleEditor
{
public:
static CppCodeStyleEditor *create(
const ICodeStylePreferencesFactory *factory,
ProjectExplorer::Project *project,
ICodeStylePreferences *codeStyle,
QWidget *parent)
{
auto editor = new CppCodeStyleEditor{parent};
editor->init(factory, wrapProject(project), codeStyle);
return editor;
}
private:
CppCodeStyleEditor(QWidget *parent)
: CodeStyleEditor{parent}
{}
CodeStyleEditorWidget *createEditorWidget(
const void * /*project*/,
ICodeStylePreferences *codeStyle,
QWidget *parent) const final
{
auto cppPreferences = dynamic_cast<CppCodeStylePreferences *>(codeStyle);
if (cppPreferences == nullptr)
return nullptr;
auto widget = new CppCodeStylePreferencesWidget(parent);
widget->layout()->setContentsMargins(0, 0, 0, 0);
widget->setCodeStyle(cppPreferences);
return widget;
}
QString previewText() const final
{
return QString::fromLatin1(Constants::DEFAULT_CODE_STYLE_SNIPPETS[0]);
}
QString snippetProviderGroupId() const final
{
return CppEditor::Constants::CPP_SNIPPETS_GROUP_ID;
}
};
// CppCodeStylePreferencesFactory
class CppCodeStylePreferencesFactory final : public ICodeStylePreferencesFactory
{
public:
CppCodeStylePreferencesFactory() = default;
private:
CodeStyleEditorWidget *createCodeStyleEditor(
const ProjectWrapper &project,
ICodeStylePreferences *codeStyle,
QWidget *parent) const final
{
return CppCodeStyleEditor::create(
this, ProjectExplorer::unwrapProject(project), codeStyle, parent);
}
Utils::Id languageId() final
{
return Constants::CPP_SETTINGS_ID;
}
QString displayName() final
{
return Tr::tr(Constants::CPP_SETTINGS_NAME);
}
ICodeStylePreferences *createCodeStyle() const final
{
return new CppCodeStylePreferences;
}
Indenter *createIndenter(QTextDocument *doc) const final
{
return createCppQtStyleIndenter(doc);
}
};
ICodeStylePreferencesFactory *createCppCodeStylePreferencesFactory()
{
return new CppCodeStylePreferencesFactory;
}
} // namespace CppEditor
|