ClangToolsSettings: Reuse ClangToolType enum

Change-Id: I24d7bde71ccf3fc3ea33b78e0ed629fa0ce90c04
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2023-01-10 15:51:31 +01:00
parent 7ef8d8313d
commit 0ba3dbf1be
4 changed files with 20 additions and 18 deletions

View File

@@ -174,16 +174,20 @@ void ClangToolsSettings::writeSettings()
emit changed(); emit changed();
} }
void ClangToolsSettings::setClangTidyExecutable(const FilePath &path) FilePath ClangToolsSettings::executable(ClangToolType tool) const
{ {
m_clangTidyExecutable = path; return tool == ClangToolType::Tidy ? m_clangTidyExecutable : m_clazyStandaloneExecutable;
m_clangTidyVersion = {};
} }
void ClangToolsSettings::setClazyStandaloneExecutable(const FilePath &path) void ClangToolsSettings::setExecutable(ClangToolType tool, const FilePath &path)
{ {
if (tool == ClangToolType::Tidy) {
m_clangTidyExecutable = path;
m_clangTidyVersion = {};
} else {
m_clazyStandaloneExecutable = path; m_clazyStandaloneExecutable = path;
m_clazyVersion = {}; m_clazyVersion = {};
}
} }
static VersionAndSuffix getVersionNumber(VersionAndSuffix &version, const FilePath &toolFilePath) static VersionAndSuffix getVersionNumber(VersionAndSuffix &version, const FilePath &toolFilePath)

View File

@@ -57,11 +57,8 @@ public:
static ClangToolsSettings *instance(); static ClangToolsSettings *instance();
void writeSettings(); void writeSettings();
Utils::FilePath clangTidyExecutable() const { return m_clangTidyExecutable; } Utils::FilePath executable(CppEditor::ClangToolType tool) const;
void setClangTidyExecutable(const Utils::FilePath &path); void setExecutable(CppEditor::ClangToolType tool, const Utils::FilePath &path);
Utils::FilePath clazyStandaloneExecutable() const { return m_clazyStandaloneExecutable; }
void setClazyStandaloneExecutable(const Utils::FilePath &path);
CppEditor::ClangDiagnosticConfigs diagnosticConfigs() const { return m_diagnosticConfigs; } CppEditor::ClangDiagnosticConfigs diagnosticConfigs() const { return m_diagnosticConfigs; }
void setDiagnosticConfigs(const CppEditor::ClangDiagnosticConfigs &configs) void setDiagnosticConfigs(const CppEditor::ClangDiagnosticConfigs &configs)

View File

@@ -200,7 +200,7 @@ FilePath clangTidyFallbackExecutable()
FilePath clangTidyExecutable() FilePath clangTidyExecutable()
{ {
const FilePath fromSettings = ClangToolsSettings::instance()->clangTidyExecutable(); const FilePath fromSettings = ClangToolsSettings::instance()->executable(ClangToolType::Tidy);
if (!fromSettings.isEmpty()) if (!fromSettings.isEmpty())
return fullPath(fromSettings); return fullPath(fromSettings);
return clangTidyFallbackExecutable(); return clangTidyFallbackExecutable();
@@ -216,7 +216,7 @@ FilePath clazyStandaloneFallbackExecutable()
FilePath clazyStandaloneExecutable() FilePath clazyStandaloneExecutable()
{ {
const FilePath fromSettings = ClangToolsSettings::instance()->clazyStandaloneExecutable(); const FilePath fromSettings = ClangToolsSettings::instance()->executable(ClangToolType::Clazy);
if (!fromSettings.isEmpty()) if (!fromSettings.isEmpty())
return fullPath(fromSettings); return fullPath(fromSettings);
return clazyStandaloneFallbackExecutable(); return clazyStandaloneFallbackExecutable();

View File

@@ -17,6 +17,7 @@
#include <QCoreApplication> #include <QCoreApplication>
using namespace CppEditor;
using namespace Utils; using namespace Utils;
namespace ClangTools::Internal { namespace ClangTools::Internal {
@@ -36,7 +37,7 @@ SettingsWidget::SettingsWidget()
resize(400, 300); resize(400, 300);
QString placeHolderText = shippedClangTidyExecutable().toUserOutput(); QString placeHolderText = shippedClangTidyExecutable().toUserOutput();
FilePath path = m_settings->clangTidyExecutable(); FilePath path = m_settings->executable(ClangToolType::Tidy);
if (path.isEmpty() && placeHolderText.isEmpty()) if (path.isEmpty() && placeHolderText.isEmpty())
path = Constants::CLANG_TIDY_EXECUTABLE_NAME; path = Constants::CLANG_TIDY_EXECUTABLE_NAME;
m_clangTidyPathChooser = new PathChooser; m_clangTidyPathChooser = new PathChooser;
@@ -47,7 +48,7 @@ SettingsWidget::SettingsWidget()
m_clangTidyPathChooser->setHistoryCompleter("ClangTools.ClangTidyExecutable.History"); m_clangTidyPathChooser->setHistoryCompleter("ClangTools.ClangTidyExecutable.History");
placeHolderText = shippedClazyStandaloneExecutable().toUserOutput(); placeHolderText = shippedClazyStandaloneExecutable().toUserOutput();
path = m_settings->clazyStandaloneExecutable(); path = m_settings->executable(ClangToolType::Clazy);
if (path.isEmpty() && placeHolderText.isEmpty()) if (path.isEmpty() && placeHolderText.isEmpty())
path = Constants::CLAZY_STANDALONE_EXECUTABLE_NAME; path = Constants::CLAZY_STANDALONE_EXECUTABLE_NAME;
m_clazyStandalonePathChooser = new PathChooser; m_clazyStandalonePathChooser = new PathChooser;
@@ -78,14 +79,14 @@ SettingsWidget::SettingsWidget()
void SettingsWidget::apply() void SettingsWidget::apply()
{ {
// Executables // Executables
m_settings->setClangTidyExecutable(clangTidyPath()); m_settings->setExecutable(ClangToolType::Tidy, clangTidyPath());
m_settings->setClazyStandaloneExecutable(clazyStandalonePath()); m_settings->setExecutable(ClangToolType::Clazy, clazyStandalonePath());
// Run options // Run options
m_settings->setRunSettings(m_runSettingsWidget->toSettings()); m_settings->setRunSettings(m_runSettingsWidget->toSettings());
// Custom configs // Custom configs
const CppEditor::ClangDiagnosticConfigs customConfigs const ClangDiagnosticConfigs customConfigs
= m_runSettingsWidget->diagnosticSelectionWidget()->customConfigs(); = m_runSettingsWidget->diagnosticSelectionWidget()->customConfigs();
m_settings->setDiagnosticConfigs(customConfigs); m_settings->setDiagnosticConfigs(customConfigs);