aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/clangtools/settingswidget.cpp
blob: 738e600a9753e2d459114ae2b6001666fdf56bad (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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#include "settingswidget.h"

#include "ui_settingswidget.h"

#include "clangtoolsconstants.h"
#include "clangtoolsutils.h"

#include <cppeditor/clangdiagnosticconfigsmodel.h>
#include <cppeditor/clangdiagnosticconfigsselectionwidget.h>

#include <debugger/analyzer/analyzericons.h>

#include <utils/optional.h>

using namespace Utils;

namespace ClangTools {
namespace Internal {

static SettingsWidget *m_instance = nullptr;

static void setupPathChooser(PathChooser *const chooser,
                             const QString &promptDiaglogTitle,
                             const QString &placeHolderText,
                             const FilePath &pathFromSettings,
                             const QString &historyCompleterId)
{
    chooser->setPromptDialogTitle(promptDiaglogTitle);
    chooser->setDefaultValue(placeHolderText);
    chooser->setFilePath(pathFromSettings);
    chooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
    chooser->setHistoryCompleter(historyCompleterId);
}

SettingsWidget *SettingsWidget::instance()
{
    return m_instance;
}

SettingsWidget::SettingsWidget()
    : m_ui(new Ui::SettingsWidget)
    , m_settings(ClangToolsSettings::instance())
{
    m_instance = this;
    m_ui->setupUi(this);

    //
    // Group box "Executables"
    //

    QString placeHolderText = shippedClangTidyExecutable().toUserOutput();
    FilePath path = m_settings->clangTidyExecutable();
    if (path.isEmpty() && placeHolderText.isEmpty())
        path = Constants::CLANG_TIDY_EXECUTABLE_NAME;
    setupPathChooser(m_ui->clangTidyPathChooser,
                     tr("Clang-Tidy Executable"),
                     placeHolderText,
                     path,
                     "ClangTools.ClangTidyExecutable.History");

    placeHolderText = shippedClazyStandaloneExecutable().toUserOutput();
    path = m_settings->clazyStandaloneExecutable();
    if (path.isEmpty() && placeHolderText.isEmpty())
        path = Constants::CLAZY_STANDALONE_EXECUTABLE_NAME;
    setupPathChooser(m_ui->clazyStandalonePathChooser,
                     tr("Clazy Executable"),
                     placeHolderText,
                     path,
                     "ClangTools.ClazyStandaloneExecutable.History");

    //
    // Group box "Run Options"
    //

    m_ui->runSettingsWidget->fromSettings(m_settings->runSettings());
}

void SettingsWidget::apply()
{
    // Executables
    m_settings->setClangTidyExecutable(clangTidyPath());
    m_settings->setClazyStandaloneExecutable(clazyStandalonePath());

    // Run options
    m_settings->setRunSettings(m_ui->runSettingsWidget->toSettings());

    // Custom configs
    const CppEditor::ClangDiagnosticConfigs customConfigs
        = m_ui->runSettingsWidget->diagnosticSelectionWidget()->customConfigs();
    m_settings->setDiagnosticConfigs(customConfigs);

    m_settings->writeSettings();
}

SettingsWidget::~SettingsWidget()
{
    m_instance = nullptr;
}

FilePath SettingsWidget::clangTidyPath() const
{
    return m_ui->clangTidyPathChooser->rawFilePath();
}

FilePath SettingsWidget::clazyStandalonePath() const
{
    return m_ui->clazyStandalonePathChooser->rawFilePath();
}

// ClangToolsOptionsPage

ClangToolsOptionsPage::ClangToolsOptionsPage()
{
    setId(Constants::SETTINGS_PAGE_ID);
    setDisplayName(QCoreApplication::translate(
                       "ClangTools::Internal::ClangToolsOptionsPage",
                       "Clang Tools"));
    setCategory("T.Analyzer");
    setDisplayCategory(QCoreApplication::translate("Analyzer", "Analyzer"));
    setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER);
    setWidgetCreator([] { return new SettingsWidget; });
}

} // namespace Internal
} // namespace ClangTools