aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cppcheck
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2023-07-17 08:44:12 +0200
committerhjk <hjk@qt.io>2023-07-18 08:43:45 +0000
commit8e7ac2e59db0f1cfcd1f28dac9f0ddd8ef7384f6 (patch)
tree584be429e30585980bfd9b8ebbf5396900491f88 /src/plugins/cppcheck
parentbce9b9ffaacc6b355bd4278356a8cd03a3816627 (diff)
CppCheck: Use new settings pattern
Change-Id: Ia2de8e684690ab7bfbdcf7ba417df1f2174433de Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/cppcheck')
-rw-r--r--src/plugins/cppcheck/cppcheckoptions.cpp33
-rw-r--r--src/plugins/cppcheck/cppcheckoptions.h11
-rw-r--r--src/plugins/cppcheck/cppcheckplugin.cpp10
-rw-r--r--src/plugins/cppcheck/cppchecktool.cpp45
-rw-r--r--src/plugins/cppcheck/cppchecktool.h6
5 files changed, 64 insertions, 41 deletions
diff --git a/src/plugins/cppcheck/cppcheckoptions.cpp b/src/plugins/cppcheck/cppcheckoptions.cpp
index 214d4b3c229..cf3cdc5c761 100644
--- a/src/plugins/cppcheck/cppcheckoptions.cpp
+++ b/src/plugins/cppcheck/cppcheckoptions.cpp
@@ -16,6 +16,7 @@
#include <utils/qtcassert.h>
#include <utils/variablechooser.h>
+#include <coreplugin/dialogs/ioptionspage.h>
#include <coreplugin/icore.h>
#include <debugger/analyzer/analyzericons.h>
@@ -25,14 +26,16 @@ using namespace Utils;
namespace Cppcheck::Internal {
-CppcheckOptions::CppcheckOptions()
+CppcheckSettings &settings()
+{
+ static CppcheckSettings theSettings;
+ return theSettings;
+}
+
+CppcheckSettings::CppcheckSettings()
{
- setId(Constants::OPTIONS_PAGE_ID);
- setDisplayName(Tr::tr("Cppcheck"));
- setCategory("T.Analyzer");
- setDisplayCategory(::Debugger::Tr::tr("Analyzer"));
- setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER);
setSettingsGroup("Cppcheck");
+ setAutoApply(false);
binary.setSettingsKey("binary");
binary.setExpectedKind(PathChooser::ExistingCommand);
@@ -108,7 +111,7 @@ CppcheckOptions::CppcheckOptions()
readSettings();
}
-std::function<Layouting::LayoutItem()> CppcheckOptions::layouter()
+std::function<Layouting::LayoutItem()> CppcheckSettings::layouter()
{
return [this] {
using namespace Layouting;
@@ -136,4 +139,20 @@ std::function<Layouting::LayoutItem()> CppcheckOptions::layouter()
};
}
+class CppCheckSettingsPage final : public Core::IOptionsPage
+{
+public:
+ CppCheckSettingsPage()
+ {
+ setId(Constants::OPTIONS_PAGE_ID);
+ setDisplayName(Tr::tr("Cppcheck"));
+ setCategory("T.Analyzer");
+ setDisplayCategory(::Debugger::Tr::tr("Analyzer"));
+ setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER);
+ setSettingsProvider([] { return &settings(); });
+ }
+};
+
+const CppCheckSettingsPage settingsPage;
+
} // Cppcheck::Internal
diff --git a/src/plugins/cppcheck/cppcheckoptions.h b/src/plugins/cppcheck/cppcheckoptions.h
index eb3e1c7ddbf..8842b2b65f2 100644
--- a/src/plugins/cppcheck/cppcheckoptions.h
+++ b/src/plugins/cppcheck/cppcheckoptions.h
@@ -3,14 +3,16 @@
#pragma once
-#include <coreplugin/dialogs/ioptionspage.h>
+#include <utils/aspects.h>
+
+#include <functional>
namespace Cppcheck::Internal {
-class CppcheckOptions final : public Core::PagedSettings
+class CppcheckSettings final : public Utils::AspectContainer
{
public:
- CppcheckOptions();
+ CppcheckSettings();
std::function<Layouting::LayoutItem()> layouter();
@@ -32,4 +34,7 @@ public:
Utils::BoolAspect guessArguments{this};
};
+CppcheckSettings &settings();
+
+
} // Cppcheck::Internal
diff --git a/src/plugins/cppcheck/cppcheckplugin.cpp b/src/plugins/cppcheck/cppcheckplugin.cpp
index b025762c8c6..33f6e3b7863 100644
--- a/src/plugins/cppcheck/cppcheckplugin.cpp
+++ b/src/plugins/cppcheck/cppcheckplugin.cpp
@@ -5,6 +5,7 @@
#include "cppcheckconstants.h"
#include "cppcheckdiagnosticview.h"
+#include "cppcheckoptions.h"
#include "cppchecktextmarkmanager.h"
#include "cppchecktool.h"
#include "cppchecktr.h"
@@ -39,11 +40,10 @@ public:
explicit CppcheckPluginPrivate();
CppcheckTextMarkManager marks;
- CppcheckOptions options;
- CppcheckTool tool{options, marks, Constants::CHECK_PROGRESS_ID};
+ CppcheckTool tool{marks, Constants::CHECK_PROGRESS_ID};
CppcheckTrigger trigger{marks, tool};
DiagnosticsModel manualRunModel;
- CppcheckTool manualRunTool{options, manualRunModel, Constants::MANUAL_CHECK_PROGRESS_ID};
+ CppcheckTool manualRunTool{manualRunModel, Constants::MANUAL_CHECK_PROGRESS_ID};
Utils::Perspective perspective{Constants::PERSPECTIVE_ID, ::Cppcheck::Tr::tr("Cppcheck")};
QAction *manualRunAction;
@@ -55,7 +55,7 @@ public:
CppcheckPluginPrivate::CppcheckPluginPrivate()
{
tool.updateOptions();
- connect(&options, &AspectContainer::changed, [this] {
+ connect(&settings(), &AspectContainer::changed, [this] {
tool.updateOptions();
trigger.recheck();
});
@@ -112,7 +112,7 @@ void CppcheckPluginPrivate::startManualRun()
manualRunTool.updateOptions();
- auto optionsWidget = options.layouter()().emerge();
+ auto optionsWidget = settings().layouter()().emerge();
ManualRunDialog dialog(optionsWidget, project);
if (dialog.exec() == ManualRunDialog::Rejected)
diff --git a/src/plugins/cppcheck/cppchecktool.cpp b/src/plugins/cppcheck/cppchecktool.cpp
index 79e5a3e5b6e..bed43a98107 100644
--- a/src/plugins/cppcheck/cppchecktool.cpp
+++ b/src/plugins/cppcheck/cppchecktool.cpp
@@ -26,8 +26,7 @@ using namespace Utils;
namespace Cppcheck::Internal {
-CppcheckTool::CppcheckTool(CppcheckOptions &options, CppcheckDiagnosticManager &manager, const Id &progressId) :
- m_options(options),
+CppcheckTool::CppcheckTool(CppcheckDiagnosticManager &manager, const Id &progressId) :
m_manager(manager),
m_progressRegexp("^.* checked (\\d+)% done$"),
m_messageRegexp("^(.+),(\\d+),(\\w+),(\\w+),(.*)$"),
@@ -43,7 +42,7 @@ CppcheckTool::~CppcheckTool() = default;
void CppcheckTool::updateOptions()
{
m_filters.clear();
- for (const QString &pattern : m_options.ignoredPatterns().split(',')) {
+ for (const QString &pattern : settings().ignoredPatterns().split(',')) {
const QString trimmedPattern = pattern.trimmed();
if (trimmedPattern.isEmpty())
continue;
@@ -69,45 +68,47 @@ void CppcheckTool::updateArguments()
m_cachedAdditionalArguments.clear();
+ CppcheckSettings &s = settings();
+
QStringList arguments;
- if (!m_options.customArguments().isEmpty()) {
+ if (!s.customArguments().isEmpty()) {
Utils::MacroExpander *expander = Utils::globalMacroExpander();
- const QString expanded = expander->expand(m_options.customArguments());
+ const QString expanded = expander->expand(s.customArguments());
arguments.push_back(expanded);
}
- if (m_options.warning())
+ if (s.warning())
arguments.push_back("--enable=warning");
- if (m_options.style())
+ if (s.style())
arguments.push_back("--enable=style");
- if (m_options.performance())
+ if (s.performance())
arguments.push_back("--enable=performance");
- if (m_options.portability())
+ if (s.portability())
arguments.push_back("--enable=portability");
- if (m_options.information())
+ if (s.information())
arguments.push_back("--enable=information");
- if (m_options.unusedFunction())
+ if (s.unusedFunction())
arguments.push_back("--enable=unusedFunction");
- if (m_options.missingInclude())
+ if (s.missingInclude())
arguments.push_back("--enable=missingInclude");
- if (m_options.inconclusive())
+ if (s.inconclusive())
arguments.push_back("--inconclusive");
- if (m_options.forceDefines())
+ if (s.forceDefines())
arguments.push_back("--force");
- if (!m_options.unusedFunction() && !m_options.customArguments().contains("-j "))
+ if (!s.unusedFunction() && !s.customArguments().contains("-j "))
arguments.push_back("-j " + QString::number(QThread::idealThreadCount()));
arguments.push_back("--template=\"{file},{line},{severity},{id},{message}\"");
- m_runner->reconfigure(m_options.binary(), arguments.join(' '));
+ m_runner->reconfigure(s.binary(), arguments.join(' '));
}
QStringList CppcheckTool::additionalArguments(const CppEditor::ProjectPart &part) const
{
QStringList result;
- if (m_options.addIncludePaths()) {
+ if (settings().addIncludePaths()) {
for (const ProjectExplorer::HeaderPath &path : part.headerPaths) {
const QString projectDir = m_project->projectDirectory().toString();
if (path.type == ProjectExplorer::HeaderPathType::User
@@ -116,7 +117,7 @@ QStringList CppcheckTool::additionalArguments(const CppEditor::ProjectPart &part
}
}
- if (!m_options.guessArguments())
+ if (!settings().guessArguments())
return result;
using Version = Utils::LanguageVersion;
@@ -221,7 +222,7 @@ void CppcheckTool::stop(const Utils::FilePaths &files)
void CppcheckTool::startParsing()
{
- if (m_options.showOutput()) {
+ if (settings().showOutput()) {
const QString message = Tr::tr("Cppcheck started: \"%1\".").arg(m_runner->currentCommand());
Core::MessageManager::writeSilently(message);
}
@@ -240,7 +241,7 @@ void CppcheckTool::parseOutputLine(const QString &line)
if (line.isEmpty())
return;
- if (m_options.showOutput())
+ if (settings().showOutput())
Core::MessageManager::writeSilently(line);
enum Matches { Percentage = 1 };
@@ -271,7 +272,7 @@ void CppcheckTool::parseErrorLine(const QString &line)
if (line.isEmpty())
return;
- if (m_options.showOutput())
+ if (settings().showOutput())
Core::MessageManager::writeSilently(line);
enum Matches { File = 1, Line, Severity, Id, Message };
@@ -296,7 +297,7 @@ void CppcheckTool::parseErrorLine(const QString &line)
void CppcheckTool::finishParsing()
{
- if (m_options.showOutput())
+ if (settings().showOutput())
Core::MessageManager::writeSilently(Tr::tr("Cppcheck finished."));
QTC_ASSERT(m_progress, return);
diff --git a/src/plugins/cppcheck/cppchecktool.h b/src/plugins/cppcheck/cppchecktool.h
index 4dc6699e336..d14485fd5e8 100644
--- a/src/plugins/cppcheck/cppchecktool.h
+++ b/src/plugins/cppcheck/cppchecktool.h
@@ -3,7 +3,7 @@
#pragma once
-#include <cppcheck/cppcheckoptions.h>
+#include <utils/id.h>
#include <QFutureInterface>
#include <QPointer>
@@ -24,14 +24,13 @@ namespace Cppcheck::Internal {
class CppcheckRunner;
class CppcheckDiagnosticManager;
-class CppcheckOptions;
class CppcheckTool final : public QObject
{
Q_OBJECT
public:
- CppcheckTool(CppcheckOptions &options, CppcheckDiagnosticManager &manager, const Utils::Id &progressId);
+ CppcheckTool(CppcheckDiagnosticManager &manager, const Utils::Id &progressId);
~CppcheckTool() override;
void updateOptions();
@@ -49,7 +48,6 @@ private:
void addToQueue(const Utils::FilePaths &files, const CppEditor::ProjectPart &part);
QStringList additionalArguments(const CppEditor::ProjectPart &part) const;
- CppcheckOptions &m_options;
CppcheckDiagnosticManager &m_manager;
QPointer<ProjectExplorer::Project> m_project;
std::unique_ptr<CppcheckRunner> m_runner;