ProjectExplorer: Add a common template for project settings

- Added base widget class for common options among project settings tabs
- Added usage new template class to all pages used in project settings

ToDo
- Make CodeStyle tab standardized

Change-Id: I8f70413b6ee764c5e43fbeae104b9389237c582f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Artem Sokolovskii
2022-04-14 15:51:18 +02:00
parent 6c05ed7920
commit 7954c4cc69
35 changed files with 630 additions and 206 deletions

View File

@@ -0,0 +1,149 @@
/****************************************************************************
**
** 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 <cppeditor/clangdiagnosticconfig.h>
#include <cppeditor/clangdiagnosticconfigswidget.h>
#include <cppeditor/cppeditorconstants.h>
#include <cppeditor/cppcodemodelsettings.h>
#include <cppeditor/cpptoolsreuse.h>
#include <utils/hostosinfo.h>
namespace ClangCodeModel {
namespace Internal {
static Utils::Id configIdForProject(ClangProjectSettings &projectSettings)
{
if (projectSettings.useGlobalConfig())
return CppEditor::codeModelSettings()->clangDiagnosticConfigId();
return projectSettings.warningConfigId();
}
ClangProjectSettingsWidget::ClangProjectSettingsWidget(ProjectExplorer::Project *project)
: m_projectSettings(ClangModelManagerSupport::instance()->projectSettings(project))
{
m_ui.setupUi(this);
setGlobalSettingsId(CppEditor::Constants::CPP_CODE_MODEL_SETTINGS_ID);
using namespace CppEditor;
m_ui.delayedTemplateParseCheckBox->setVisible(Utils::HostOsInfo::isWindowsHost());
connect(m_ui.clangDiagnosticConfigsSelectionWidget,
&ClangDiagnosticConfigsSelectionWidget::changed,
this,
[this]() {
// Save project's config id
const Utils::Id currentConfigId = m_ui.clangDiagnosticConfigsSelectionWidget
->currentConfigId();
m_projectSettings.setWarningConfigId(currentConfigId);
// Save global custom configs
const ClangDiagnosticConfigs configs = m_ui.clangDiagnosticConfigsSelectionWidget
->customConfigs();
CppEditor::codeModelSettings()->setClangCustomDiagnosticConfigs(configs);
CppEditor::codeModelSettings()->toSettings(Core::ICore::settings());
});
connect(this, &ProjectSettingsWidget::useGlobalSettingsChanged,
this, &ClangProjectSettingsWidget::onGlobalCustomChanged);
connect(m_ui.delayedTemplateParseCheckBox, &QCheckBox::toggled,
this, &ClangProjectSettingsWidget::onDelayedTemplateParseClicked);
connect(project, &ProjectExplorer::Project::aboutToSaveSettings,
this, &ClangProjectSettingsWidget::onAboutToSaveProjectSettings);
connect(&m_projectSettings, &ClangProjectSettings::changed,
this, &ClangProjectSettingsWidget::syncWidgets);
connect(CppEditor::codeModelSettings(), &CppEditor::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(bool useGlobalSettings)
{
m_projectSettings.setUseGlobalConfig(useGlobalSettings);
syncOtherWidgetsToComboBox();
}
void ClangProjectSettingsWidget::onAboutToSaveProjectSettings()
{
CppEditor::codeModelSettings()->toSettings(Core::ICore::settings());
}
void ClangProjectSettingsWidget::syncWidgets()
{
setUseGlobalSettings(m_projectSettings.useGlobalConfig());
syncOtherWidgetsToComboBox();
}
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(CppEditor::diagnosticConfigsModel(),
configIdForProject(m_projectSettings),
[](const CppEditor::ClangDiagnosticConfigs &configs,
const Utils::Id &configToSelect) {
return new CppEditor::ClangDiagnosticConfigsWidget(configs, configToSelect);
});
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -0,0 +1,61 @@
/****************************************************************************
**
** 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.
**
****************************************************************************/
#pragma once
#include "ui_clangprojectsettingswidget.h"
#include "clangprojectsettings.h"
#include <projectexplorer/projectsettingswidget.h>
#include <QPointer>
namespace ProjectExplorer { class Project; }
namespace ClangCodeModel {
namespace Internal {
class ClangProjectSettingsWidget: public ProjectExplorer::ProjectSettingsWidget
{
Q_OBJECT
public:
explicit ClangProjectSettingsWidget(ProjectExplorer::Project *project);
private:
void onDelayedTemplateParseClicked(bool);
void onGlobalCustomChanged(bool useGlobalSettings);
void onAboutToSaveProjectSettings();
void syncWidgets();
void syncOtherWidgetsToComboBox();
private:
Ui::ClangProjectSettingsWidget m_ui;
ClangProjectSettings &m_projectSettings;
};
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ClangCodeModel::Internal::ClangProjectSettingsWidget</class>
<widget class="QWidget" name="ClangCodeModel::Internal::ClangProjectSettingsWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>814</width>
<height>330</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="delayedTemplateParseCheckBox">
<property name="toolTip">
<string>Parse templates in a MSVC-compliant way. This helps to parse headers for example from Active Template Library (ATL) or Windows Runtime Library (WRL).
However, using the relaxed and extended rules means also that no highlighting/completion can be provided within template functions.</string>
</property>
<property name="text">
<string>Enable MSVC-compliant template parsing</string>
</property>
</widget>
</item>
<item>
<widget class="CppEditor::ClangDiagnosticConfigsSelectionWidget" name="clangDiagnosticConfigsSelectionWidget" native="true"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>CppEditor::ClangDiagnosticConfigsSelectionWidget</class>
<extends>QWidget</extends>
<header>cppeditor/clangdiagnosticconfigsselectionwidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>