forked from qt-creator/qt-creator
* Improve distinction between built-in and custom configs by introducing corresponding parent nodes * Add button to rename a config * Make closing the dialog apply the selected config. * Adapt also the related ClangDiagnosticConfigsSelectionWidget showing a combo box of the diagnostic configs and a "Manage..." button: Remove the combo box and show the current config as the button text. Change-Id: Ic015df37f2532f84bd7da6cd20bfce07799a97b8 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
150 lines
6.0 KiB
C++
150 lines
6.0 KiB
C++
/****************************************************************************
|
|
**
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
** Contact: https://www.qt.io/licensing/
|
|
**
|
|
** This file is part of Qt Creator.
|
|
**
|
|
** Commercial License Usage
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
** accordance with the commercial license agreement provided with the
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
**
|
|
** GNU General Public License Usage
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
** General Public License version 3 as published by the Free Software
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
** included in the packaging of this file. Please review the following
|
|
** information to ensure the GNU General Public License requirements will
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
**
|
|
****************************************************************************/
|
|
|
|
#include "clangprojectsettingswidget.h"
|
|
|
|
#include "clangmodelmanagersupport.h"
|
|
#include "clangprojectsettings.h"
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
#include <cpptools/clangdiagnosticconfig.h>
|
|
#include <cpptools/clangdiagnosticconfigswidget.h>
|
|
#include <cpptools/cppcodemodelsettings.h>
|
|
#include <cpptools/cpptoolsreuse.h>
|
|
|
|
#include <utils/hostosinfo.h>
|
|
|
|
namespace ClangCodeModel {
|
|
namespace Internal {
|
|
|
|
static Core::Id configIdForProject(ClangProjectSettings &projectSettings)
|
|
{
|
|
if (projectSettings.useGlobalConfig())
|
|
return CppTools::codeModelSettings()->clangDiagnosticConfigId();
|
|
return projectSettings.warningConfigId();
|
|
}
|
|
|
|
ClangProjectSettingsWidget::ClangProjectSettingsWidget(ProjectExplorer::Project *project)
|
|
: m_projectSettings(ClangModelManagerSupport::instance()->projectSettings(project))
|
|
{
|
|
m_ui.setupUi(this);
|
|
|
|
using namespace CppTools;
|
|
|
|
m_ui.delayedTemplateParseCheckBox->setVisible(Utils::HostOsInfo::isWindowsHost());
|
|
|
|
connect(m_ui.clangDiagnosticConfigsSelectionWidget,
|
|
&ClangDiagnosticConfigsSelectionWidget::changed,
|
|
this,
|
|
[this]() {
|
|
// Save project's config id
|
|
const Core::Id currentConfigId = m_ui.clangDiagnosticConfigsSelectionWidget
|
|
->currentConfigId();
|
|
m_projectSettings.setWarningConfigId(currentConfigId);
|
|
|
|
// Save global custom configs
|
|
const ClangDiagnosticConfigs configs = m_ui.clangDiagnosticConfigsSelectionWidget
|
|
->customConfigs();
|
|
CppTools::codeModelSettings()->setClangCustomDiagnosticConfigs(configs);
|
|
CppTools::codeModelSettings()->toSettings(Core::ICore::settings());
|
|
});
|
|
|
|
connect(m_ui.delayedTemplateParseCheckBox, &QCheckBox::toggled,
|
|
this, &ClangProjectSettingsWidget::onDelayedTemplateParseClicked);
|
|
connect(m_ui.globalOrCustomComboBox,
|
|
QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
this, &ClangProjectSettingsWidget::onGlobalCustomChanged);
|
|
connect(project, &ProjectExplorer::Project::aboutToSaveSettings,
|
|
this, &ClangProjectSettingsWidget::onAboutToSaveProjectSettings);
|
|
|
|
connect(&m_projectSettings, &ClangProjectSettings::changed,
|
|
this, &ClangProjectSettingsWidget::syncWidgets);
|
|
connect(CppTools::codeModelSettings().data(), &CppTools::CppCodeModelSettings::changed,
|
|
this, &ClangProjectSettingsWidget::syncOtherWidgetsToComboBox);
|
|
|
|
syncWidgets();
|
|
}
|
|
|
|
void ClangProjectSettingsWidget::onDelayedTemplateParseClicked(bool checked)
|
|
{
|
|
// Don't save it when we reset the global config in code
|
|
if (m_projectSettings.useGlobalConfig())
|
|
return;
|
|
|
|
const QLatin1String extraFlag{checked ? ClangProjectSettings::DelayedTemplateParsing
|
|
: ClangProjectSettings::NoDelayedTemplateParsing};
|
|
QStringList options = m_projectSettings.commandLineOptions();
|
|
options.removeAll(QLatin1String{ClangProjectSettings::DelayedTemplateParsing});
|
|
options.removeAll(QLatin1String{ClangProjectSettings::NoDelayedTemplateParsing});
|
|
options.append(extraFlag);
|
|
m_projectSettings.setCommandLineOptions(options);
|
|
}
|
|
|
|
void ClangProjectSettingsWidget::onGlobalCustomChanged(int index)
|
|
{
|
|
m_projectSettings.setUseGlobalConfig(index == 0 ? true : false);
|
|
syncOtherWidgetsToComboBox();
|
|
}
|
|
|
|
void ClangProjectSettingsWidget::onAboutToSaveProjectSettings()
|
|
{
|
|
CppTools::codeModelSettings()->toSettings(Core::ICore::settings());
|
|
}
|
|
|
|
void ClangProjectSettingsWidget::syncWidgets()
|
|
{
|
|
syncGlobalCustomComboBox();
|
|
syncOtherWidgetsToComboBox();
|
|
}
|
|
|
|
void ClangProjectSettingsWidget::syncGlobalCustomComboBox()
|
|
{
|
|
m_ui.globalOrCustomComboBox->setCurrentIndex(m_projectSettings.useGlobalConfig() ? 0 : 1);
|
|
}
|
|
|
|
void ClangProjectSettingsWidget::syncOtherWidgetsToComboBox()
|
|
{
|
|
const QStringList options = m_projectSettings.commandLineOptions();
|
|
m_ui.delayedTemplateParseCheckBox->setChecked(
|
|
options.contains(QLatin1String{ClangProjectSettings::DelayedTemplateParsing}));
|
|
|
|
const bool isCustom = !m_projectSettings.useGlobalConfig();
|
|
m_ui.delayedTemplateParseCheckBox->setEnabled(isCustom);
|
|
|
|
for (int i = 0; i < m_ui.clangDiagnosticConfigsSelectionWidget->layout()->count(); ++i) {
|
|
QWidget *widget = m_ui.clangDiagnosticConfigsSelectionWidget->layout()->itemAt(i)->widget();
|
|
if (widget)
|
|
widget->setEnabled(isCustom);
|
|
}
|
|
|
|
m_ui.clangDiagnosticConfigsSelectionWidget->refresh(CppTools::diagnosticConfigsModel(),
|
|
configIdForProject(m_projectSettings),
|
|
/*showTidyClazyUi=*/false);
|
|
}
|
|
|
|
} // namespace Internal
|
|
} // namespace ClangCodeModel
|