2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2019 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2019-09-13 10:49:14 +02:00
|
|
|
|
|
|
|
|
#include "runsettingswidget.h"
|
|
|
|
|
|
|
|
|
|
#include "clangtoolssettings.h"
|
2023-01-19 18:42:01 +01:00
|
|
|
#include "clangtoolstr.h"
|
2019-09-13 10:49:14 +02:00
|
|
|
#include "clangtoolsutils.h"
|
2019-10-21 14:59:57 +02:00
|
|
|
#include "diagnosticconfigswidget.h"
|
|
|
|
|
#include "executableinfo.h"
|
|
|
|
|
#include "settingswidget.h"
|
|
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <cppeditor/clangdiagnosticconfigswidget.h>
|
2022-09-26 16:36:15 +02:00
|
|
|
#include <cppeditor/clangdiagnosticconfigsselectionwidget.h>
|
2019-09-13 10:49:14 +02:00
|
|
|
|
2022-09-26 16:36:15 +02:00
|
|
|
#include <utils/layoutbuilder.h>
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QSpinBox>
|
2019-09-13 10:49:14 +02:00
|
|
|
#include <QThread>
|
|
|
|
|
|
2023-01-10 16:36:59 +01:00
|
|
|
using namespace CppEditor;
|
2021-08-12 09:19:55 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2022-09-26 16:36:15 +02:00
|
|
|
namespace ClangTools::Internal {
|
2019-09-13 10:49:14 +02:00
|
|
|
|
|
|
|
|
RunSettingsWidget::RunSettingsWidget(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
{
|
2022-09-26 16:36:15 +02:00
|
|
|
resize(383, 125);
|
2019-09-13 10:49:14 +02:00
|
|
|
|
2023-01-10 16:36:59 +01:00
|
|
|
m_diagnosticWidget = new ClangDiagnosticConfigsSelectionWidget;
|
2023-04-11 12:49:21 +02:00
|
|
|
m_preferConfigFile = new QCheckBox(Tr::tr("Prefer .clang-tidy file, if present"));
|
2023-01-19 18:42:01 +01:00
|
|
|
m_buildBeforeAnalysis = new QCheckBox(Tr::tr("Build the project before analysis"));
|
|
|
|
|
m_analyzeOpenFiles = new QCheckBox(Tr::tr("Analyze open files"));
|
2022-09-26 16:36:15 +02:00
|
|
|
m_parallelJobsSpinBox = new QSpinBox;
|
|
|
|
|
m_parallelJobsSpinBox->setRange(1, 32);
|
|
|
|
|
|
|
|
|
|
using namespace Layouting;
|
|
|
|
|
|
|
|
|
|
// FIXME: Let RunSettingsWidget inherit from QGroupBox?
|
|
|
|
|
Column {
|
|
|
|
|
Group {
|
2023-01-19 18:42:01 +01:00
|
|
|
title(Tr::tr("Run Options")),
|
2022-09-26 16:36:15 +02:00
|
|
|
Column {
|
|
|
|
|
m_diagnosticWidget,
|
2023-04-11 12:49:21 +02:00
|
|
|
m_preferConfigFile,
|
2022-09-26 16:36:15 +02:00
|
|
|
m_buildBeforeAnalysis,
|
|
|
|
|
m_analyzeOpenFiles,
|
2023-01-19 18:42:01 +01:00
|
|
|
Row { Tr::tr("Parallel jobs:"), m_parallelJobsSpinBox, st },
|
2022-09-26 16:36:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}.attachTo(this, WithoutMargins);
|
2019-09-13 10:49:14 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-26 16:36:15 +02:00
|
|
|
RunSettingsWidget::~RunSettingsWidget() = default;
|
|
|
|
|
|
2023-01-10 16:36:59 +01:00
|
|
|
ClangDiagnosticConfigsSelectionWidget *RunSettingsWidget::diagnosticSelectionWidget()
|
2019-10-01 16:53:01 +02:00
|
|
|
{
|
2022-09-26 16:36:15 +02:00
|
|
|
return m_diagnosticWidget;
|
2019-10-01 16:53:01 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-10 16:36:59 +01:00
|
|
|
static ClangDiagnosticConfigsWidget *createEditWidget(const ClangDiagnosticConfigs &configs,
|
|
|
|
|
const Id &configToSelect)
|
2019-10-21 14:59:57 +02:00
|
|
|
{
|
|
|
|
|
// Determine executable paths
|
2021-08-12 09:19:55 +02:00
|
|
|
FilePath clangTidyPath;
|
|
|
|
|
FilePath clazyStandalonePath;
|
2019-10-21 14:59:57 +02:00
|
|
|
if (auto settingsWidget = SettingsWidget::instance()) {
|
|
|
|
|
// Global settings case; executables might not yet applied to settings
|
|
|
|
|
clangTidyPath = settingsWidget->clangTidyPath();
|
2023-01-10 16:36:59 +01:00
|
|
|
clangTidyPath = clangTidyPath.isEmpty() ? toolFallbackExecutable(ClangToolType::Tidy)
|
2019-10-21 14:59:57 +02:00
|
|
|
: fullPath(clangTidyPath);
|
|
|
|
|
|
|
|
|
|
clazyStandalonePath = settingsWidget->clazyStandalonePath();
|
2023-01-10 16:36:59 +01:00
|
|
|
clazyStandalonePath = clazyStandalonePath.isEmpty()
|
|
|
|
|
? toolFallbackExecutable(ClangToolType::Clazy)
|
|
|
|
|
: fullPath(clazyStandalonePath);
|
2019-10-21 14:59:57 +02:00
|
|
|
} else {
|
|
|
|
|
// "Projects Mode > Clang Tools" case, check settings
|
2023-01-10 16:36:59 +01:00
|
|
|
clangTidyPath = toolExecutable(ClangToolType::Tidy);
|
|
|
|
|
clazyStandalonePath = toolExecutable(ClangToolType::Clazy);
|
2019-10-21 14:59:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new DiagnosticConfigsWidget(configs,
|
|
|
|
|
configToSelect,
|
|
|
|
|
ClangTidyInfo(clangTidyPath),
|
2021-09-08 12:08:55 +02:00
|
|
|
ClazyStandaloneInfo::getInfo(clazyStandalonePath));
|
2019-10-21 14:59:57 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-13 10:49:14 +02:00
|
|
|
void RunSettingsWidget::fromSettings(const RunSettings &s)
|
|
|
|
|
{
|
2022-09-26 16:36:15 +02:00
|
|
|
disconnect(m_diagnosticWidget, 0, 0, 0);
|
|
|
|
|
m_diagnosticWidget->refresh(diagnosticConfigsModel(),
|
|
|
|
|
s.diagnosticConfigId(),
|
|
|
|
|
createEditWidget);
|
2023-01-10 16:36:59 +01:00
|
|
|
connect(m_diagnosticWidget, &ClangDiagnosticConfigsSelectionWidget::changed,
|
|
|
|
|
this, &RunSettingsWidget::changed);
|
2019-09-13 10:49:14 +02:00
|
|
|
|
2023-04-11 12:49:21 +02:00
|
|
|
m_preferConfigFile->setChecked(s.preferConfigFile());
|
|
|
|
|
connect(m_preferConfigFile, &QCheckBox::toggled, this, &RunSettingsWidget::changed);
|
|
|
|
|
|
2022-09-26 16:36:15 +02:00
|
|
|
disconnect(m_buildBeforeAnalysis, 0, 0, 0);
|
|
|
|
|
m_buildBeforeAnalysis->setToolTip(hintAboutBuildBeforeAnalysis());
|
|
|
|
|
m_buildBeforeAnalysis->setCheckState(s.buildBeforeAnalysis() ? Qt::Checked : Qt::Unchecked);
|
2022-12-07 20:25:25 +01:00
|
|
|
connect(m_buildBeforeAnalysis, &QCheckBox::toggled, this, [this](bool checked) {
|
2019-09-13 10:49:14 +02:00
|
|
|
if (!checked)
|
|
|
|
|
showHintAboutBuildBeforeAnalysis();
|
|
|
|
|
emit changed();
|
|
|
|
|
});
|
|
|
|
|
|
2022-09-26 16:36:15 +02:00
|
|
|
disconnect(m_parallelJobsSpinBox, 0, 0, 0);
|
|
|
|
|
m_parallelJobsSpinBox->setValue(s.parallelJobs());
|
|
|
|
|
m_parallelJobsSpinBox->setMinimum(1);
|
|
|
|
|
m_parallelJobsSpinBox->setMaximum(QThread::idealThreadCount());
|
|
|
|
|
connect(m_parallelJobsSpinBox, &QSpinBox::valueChanged, this, &RunSettingsWidget::changed);
|
|
|
|
|
m_analyzeOpenFiles->setChecked(s.analyzeOpenFiles());
|
|
|
|
|
connect(m_analyzeOpenFiles, &QCheckBox::toggled, this, &RunSettingsWidget::changed);
|
2019-09-13 10:49:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RunSettings RunSettingsWidget::toSettings() const
|
|
|
|
|
{
|
|
|
|
|
RunSettings s;
|
2022-09-26 16:36:15 +02:00
|
|
|
s.setDiagnosticConfigId(m_diagnosticWidget->currentConfigId());
|
2023-04-11 12:49:21 +02:00
|
|
|
s.setPreferConfigFile(m_preferConfigFile->isChecked());
|
2022-09-26 16:36:15 +02:00
|
|
|
s.setBuildBeforeAnalysis(m_buildBeforeAnalysis->checkState() == Qt::CheckState::Checked);
|
|
|
|
|
s.setParallelJobs(m_parallelJobsSpinBox->value());
|
|
|
|
|
s.setAnalyzeOpenFiles(m_analyzeOpenFiles->checkState() == Qt::CheckState::Checked);
|
2019-09-13 10:49:14 +02:00
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-26 16:36:15 +02:00
|
|
|
} // ClangTools::Internal
|