aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cppcheck/cppcheckoptions.cpp
blob: 74e56b8e81c3eaafa867cea323c7882364f3b9b7 (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
// Copyright (C) 2018 Sergey Morozov
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#include "cppcheckconstants.h"
#include "cppcheckoptions.h"
#include "cppchecktool.h"
#include "cppchecktrigger.h"

#include <utils/flowlayout.h>
#include <utils/hostosinfo.h>
#include <utils/pathchooser.h>
#include <utils/qtcassert.h>
#include <utils/variablechooser.h>

#include <coreplugin/icore.h>

#include <debugger/analyzer/analyzericons.h>

#include <QCheckBox>
#include <QFormLayout>

using namespace Utils;

namespace Cppcheck {
namespace Internal {

OptionsWidget::OptionsWidget(QWidget *parent)
    : QWidget(parent),
    m_binary(new Utils::PathChooser(this)),
    m_customArguments(new QLineEdit(this)),
    m_ignorePatterns(new QLineEdit(this)),
    m_warning(new QCheckBox(tr("Warnings"), this)),
    m_style(new QCheckBox(tr("Style"), this)),
    m_performance(new QCheckBox(tr("Performance"), this)),
    m_portability(new QCheckBox(tr("Portability"), this)),
    m_information(new QCheckBox(tr("Information"), this)),
    m_unusedFunction(new QCheckBox(tr("Unused functions"), this)),
    m_missingInclude(new QCheckBox(tr("Missing includes"), this)),
    m_inconclusive(new QCheckBox(tr("Inconclusive errors"), this)),
    m_forceDefines(new QCheckBox(tr("Check all define combinations"), this)),
    m_showOutput(new QCheckBox(tr("Show raw output"), this)),
    m_addIncludePaths(new QCheckBox(tr("Add include paths"), this)),
    m_guessArguments(new QCheckBox(tr("Calculate additional arguments"), this))
{
    m_binary->setExpectedKind(Utils::PathChooser::ExistingCommand);
    m_binary->setCommandVersionArguments({"--version"});

    auto variableChooser = new Utils::VariableChooser(this);
    variableChooser->addSupportedWidget (m_customArguments);

    m_unusedFunction->setToolTip(tr("Disables multithreaded check."));
    m_ignorePatterns->setToolTip(tr("Comma-separated wildcards of full file paths. "
                                    "Files still can be checked if others include them."));
    m_addIncludePaths->setToolTip(tr("Can find missing includes but makes "
                                     "checking slower. Use only when needed."));
    m_guessArguments->setToolTip(tr("Like C++ standard and language."));

    auto layout = new QFormLayout(this);
    layout->addRow(tr("Binary:"), m_binary);

    auto checks = new Utils::FlowLayout;
    layout->addRow(tr("Checks:"), checks);
    checks->addWidget(m_warning);
    checks->addWidget(m_style);
    checks->addWidget(m_performance);
    checks->addWidget(m_portability);
    checks->addWidget(m_information);
    checks->addWidget(m_unusedFunction);
    checks->addWidget(m_missingInclude);

    layout->addRow(tr("Custom arguments:"), m_customArguments);
    layout->addRow(tr("Ignored file patterns:"), m_ignorePatterns);
    auto flags = new Utils::FlowLayout;
    layout->addRow(flags);
    flags->addWidget(m_inconclusive);
    flags->addWidget(m_forceDefines);
    flags->addWidget(m_showOutput);
    flags->addWidget(m_addIncludePaths);
    flags->addWidget(m_guessArguments);
}

void OptionsWidget::load(const CppcheckOptions &options)
{
    m_binary->setFilePath(options.binary);
    m_customArguments->setText(options.customArguments);
    m_ignorePatterns->setText(options.ignoredPatterns);
    m_warning->setChecked(options.warning);
    m_style->setChecked(options.style);
    m_performance->setChecked(options.performance);
    m_portability->setChecked(options.portability);
    m_information->setChecked(options.information);
    m_unusedFunction->setChecked(options.unusedFunction);
    m_missingInclude->setChecked(options.missingInclude);
    m_inconclusive->setChecked(options.inconclusive);
    m_forceDefines->setChecked(options.forceDefines);
    m_showOutput->setChecked(options.showOutput);
    m_addIncludePaths->setChecked(options.addIncludePaths);
    m_guessArguments->setChecked(options.guessArguments);
}

void OptionsWidget::save(CppcheckOptions &options) const
{
    options.binary = m_binary->filePath();
    options.customArguments = m_customArguments->text();
    options.ignoredPatterns = m_ignorePatterns->text();
    options.warning = m_warning->isChecked();
    options.style = m_style->isChecked();
    options.performance = m_performance->isChecked();
    options.portability = m_portability->isChecked();
    options.information = m_information->isChecked();
    options.unusedFunction = m_unusedFunction->isChecked();
    options.missingInclude = m_missingInclude->isChecked();
    options.inconclusive = m_inconclusive->isChecked();
    options.forceDefines = m_forceDefines->isChecked();
    options.showOutput = m_showOutput->isChecked();
    options.addIncludePaths = m_addIncludePaths->isChecked();
    options.guessArguments = m_guessArguments->isChecked();
}

CppcheckOptionsPage::CppcheckOptionsPage(CppcheckTool &tool, CppcheckTrigger &trigger):
    m_tool(tool),
    m_trigger(trigger)
{
    setId(Constants::OPTIONS_PAGE_ID);
    setDisplayName(tr("Cppcheck"));
    setCategory("T.Analyzer");
    setDisplayCategory(QCoreApplication::translate("Analyzer", "Analyzer"));
    setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER);

    CppcheckOptions options;
    if (HostOsInfo::isAnyUnixHost()) {
        options.binary = "cppcheck";
    } else {
        FilePath programFiles = FilePath::fromUserInput(qEnvironmentVariable("PROGRAMFILES"));
        if (programFiles.isEmpty())
            programFiles = "C:/Program Files";
        options.binary = programFiles / "Cppcheck/cppcheck.exe";
    }

    load(options);

    m_tool.updateOptions(options);
}

QWidget *CppcheckOptionsPage::widget()
{
    if (!m_widget)
        m_widget = new OptionsWidget;
    m_widget->load(m_tool.options());
    return m_widget.data();
}

void CppcheckOptionsPage::apply()
{
    CppcheckOptions options;
    m_widget->save(options);
    save(options);
    m_tool.updateOptions(options);
    m_trigger.recheck();
}

void CppcheckOptionsPage::finish()
{
}

void CppcheckOptionsPage::save(const CppcheckOptions &options) const
{
    QSettings *s = Core::ICore::settings();
    QTC_ASSERT(s, return);
    s->beginGroup(Constants::SETTINGS_ID);
    s->setValue(Constants::SETTINGS_BINARY, options.binary.toString());
    s->setValue(Constants::SETTINGS_CUSTOM_ARGUMENTS, options.customArguments);
    s->setValue(Constants::SETTINGS_IGNORE_PATTERNS, options.ignoredPatterns);
    s->setValue(Constants::SETTINGS_WARNING, options.warning);
    s->setValue(Constants::SETTINGS_STYLE, options.style);
    s->setValue(Constants::SETTINGS_PERFORMANCE, options.performance);
    s->setValue(Constants::SETTINGS_PORTABILITY, options.portability);
    s->setValue(Constants::SETTINGS_INFORMATION, options.information);
    s->setValue(Constants::SETTINGS_UNUSED_FUNCTION, options.unusedFunction);
    s->setValue(Constants::SETTINGS_MISSING_INCLUDE, options.missingInclude);
    s->setValue(Constants::SETTINGS_INCONCLUSIVE, options.inconclusive);
    s->setValue(Constants::SETTINGS_FORCE_DEFINES, options.forceDefines);
    s->setValue(Constants::SETTINGS_SHOW_OUTPUT, options.showOutput);
    s->setValue(Constants::SETTINGS_ADD_INCLUDE_PATHS, options.addIncludePaths);
    s->setValue(Constants::SETTINGS_GUESS_ARGUMENTS, options.guessArguments);
    s->endGroup();
}

void CppcheckOptionsPage::load(CppcheckOptions &options) const
{
    QSettings *s = Core::ICore::settings();
    QTC_ASSERT(s, return);
    s->beginGroup(Constants::SETTINGS_ID);
    options.binary = FilePath::fromString(s->value(Constants::SETTINGS_BINARY,
                                                   options.binary.toString()).toString());
    options.customArguments = s->value(Constants::SETTINGS_CUSTOM_ARGUMENTS,
                                       options.customArguments).toString();
    options.ignoredPatterns = s->value(Constants::SETTINGS_IGNORE_PATTERNS,
                                       options.ignoredPatterns).toString();
    options.warning = s->value(Constants::SETTINGS_WARNING,
                               options.warning).toBool();
    options.style = s->value(Constants::SETTINGS_STYLE,
                             options.style).toBool();
    options.performance = s->value(Constants::SETTINGS_PERFORMANCE,
                                   options.performance).toBool();
    options.portability = s->value(Constants::SETTINGS_PORTABILITY,
                                   options.portability).toBool();
    options.information = s->value(Constants::SETTINGS_INFORMATION,
                                   options.information).toBool();
    options.unusedFunction = s->value(Constants::SETTINGS_UNUSED_FUNCTION,
                                      options.unusedFunction).toBool();
    options.missingInclude = s->value(Constants::SETTINGS_MISSING_INCLUDE,
                                      options.missingInclude).toBool();
    options.inconclusive = s->value(Constants::SETTINGS_INCONCLUSIVE,
                                    options.inconclusive).toBool();
    options.forceDefines = s->value(Constants::SETTINGS_FORCE_DEFINES,
                                    options.forceDefines).toBool();
    options.showOutput = s->value(Constants::SETTINGS_SHOW_OUTPUT,
                                  options.showOutput).toBool();
    options.addIncludePaths = s->value(Constants::SETTINGS_ADD_INCLUDE_PATHS,
                                       options.addIncludePaths).toBool();
    options.guessArguments = s->value(Constants::SETTINGS_GUESS_ARGUMENTS,
                                      options.guessArguments).toBool();
    s->endGroup();
}

} // namespace Internal
} // namespace Cppcheck