forked from qt-creator/qt-creator
CppCheck: Rework settings handling
Change-Id: Id9c9b316c5e0d39bc5fcba14951664e72d947a71 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -9,23 +9,6 @@ const char TEXTMARK_CATEGORY_ID[] = "Cppcheck";
|
|||||||
|
|
||||||
const char OPTIONS_PAGE_ID[] = "Analyzer.Cppcheck.Settings";
|
const char OPTIONS_PAGE_ID[] = "Analyzer.Cppcheck.Settings";
|
||||||
|
|
||||||
const char SETTINGS_ID[] = "Cppcheck";
|
|
||||||
const char SETTINGS_BINARY[] = "binary";
|
|
||||||
const char SETTINGS_WARNING[] = "warning";
|
|
||||||
const char SETTINGS_STYLE[] = "style";
|
|
||||||
const char SETTINGS_PERFORMANCE[] = "performance";
|
|
||||||
const char SETTINGS_PORTABILITY[] = "portability";
|
|
||||||
const char SETTINGS_INFORMATION[] = "information";
|
|
||||||
const char SETTINGS_UNUSED_FUNCTION[] = "unusedFunction";
|
|
||||||
const char SETTINGS_MISSING_INCLUDE[] = "missingInclude";
|
|
||||||
const char SETTINGS_INCONCLUSIVE[] = "inconclusive";
|
|
||||||
const char SETTINGS_FORCE_DEFINES[] = "forceDefines";
|
|
||||||
const char SETTINGS_CUSTOM_ARGUMENTS[] = "customArguments";
|
|
||||||
const char SETTINGS_IGNORE_PATTERNS[] = "ignorePatterns";
|
|
||||||
const char SETTINGS_SHOW_OUTPUT[] = "showOutput";
|
|
||||||
const char SETTINGS_ADD_INCLUDE_PATHS[] = "addIncludePaths";
|
|
||||||
const char SETTINGS_GUESS_ARGUMENTS[] = "guessArguments";
|
|
||||||
|
|
||||||
const char CHECK_PROGRESS_ID[] = "Cppcheck.CheckingTask";
|
const char CHECK_PROGRESS_ID[] = "Cppcheck.CheckingTask";
|
||||||
|
|
||||||
const char MANUAL_CHECK_PROGRESS_ID[] = "Cppcheck.ManualCheckingTask";
|
const char MANUAL_CHECK_PROGRESS_ID[] = "Cppcheck.ManualCheckingTask";
|
||||||
|
|||||||
@@ -18,11 +18,9 @@
|
|||||||
|
|
||||||
namespace Cppcheck::Internal {
|
namespace Cppcheck::Internal {
|
||||||
|
|
||||||
ManualRunDialog::ManualRunDialog(const CppcheckOptions &options,
|
ManualRunDialog::ManualRunDialog(QWidget *optionsWidget,
|
||||||
const ProjectExplorer::Project *project)
|
const ProjectExplorer::Project *project)
|
||||||
: QDialog(),
|
: m_model(new ProjectExplorer::SelectableFilesFromDirModel(this))
|
||||||
m_options(new OptionsWidget(this)),
|
|
||||||
m_model(new ProjectExplorer::SelectableFilesFromDirModel(this))
|
|
||||||
{
|
{
|
||||||
QTC_ASSERT(project, return );
|
QTC_ASSERT(project, return );
|
||||||
|
|
||||||
@@ -55,21 +53,12 @@ ManualRunDialog::ManualRunDialog(const CppcheckOptions &options,
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto layout = new QVBoxLayout(this);
|
auto layout = new QVBoxLayout(this);
|
||||||
layout->addWidget(m_options);
|
layout->addWidget(optionsWidget);
|
||||||
layout->addWidget(view);
|
layout->addWidget(view);
|
||||||
layout->addWidget(buttons);
|
layout->addWidget(buttons);
|
||||||
|
|
||||||
if (auto layout = m_options->layout())
|
if (auto layout = optionsWidget->layout())
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
m_options->load(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
CppcheckOptions ManualRunDialog::options() const
|
|
||||||
{
|
|
||||||
CppcheckOptions result;
|
|
||||||
m_options->save(result);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FilePaths ManualRunDialog::filePaths() const
|
Utils::FilePaths ManualRunDialog::filePaths() const
|
||||||
|
|||||||
@@ -17,21 +17,15 @@ class SelectableFilesFromDirModel;
|
|||||||
|
|
||||||
namespace Cppcheck::Internal {
|
namespace Cppcheck::Internal {
|
||||||
|
|
||||||
class OptionsWidget;
|
|
||||||
class CppcheckOptions;
|
|
||||||
|
|
||||||
class ManualRunDialog : public QDialog
|
class ManualRunDialog : public QDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ManualRunDialog(const CppcheckOptions &options,
|
ManualRunDialog(QWidget *optionsWidget, const ProjectExplorer::Project *project);
|
||||||
const ProjectExplorer::Project *project);
|
|
||||||
|
|
||||||
CppcheckOptions options() const;
|
|
||||||
Utils::FilePaths filePaths() const;
|
Utils::FilePaths filePaths() const;
|
||||||
QSize sizeHint() const override;
|
QSize sizeHint() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OptionsWidget *m_options;
|
|
||||||
ProjectExplorer::SelectableFilesFromDirModel *m_model;
|
ProjectExplorer::SelectableFilesFromDirModel *m_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <utils/flowlayout.h>
|
#include <utils/flowlayout.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/pathchooser.h>
|
#include <utils/pathchooser.h>
|
||||||
|
#include <utils/layoutbuilder.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/variablechooser.h>
|
#include <utils/variablechooser.h>
|
||||||
|
|
||||||
@@ -20,220 +21,135 @@
|
|||||||
#include <debugger/analyzer/analyzericons.h>
|
#include <debugger/analyzer/analyzericons.h>
|
||||||
#include <debugger/debuggertr.h>
|
#include <debugger/debuggertr.h>
|
||||||
|
|
||||||
#include <QCheckBox>
|
|
||||||
#include <QFormLayout>
|
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Cppcheck::Internal {
|
namespace Cppcheck::Internal {
|
||||||
|
|
||||||
OptionsWidget::OptionsWidget(QWidget *parent)
|
CppcheckOptions::CppcheckOptions()
|
||||||
: QWidget(parent),
|
|
||||||
m_binary(new Utils::PathChooser(this)),
|
|
||||||
m_customArguments(new QLineEdit(this)),
|
|
||||||
m_ignorePatterns(new QLineEdit(this)),
|
|
||||||
m_warning(new QCheckBox(Tr::tr("Warnings"), this)),
|
|
||||||
m_style(new QCheckBox(Tr::tr("Style"), this)),
|
|
||||||
m_performance(new QCheckBox(Tr::tr("Performance"), this)),
|
|
||||||
m_portability(new QCheckBox(Tr::tr("Portability"), this)),
|
|
||||||
m_information(new QCheckBox(Tr::tr("Information"), this)),
|
|
||||||
m_unusedFunction(new QCheckBox(Tr::tr("Unused functions"), this)),
|
|
||||||
m_missingInclude(new QCheckBox(Tr::tr("Missing includes"), this)),
|
|
||||||
m_inconclusive(new QCheckBox(Tr::tr("Inconclusive errors"), this)),
|
|
||||||
m_forceDefines(new QCheckBox(Tr::tr("Check all define combinations"), this)),
|
|
||||||
m_showOutput(new QCheckBox(Tr::tr("Show raw output"), this)),
|
|
||||||
m_addIncludePaths(new QCheckBox(Tr::tr("Add include paths"), this)),
|
|
||||||
m_guessArguments(new QCheckBox(Tr::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::tr("Disables multithreaded check."));
|
|
||||||
m_ignorePatterns->setToolTip(Tr::tr("Comma-separated wildcards of full file paths. "
|
|
||||||
"Files still can be checked if others include them."));
|
|
||||||
m_addIncludePaths->setToolTip(Tr::tr("Can find missing includes but makes "
|
|
||||||
"checking slower. Use only when needed."));
|
|
||||||
m_guessArguments->setToolTip(Tr::tr("Like C++ standard and language."));
|
|
||||||
|
|
||||||
auto layout = new QFormLayout(this);
|
|
||||||
layout->addRow(Tr::tr("Binary:"), m_binary);
|
|
||||||
|
|
||||||
auto checks = new Utils::FlowLayout;
|
|
||||||
layout->addRow(Tr::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::tr("Custom arguments:"), m_customArguments);
|
|
||||||
layout->addRow(Tr::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();
|
|
||||||
}
|
|
||||||
|
|
||||||
class CppcheckOptionsPageWidget : public Core::IOptionsPageWidget
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CppcheckOptionsPageWidget(CppcheckOptionsPage *page)
|
|
||||||
: m_page(page)
|
|
||||||
{
|
|
||||||
m_optionWidget = new OptionsWidget;
|
|
||||||
|
|
||||||
auto vbox = new QVBoxLayout(this);
|
|
||||||
vbox->addWidget(m_optionWidget);
|
|
||||||
vbox->setContentsMargins(0, 0, 0, 0);
|
|
||||||
|
|
||||||
m_optionWidget->load(m_page->m_tool.options());
|
|
||||||
}
|
|
||||||
|
|
||||||
void apply() final
|
|
||||||
{
|
|
||||||
CppcheckOptions options;
|
|
||||||
m_optionWidget->save(options);
|
|
||||||
m_page->save(options);
|
|
||||||
m_page->m_tool.updateOptions(options);
|
|
||||||
m_page->m_trigger.recheck();
|
|
||||||
}
|
|
||||||
|
|
||||||
OptionsWidget *m_optionWidget;
|
|
||||||
CppcheckOptionsPage *m_page;
|
|
||||||
};
|
|
||||||
|
|
||||||
CppcheckOptionsPage::CppcheckOptionsPage(CppcheckTool &tool, CppcheckTrigger &trigger):
|
|
||||||
m_tool(tool),
|
|
||||||
m_trigger(trigger)
|
|
||||||
{
|
{
|
||||||
setId(Constants::OPTIONS_PAGE_ID);
|
setId(Constants::OPTIONS_PAGE_ID);
|
||||||
setDisplayName(Tr::tr("Cppcheck"));
|
setDisplayName(Tr::tr("Cppcheck"));
|
||||||
setCategory("T.Analyzer");
|
setCategory("T.Analyzer");
|
||||||
setDisplayCategory(::Debugger::Tr::tr("Analyzer"));
|
setDisplayCategory(::Debugger::Tr::tr("Analyzer"));
|
||||||
setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER);
|
setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER);
|
||||||
|
setSettingsGroup("Cppcheck");
|
||||||
|
|
||||||
setWidgetCreator([this] { return new CppcheckOptionsPageWidget(this); });
|
registerAspect(&binary);
|
||||||
|
binary.setSettingsKey("binary");
|
||||||
CppcheckOptions options;
|
binary.setDisplayStyle(StringAspect::PathChooserDisplay);
|
||||||
|
binary.setExpectedKind(PathChooser::ExistingCommand);
|
||||||
|
binary.setCommandVersionArguments({"--version"});
|
||||||
|
binary.setLabelText(Tr::tr("Binary:"));
|
||||||
if (HostOsInfo::isAnyUnixHost()) {
|
if (HostOsInfo::isAnyUnixHost()) {
|
||||||
options.binary = "cppcheck";
|
binary.setDefaultValue("cppcheck");
|
||||||
} else {
|
} else {
|
||||||
FilePath programFiles = FilePath::fromUserInput(qtcEnvironmentVariable("PROGRAMFILES"));
|
FilePath programFiles = FilePath::fromUserInput(qtcEnvironmentVariable("PROGRAMFILES"));
|
||||||
if (programFiles.isEmpty())
|
if (programFiles.isEmpty())
|
||||||
programFiles = "C:/Program Files";
|
programFiles = "C:/Program Files";
|
||||||
options.binary = programFiles / "Cppcheck/cppcheck.exe";
|
binary.setDefaultValue(programFiles.pathAppended("Cppcheck/cppcheck.exe").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
load(options);
|
registerAspect(&warning);
|
||||||
|
warning.setSettingsKey("warning");
|
||||||
|
warning.setDefaultValue(true);
|
||||||
|
warning.setLabelText(Tr::tr("Warnings"));
|
||||||
|
|
||||||
m_tool.updateOptions(options);
|
registerAspect(&style);
|
||||||
|
style.setSettingsKey("style");
|
||||||
|
style.setDefaultValue(true);
|
||||||
|
style.setLabelText(Tr::tr("Style"));
|
||||||
|
|
||||||
|
registerAspect(&performance);
|
||||||
|
performance.setSettingsKey("performance");
|
||||||
|
performance.setDefaultValue(true);
|
||||||
|
performance.setLabelText(Tr::tr("Performance"));
|
||||||
|
|
||||||
|
registerAspect(&portability);
|
||||||
|
portability.setSettingsKey("portability");
|
||||||
|
portability.setDefaultValue(true);
|
||||||
|
portability.setLabelText(Tr::tr("Portability"));
|
||||||
|
|
||||||
|
registerAspect(&information);
|
||||||
|
information.setSettingsKey("information");
|
||||||
|
information.setDefaultValue(true);
|
||||||
|
information.setLabelText(Tr::tr("Information"));
|
||||||
|
|
||||||
|
registerAspect(&unusedFunction);
|
||||||
|
unusedFunction.setSettingsKey("unusedFunction");
|
||||||
|
unusedFunction.setLabelText(Tr::tr("Unused functions"));
|
||||||
|
unusedFunction.setToolTip(Tr::tr("Disables multithreaded check."));
|
||||||
|
|
||||||
|
registerAspect(&missingInclude);
|
||||||
|
missingInclude.setSettingsKey("missingInclude");
|
||||||
|
missingInclude.setLabelText(Tr::tr("Missing includes"));
|
||||||
|
|
||||||
|
registerAspect(&inconclusive);
|
||||||
|
inconclusive.setSettingsKey("inconclusive");
|
||||||
|
inconclusive.setLabelText(Tr::tr("Inconclusive errors"));
|
||||||
|
|
||||||
|
registerAspect(&forceDefines);
|
||||||
|
forceDefines.setSettingsKey("forceDefines");
|
||||||
|
forceDefines.setLabelText(Tr::tr("Check all define combinations"));
|
||||||
|
|
||||||
|
registerAspect(&customArguments);
|
||||||
|
customArguments.setSettingsKey("customArguments");
|
||||||
|
customArguments.setDisplayStyle(StringAspect::LineEditDisplay);
|
||||||
|
customArguments.setLabelText(Tr::tr("Custom arguments:"));
|
||||||
|
|
||||||
|
registerAspect(&ignoredPatterns);
|
||||||
|
ignoredPatterns.setSettingsKey("ignoredPatterns");
|
||||||
|
ignoredPatterns.setDisplayStyle(StringAspect::LineEditDisplay);
|
||||||
|
ignoredPatterns.setLabelText(Tr::tr("Ignored file patterns:"));
|
||||||
|
ignoredPatterns.setToolTip(Tr::tr("Comma-separated wildcards of full file paths. "
|
||||||
|
"Files still can be checked if others include them."));
|
||||||
|
|
||||||
|
registerAspect(&showOutput);
|
||||||
|
showOutput.setSettingsKey("showOutput");
|
||||||
|
showOutput.setLabelText(Tr::tr("Show raw output"));
|
||||||
|
|
||||||
|
registerAspect(&addIncludePaths);
|
||||||
|
addIncludePaths.setSettingsKey("addIncludePaths");
|
||||||
|
addIncludePaths.setLabelText(Tr::tr("Add include paths"));
|
||||||
|
addIncludePaths.setToolTip(Tr::tr("Can find missing includes but makes "
|
||||||
|
"checking slower. Use only when needed."));
|
||||||
|
|
||||||
|
registerAspect(&guessArguments);
|
||||||
|
guessArguments.setSettingsKey("guessArguments");
|
||||||
|
guessArguments.setDefaultValue(true);
|
||||||
|
guessArguments.setLabelText(Tr::tr("Calculate additional arguments"));
|
||||||
|
guessArguments.setToolTip(Tr::tr("Like C++ standard and language."));
|
||||||
|
|
||||||
|
setLayouter(layouter());
|
||||||
|
|
||||||
|
readSettings(Core::ICore::settings());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppcheckOptionsPage::save(const CppcheckOptions &options) const
|
std::function<void(QWidget *widget)> CppcheckOptions::layouter()
|
||||||
{
|
{
|
||||||
QSettings *s = Core::ICore::settings();
|
return [this](QWidget *widget) {
|
||||||
QTC_ASSERT(s, return);
|
using namespace Layouting;
|
||||||
s->beginGroup(Constants::SETTINGS_ID);
|
Form {
|
||||||
s->setValue(Constants::SETTINGS_BINARY, options.binary.toString());
|
binary, br,
|
||||||
s->setValue(Constants::SETTINGS_CUSTOM_ARGUMENTS, options.customArguments);
|
Tr::tr("Checks:"), Flow {
|
||||||
s->setValue(Constants::SETTINGS_IGNORE_PATTERNS, options.ignoredPatterns);
|
warning,
|
||||||
s->setValue(Constants::SETTINGS_WARNING, options.warning);
|
style,
|
||||||
s->setValue(Constants::SETTINGS_STYLE, options.style);
|
performance,
|
||||||
s->setValue(Constants::SETTINGS_PERFORMANCE, options.performance);
|
portability,
|
||||||
s->setValue(Constants::SETTINGS_PORTABILITY, options.portability);
|
information,
|
||||||
s->setValue(Constants::SETTINGS_INFORMATION, options.information);
|
unusedFunction,
|
||||||
s->setValue(Constants::SETTINGS_UNUSED_FUNCTION, options.unusedFunction);
|
missingInclude
|
||||||
s->setValue(Constants::SETTINGS_MISSING_INCLUDE, options.missingInclude);
|
}, br,
|
||||||
s->setValue(Constants::SETTINGS_INCONCLUSIVE, options.inconclusive);
|
customArguments, br,
|
||||||
s->setValue(Constants::SETTINGS_FORCE_DEFINES, options.forceDefines);
|
ignoredPatterns, br,
|
||||||
s->setValue(Constants::SETTINGS_SHOW_OUTPUT, options.showOutput);
|
Flow {
|
||||||
s->setValue(Constants::SETTINGS_ADD_INCLUDE_PATHS, options.addIncludePaths);
|
inconclusive,
|
||||||
s->setValue(Constants::SETTINGS_GUESS_ARGUMENTS, options.guessArguments);
|
forceDefines,
|
||||||
s->endGroup();
|
showOutput,
|
||||||
|
addIncludePaths,
|
||||||
|
guessArguments
|
||||||
}
|
}
|
||||||
|
}.attachTo(widget);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Cppcheck::Internal
|
} // Cppcheck::Internal
|
||||||
|
|||||||
@@ -4,80 +4,35 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
#include <utils/filepath.h>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QLineEdit;
|
|
||||||
class QCheckBox;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace Utils { class PathChooser; }
|
|
||||||
|
|
||||||
namespace Cppcheck::Internal {
|
namespace Cppcheck::Internal {
|
||||||
|
|
||||||
class CppcheckTool;
|
class CppcheckTool;
|
||||||
class CppcheckTrigger;
|
class CppcheckTrigger;
|
||||||
class OptionsWidget;
|
|
||||||
|
|
||||||
class CppcheckOptions final
|
class CppcheckOptions final : public Core::PagedSettings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Utils::FilePath binary;
|
CppcheckOptions();
|
||||||
|
|
||||||
bool warning = true;
|
std::function<void(QWidget *widget)> layouter();
|
||||||
bool style = true;
|
|
||||||
bool performance = true;
|
|
||||||
bool portability = true;
|
|
||||||
bool information = true;
|
|
||||||
bool unusedFunction = false;
|
|
||||||
bool missingInclude = false;
|
|
||||||
bool inconclusive = false;
|
|
||||||
bool forceDefines = false;
|
|
||||||
|
|
||||||
QString customArguments;
|
Utils::StringAspect binary;
|
||||||
QString ignoredPatterns;
|
Utils::BoolAspect warning;
|
||||||
bool showOutput = false;
|
Utils::BoolAspect style;
|
||||||
bool addIncludePaths = false;
|
Utils::BoolAspect performance;
|
||||||
bool guessArguments = true;
|
Utils::BoolAspect portability;
|
||||||
};
|
Utils::BoolAspect information;
|
||||||
|
Utils::BoolAspect unusedFunction;
|
||||||
|
Utils::BoolAspect missingInclude;
|
||||||
|
Utils::BoolAspect inconclusive;
|
||||||
|
Utils::BoolAspect forceDefines;
|
||||||
|
|
||||||
class OptionsWidget final : public QWidget
|
Utils::StringAspect customArguments;
|
||||||
{
|
Utils::StringAspect ignoredPatterns;
|
||||||
public:
|
Utils::BoolAspect showOutput;
|
||||||
explicit OptionsWidget(QWidget *parent = nullptr);
|
Utils::BoolAspect addIncludePaths;
|
||||||
void load(const CppcheckOptions &options);
|
Utils::BoolAspect guessArguments;
|
||||||
void save(CppcheckOptions &options) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Utils::PathChooser *m_binary = nullptr;
|
|
||||||
QLineEdit *m_customArguments = nullptr;
|
|
||||||
QLineEdit *m_ignorePatterns = nullptr;
|
|
||||||
QCheckBox *m_warning = nullptr;
|
|
||||||
QCheckBox *m_style = nullptr;
|
|
||||||
QCheckBox *m_performance = nullptr;
|
|
||||||
QCheckBox *m_portability = nullptr;
|
|
||||||
QCheckBox *m_information = nullptr;
|
|
||||||
QCheckBox *m_unusedFunction = nullptr;
|
|
||||||
QCheckBox *m_missingInclude = nullptr;
|
|
||||||
QCheckBox *m_inconclusive = nullptr;
|
|
||||||
QCheckBox *m_forceDefines = nullptr;
|
|
||||||
QCheckBox *m_showOutput = nullptr;
|
|
||||||
QCheckBox *m_addIncludePaths = nullptr;
|
|
||||||
QCheckBox *m_guessArguments = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CppcheckOptionsPage final : public Core::IOptionsPage
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit CppcheckOptionsPage(CppcheckTool &tool, CppcheckTrigger &trigger);
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class CppcheckOptionsPageWidget;
|
|
||||||
void save(const CppcheckOptions &options) const;
|
|
||||||
void load(CppcheckOptions &options) const;
|
|
||||||
|
|
||||||
CppcheckTool &m_tool;
|
|
||||||
CppcheckTrigger &m_trigger;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Cppcheck::Internal
|
} // Cppcheck::Internal
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Cppcheck::Internal {
|
namespace Cppcheck::Internal {
|
||||||
|
|
||||||
class CppcheckPluginPrivate final : public QObject
|
class CppcheckPluginPrivate final : public QObject
|
||||||
@@ -36,11 +38,11 @@ public:
|
|||||||
explicit CppcheckPluginPrivate();
|
explicit CppcheckPluginPrivate();
|
||||||
|
|
||||||
CppcheckTextMarkManager marks;
|
CppcheckTextMarkManager marks;
|
||||||
CppcheckTool tool{marks, Constants::CHECK_PROGRESS_ID};
|
CppcheckOptions options;
|
||||||
|
CppcheckTool tool{options, marks, Constants::CHECK_PROGRESS_ID};
|
||||||
CppcheckTrigger trigger{marks, tool};
|
CppcheckTrigger trigger{marks, tool};
|
||||||
CppcheckOptionsPage options{tool, trigger};
|
|
||||||
DiagnosticsModel manualRunModel;
|
DiagnosticsModel manualRunModel;
|
||||||
CppcheckTool manualRunTool{manualRunModel, Constants::MANUAL_CHECK_PROGRESS_ID};
|
CppcheckTool manualRunTool{options, manualRunModel, Constants::MANUAL_CHECK_PROGRESS_ID};
|
||||||
Utils::Perspective perspective{Constants::PERSPECTIVE_ID, ::Cppcheck::Tr::tr("Cppcheck")};
|
Utils::Perspective perspective{Constants::PERSPECTIVE_ID, ::Cppcheck::Tr::tr("Cppcheck")};
|
||||||
|
|
||||||
QAction *manualRunAction;
|
QAction *manualRunAction;
|
||||||
@@ -51,7 +53,11 @@ public:
|
|||||||
|
|
||||||
CppcheckPluginPrivate::CppcheckPluginPrivate()
|
CppcheckPluginPrivate::CppcheckPluginPrivate()
|
||||||
{
|
{
|
||||||
manualRunTool.updateOptions(tool.options());
|
tool.updateOptions();
|
||||||
|
connect(&options, &AspectContainer::changed, [this] {
|
||||||
|
tool.updateOptions();
|
||||||
|
trigger.recheck();
|
||||||
|
});
|
||||||
|
|
||||||
auto manualRunView = new DiagnosticView;
|
auto manualRunView = new DiagnosticView;
|
||||||
manualRunView->setModel(&manualRunModel);
|
manualRunView->setModel(&manualRunModel);
|
||||||
@@ -103,7 +109,12 @@ void CppcheckPluginPrivate::startManualRun()
|
|||||||
if (!project)
|
if (!project)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ManualRunDialog dialog(manualRunTool.options(), project);
|
manualRunTool.updateOptions();
|
||||||
|
|
||||||
|
auto optionsWidget = new QWidget;
|
||||||
|
options.layouter()(optionsWidget);
|
||||||
|
|
||||||
|
ManualRunDialog dialog(optionsWidget, project);
|
||||||
if (dialog.exec() == ManualRunDialog::Rejected)
|
if (dialog.exec() == ManualRunDialog::Rejected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -114,7 +125,7 @@ void CppcheckPluginPrivate::startManualRun()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
manualRunTool.setProject(project);
|
manualRunTool.setProject(project);
|
||||||
manualRunTool.updateOptions(dialog.options());
|
manualRunTool.updateOptions();
|
||||||
manualRunTool.check(files);
|
manualRunTool.check(files);
|
||||||
perspective.select();
|
perspective.select();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace Cppcheck::Internal {
|
namespace Cppcheck::Internal {
|
||||||
|
|
||||||
CppcheckTool::CppcheckTool(CppcheckDiagnosticManager &manager, const Id &progressId) :
|
CppcheckTool::CppcheckTool(CppcheckOptions &options, CppcheckDiagnosticManager &manager, const Id &progressId) :
|
||||||
|
m_options(options),
|
||||||
m_manager(manager),
|
m_manager(manager),
|
||||||
m_progressRegexp("^.* checked (\\d+)% done$"),
|
m_progressRegexp("^.* checked (\\d+)% done$"),
|
||||||
m_messageRegexp("^(.+),(\\d+),(\\w+),(\\w+),(.*)$"),
|
m_messageRegexp("^(.+),(\\d+),(\\w+),(\\w+),(.*)$"),
|
||||||
@@ -39,11 +40,10 @@ CppcheckTool::CppcheckTool(CppcheckDiagnosticManager &manager, const Id &progres
|
|||||||
|
|
||||||
CppcheckTool::~CppcheckTool() = default;
|
CppcheckTool::~CppcheckTool() = default;
|
||||||
|
|
||||||
void CppcheckTool::updateOptions(const CppcheckOptions &options)
|
void CppcheckTool::updateOptions()
|
||||||
{
|
{
|
||||||
m_options = options;
|
|
||||||
m_filters.clear();
|
m_filters.clear();
|
||||||
for (const QString &pattern : m_options.ignoredPatterns.split(',')) {
|
for (const QString &pattern : m_options.ignoredPatterns().split(',')) {
|
||||||
const QString trimmedPattern = pattern.trimmed();
|
const QString trimmedPattern = pattern.trimmed();
|
||||||
if (trimmedPattern.isEmpty())
|
if (trimmedPattern.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
@@ -70,44 +70,44 @@ void CppcheckTool::updateArguments()
|
|||||||
m_cachedAdditionalArguments.clear();
|
m_cachedAdditionalArguments.clear();
|
||||||
|
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
if (!m_options.customArguments.isEmpty()) {
|
if (!m_options.customArguments().isEmpty()) {
|
||||||
Utils::MacroExpander *expander = Utils::globalMacroExpander();
|
Utils::MacroExpander *expander = Utils::globalMacroExpander();
|
||||||
const QString expanded = expander->expand(m_options.customArguments);
|
const QString expanded = expander->expand(m_options.customArguments());
|
||||||
arguments.push_back(expanded);
|
arguments.push_back(expanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_options.warning)
|
if (m_options.warning())
|
||||||
arguments.push_back("--enable=warning");
|
arguments.push_back("--enable=warning");
|
||||||
if (m_options.style)
|
if (m_options.style())
|
||||||
arguments.push_back("--enable=style");
|
arguments.push_back("--enable=style");
|
||||||
if (m_options.performance)
|
if (m_options.performance())
|
||||||
arguments.push_back("--enable=performance");
|
arguments.push_back("--enable=performance");
|
||||||
if (m_options.portability)
|
if (m_options.portability())
|
||||||
arguments.push_back("--enable=portability");
|
arguments.push_back("--enable=portability");
|
||||||
if (m_options.information)
|
if (m_options.information())
|
||||||
arguments.push_back("--enable=information");
|
arguments.push_back("--enable=information");
|
||||||
if (m_options.unusedFunction)
|
if (m_options.unusedFunction())
|
||||||
arguments.push_back("--enable=unusedFunction");
|
arguments.push_back("--enable=unusedFunction");
|
||||||
if (m_options.missingInclude)
|
if (m_options.missingInclude())
|
||||||
arguments.push_back("--enable=missingInclude");
|
arguments.push_back("--enable=missingInclude");
|
||||||
if (m_options.inconclusive)
|
if (m_options.inconclusive())
|
||||||
arguments.push_back("--inconclusive");
|
arguments.push_back("--inconclusive");
|
||||||
if (m_options.forceDefines)
|
if (m_options.forceDefines())
|
||||||
arguments.push_back("--force");
|
arguments.push_back("--force");
|
||||||
|
|
||||||
if (!m_options.unusedFunction && !m_options.customArguments.contains("-j "))
|
if (!m_options.unusedFunction() && !m_options.customArguments().contains("-j "))
|
||||||
arguments.push_back("-j " + QString::number(QThread::idealThreadCount()));
|
arguments.push_back("-j " + QString::number(QThread::idealThreadCount()));
|
||||||
|
|
||||||
arguments.push_back("--template=\"{file},{line},{severity},{id},{message}\"");
|
arguments.push_back("--template=\"{file},{line},{severity},{id},{message}\"");
|
||||||
|
|
||||||
m_runner->reconfigure(m_options.binary, arguments.join(' '));
|
m_runner->reconfigure(m_options.binary.filePath(), arguments.join(' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList CppcheckTool::additionalArguments(const CppEditor::ProjectPart &part) const
|
QStringList CppcheckTool::additionalArguments(const CppEditor::ProjectPart &part) const
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
|
|
||||||
if (m_options.addIncludePaths) {
|
if (m_options.addIncludePaths()) {
|
||||||
for (const ProjectExplorer::HeaderPath &path : part.headerPaths) {
|
for (const ProjectExplorer::HeaderPath &path : part.headerPaths) {
|
||||||
const QString projectDir = m_project->projectDirectory().toString();
|
const QString projectDir = m_project->projectDirectory().toString();
|
||||||
if (path.type == ProjectExplorer::HeaderPathType::User
|
if (path.type == ProjectExplorer::HeaderPathType::User
|
||||||
@@ -116,7 +116,7 @@ QStringList CppcheckTool::additionalArguments(const CppEditor::ProjectPart &part
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_options.guessArguments)
|
if (!m_options.guessArguments())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
using Version = Utils::LanguageVersion;
|
using Version = Utils::LanguageVersion;
|
||||||
@@ -158,11 +158,6 @@ QStringList CppcheckTool::additionalArguments(const CppEditor::ProjectPart &part
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CppcheckOptions &CppcheckTool::options() const
|
|
||||||
{
|
|
||||||
return m_options;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppcheckTool::check(const Utils::FilePaths &files)
|
void CppcheckTool::check(const Utils::FilePaths &files)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_project, return);
|
QTC_ASSERT(m_project, return);
|
||||||
@@ -226,7 +221,7 @@ void CppcheckTool::stop(const Utils::FilePaths &files)
|
|||||||
|
|
||||||
void CppcheckTool::startParsing()
|
void CppcheckTool::startParsing()
|
||||||
{
|
{
|
||||||
if (m_options.showOutput) {
|
if (m_options.showOutput()) {
|
||||||
const QString message = Tr::tr("Cppcheck started: \"%1\".").arg(m_runner->currentCommand());
|
const QString message = Tr::tr("Cppcheck started: \"%1\".").arg(m_runner->currentCommand());
|
||||||
Core::MessageManager::writeSilently(message);
|
Core::MessageManager::writeSilently(message);
|
||||||
}
|
}
|
||||||
@@ -245,7 +240,7 @@ void CppcheckTool::parseOutputLine(const QString &line)
|
|||||||
if (line.isEmpty())
|
if (line.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_options.showOutput)
|
if (m_options.showOutput())
|
||||||
Core::MessageManager::writeSilently(line);
|
Core::MessageManager::writeSilently(line);
|
||||||
|
|
||||||
enum Matches { Percentage = 1 };
|
enum Matches { Percentage = 1 };
|
||||||
@@ -276,7 +271,7 @@ void CppcheckTool::parseErrorLine(const QString &line)
|
|||||||
if (line.isEmpty())
|
if (line.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_options.showOutput)
|
if (m_options.showOutput())
|
||||||
Core::MessageManager::writeSilently(line);
|
Core::MessageManager::writeSilently(line);
|
||||||
|
|
||||||
enum Matches { File = 1, Line, Severity, Id, Message };
|
enum Matches { File = 1, Line, Severity, Id, Message };
|
||||||
@@ -301,7 +296,7 @@ void CppcheckTool::parseErrorLine(const QString &line)
|
|||||||
|
|
||||||
void CppcheckTool::finishParsing()
|
void CppcheckTool::finishParsing()
|
||||||
{
|
{
|
||||||
if (m_options.showOutput)
|
if (m_options.showOutput())
|
||||||
Core::MessageManager::writeSilently(Tr::tr("Cppcheck finished."));
|
Core::MessageManager::writeSilently(Tr::tr("Cppcheck finished."));
|
||||||
|
|
||||||
QTC_ASSERT(m_progress, return);
|
QTC_ASSERT(m_progress, return);
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ class CppcheckTool final : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CppcheckTool(CppcheckDiagnosticManager &manager, const Utils::Id &progressId);
|
CppcheckTool(CppcheckOptions &options, CppcheckDiagnosticManager &manager, const Utils::Id &progressId);
|
||||||
~CppcheckTool() override;
|
~CppcheckTool() override;
|
||||||
|
|
||||||
void updateOptions(const CppcheckOptions &options);
|
void updateOptions();
|
||||||
void setProject(ProjectExplorer::Project *project);
|
void setProject(ProjectExplorer::Project *project);
|
||||||
void check(const Utils::FilePaths &files);
|
void check(const Utils::FilePaths &files);
|
||||||
void stop(const Utils::FilePaths &files);
|
void stop(const Utils::FilePaths &files);
|
||||||
@@ -44,15 +44,13 @@ public:
|
|||||||
void parseErrorLine(const QString &line);
|
void parseErrorLine(const QString &line);
|
||||||
void finishParsing();
|
void finishParsing();
|
||||||
|
|
||||||
const CppcheckOptions &options() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateArguments();
|
void updateArguments();
|
||||||
void addToQueue(const Utils::FilePaths &files, const CppEditor::ProjectPart &part);
|
void addToQueue(const Utils::FilePaths &files, const CppEditor::ProjectPart &part);
|
||||||
QStringList additionalArguments(const CppEditor::ProjectPart &part) const;
|
QStringList additionalArguments(const CppEditor::ProjectPart &part) const;
|
||||||
|
|
||||||
|
CppcheckOptions &m_options;
|
||||||
CppcheckDiagnosticManager &m_manager;
|
CppcheckDiagnosticManager &m_manager;
|
||||||
CppcheckOptions m_options;
|
|
||||||
QPointer<ProjectExplorer::Project> m_project;
|
QPointer<ProjectExplorer::Project> m_project;
|
||||||
std::unique_ptr<CppcheckRunner> m_runner;
|
std::unique_ptr<CppcheckRunner> m_runner;
|
||||||
std::unique_ptr<QFutureInterface<void>> m_progress;
|
std::unique_ptr<QFutureInterface<void>> m_progress;
|
||||||
|
|||||||
Reference in New Issue
Block a user