diff options
author | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2016-02-26 17:50:38 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2016-03-01 15:55:30 +0000 |
commit | 83e18c127c5c9b811eeb088c37cd94b70e166482 (patch) | |
tree | 97c69cc5ec33f07a9f8e97d17b4a0f83682d2e14 /src/plugins/clangcodemodel | |
parent | b590642a859fba9290e031cd745ca5be24662408 (diff) | |
download | qt-creator-83e18c127c5c9b811eeb088c37cd94b70e166482.tar.gz |
Clang: Introduce warning configuration per project
Change-Id: I5b9a330274e6f72b0786259eb25aa454877d4eef
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
Diffstat (limited to 'src/plugins/clangcodemodel')
9 files changed, 462 insertions, 2 deletions
diff --git a/src/plugins/clangcodemodel/clangcodemodel.pro b/src/plugins/clangcodemodel/clangcodemodel.pro index 17a63638e5..ff3ce0aea4 100644 --- a/src/plugins/clangcodemodel/clangcodemodel.pro +++ b/src/plugins/clangcodemodel/clangcodemodel.pro @@ -29,6 +29,8 @@ SOURCES += \ clanghighlightingmarksreporter.cpp \ clangmodelmanagersupport.cpp \ clangpreprocessorassistproposalitem.cpp \ + clangprojectsettings.cpp \ + clangprojectsettingswidget.cpp \ clangtextmark.cpp \ clangutils.cpp @@ -58,9 +60,13 @@ HEADERS += \ clangisdiagnosticrelatedtolocation.h \ clangmodelmanagersupport.h \ clangpreprocessorassistproposalitem.h \ + clangprojectsettings.h \ + clangprojectsettingswidget.h \ clangtextmark.h \ clangutils.h +FORMS += clangprojectsettingswidget.ui + RESOURCES += \ clangcodemodel.qrc diff --git a/src/plugins/clangcodemodel/clangcodemodel.qbs b/src/plugins/clangcodemodel/clangcodemodel.qbs index 9459aa8391..3109e20df4 100644 --- a/src/plugins/clangcodemodel/clangcodemodel.qbs +++ b/src/plugins/clangcodemodel/clangcodemodel.qbs @@ -84,6 +84,11 @@ QtcPlugin { "clangmodelmanagersupport.h", "clangpreprocessorassistproposalitem.cpp", "clangpreprocessorassistproposalitem.h", + "clangprojectsettings.cpp", + "clangprojectsettings.h", + "clangprojectsettingswidget.cpp", + "clangprojectsettingswidget.h", + "clangprojectsettingswidget.ui", "clangtextmark.cpp", "clangtextmark.h", "clangutils.cpp", diff --git a/src/plugins/clangcodemodel/clangcodemodelplugin.cpp b/src/plugins/clangcodemodel/clangcodemodelplugin.cpp index f81eb2d734..285042cc31 100644 --- a/src/plugins/clangcodemodel/clangcodemodelplugin.cpp +++ b/src/plugins/clangcodemodel/clangcodemodelplugin.cpp @@ -26,6 +26,7 @@ #include "clangcodemodelplugin.h" #include "clangconstants.h" +#include "clangprojectsettingswidget.h" #ifdef WITH_TESTS # include "test/clangcodecompletion_test.h" @@ -33,6 +34,10 @@ #include <cpptools/cppmodelmanager.h> +#include <projectexplorer/projectpanelfactory.h> +#include <projectexplorer/projectexplorer.h> +#include <projectexplorer/session.h> + #include <texteditor/textmark.h> namespace ClangCodeModel { @@ -48,6 +53,15 @@ void initializeTextMarks() Utils::Theme::ClangCodeModel_Error_TextMarkColor); } +void addProjectPanelWidget() +{ + auto panelFactory = new ProjectExplorer::ProjectPanelFactory(); + panelFactory->setPriority(60); + panelFactory->setDisplayName(ClangProjectSettingsWidget::tr("Clang Code Model")); + panelFactory->setSimpleCreateWidgetFunction<ClangProjectSettingsWidget>(QIcon()); + ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory); +} + } // anonymous namespace bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *errorMessage) @@ -58,6 +72,7 @@ bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *err CppTools::CppModelManager::instance()->activateClangCodeModel(&m_modelManagerSupportProvider); initializeTextMarks(); + addProjectPanelWidget(); return true; } diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp index 38f7cb2d51..6428abcc5b 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp @@ -30,11 +30,14 @@ #include "clangfixitoperation.h" #include "clangfixitoperationsextractor.h" #include "clanghighlightingmarksreporter.h" +#include "clangprojectsettings.h" #include "clangutils.h" #include <diagnosticcontainer.h> #include <sourcelocationcontainer.h> +#include <cpptools/clangdiagnosticconfigsmodel.h> +#include <cpptools/clangdiagnosticconfigsmodel.h> #include <cpptools/compileroptionsbuilder.h> #include <cpptools/cppcodemodelsettings.h> #include <cpptools/cppmodelmanager.h> @@ -340,10 +343,25 @@ static QStringList languageOptions(const QString &filePath, CppTools::ProjectPar return builder.options(); } +static QStringList warningOptions(CppTools::ProjectPart *projectPart) +{ + if (projectPart && projectPart->project) { + ClangProjectSettings projectSettings(projectPart->project); + if (!projectSettings.useGlobalWarningConfig()) { + const Core::Id warningConfigId = projectSettings.warningConfigId(); + const CppTools::ClangDiagnosticConfigsModel configsModel( + CppTools::codeModelSettings()->clangCustomDiagnosticConfigs()); + if (configsModel.hasConfigWithId(warningConfigId)) + return configsModel.configWithId(warningConfigId).commandLineOptions(); + } + } + + return CppTools::codeModelSettings()->clangDiagnosticConfig().commandLineOptions(); +} + static QStringList fileArguments(const QString &filePath, CppTools::ProjectPart *projectPart) { - return languageOptions(filePath, projectPart) - + CppTools::codeModelSettings()->clangDiagnosticConfig().commandLineOptions(); + return languageOptions(filePath, projectPart) + warningOptions(projectPart); } ClangBackEnd::FileContainer diff --git a/src/plugins/clangcodemodel/clangprojectsettings.cpp b/src/plugins/clangcodemodel/clangprojectsettings.cpp new file mode 100644 index 0000000000..a5311513b8 --- /dev/null +++ b/src/plugins/clangcodemodel/clangprojectsettings.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "clangprojectsettings.h" + +namespace ClangCodeModel { +namespace Internal { + +static QString useGlobalWarningConfigKey() +{ return QStringLiteral("ClangCodeModel.UseGlobalWarningConfig"); } + +static QString warningConfigIdKey() +{ return QStringLiteral("ClangCodeModel.WarningConfigId"); } + +ClangProjectSettings::ClangProjectSettings(ProjectExplorer::Project *project) + : m_project(project) +{ + load(); + + connect(project, &ProjectExplorer::Project::settingsLoaded, + this, &ClangProjectSettings::load); + connect(project, &ProjectExplorer::Project::aboutToSaveSettings, + this, &ClangProjectSettings::store); +} + +Core::Id ClangProjectSettings::warningConfigId() const +{ + return m_warningConfigId; +} + +void ClangProjectSettings::setWarningConfigId(const Core::Id &customConfigId) +{ + m_warningConfigId = customConfigId; +} + +bool ClangProjectSettings::useGlobalWarningConfig() const +{ + return m_useGlobalWarningConfig; +} + +void ClangProjectSettings::setUseGlobalWarningConfig(bool useGlobalWarningConfig) +{ + m_useGlobalWarningConfig = useGlobalWarningConfig; +} + +void ClangProjectSettings::load() +{ + const QVariant useGlobalConfigVariant = m_project->namedSettings(useGlobalWarningConfigKey()); + const bool useGlobalConfig = useGlobalConfigVariant.isValid() + ? useGlobalConfigVariant.toBool() + : true; + + setUseGlobalWarningConfig(useGlobalConfig); + setWarningConfigId(Core::Id::fromSetting(m_project->namedSettings(warningConfigIdKey()))); +} + +void ClangProjectSettings::store() +{ + m_project->setNamedSettings(useGlobalWarningConfigKey(), useGlobalWarningConfig()); + m_project->setNamedSettings(warningConfigIdKey(), warningConfigId().toSetting()); +} + +} // namespace Internal +} // namespace ClangCodeModel diff --git a/src/plugins/clangcodemodel/clangprojectsettings.h b/src/plugins/clangcodemodel/clangprojectsettings.h new file mode 100644 index 0000000000..5ffe12aa46 --- /dev/null +++ b/src/plugins/clangcodemodel/clangprojectsettings.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#pragma once + +#include <coreplugin/id.h> +#include <projectexplorer/project.h> + +#include <QObject> +#include <QString> + +namespace ClangCodeModel { +namespace Internal { + +class ClangProjectSettings: public QObject +{ + Q_OBJECT + +public: + ClangProjectSettings(ProjectExplorer::Project *project); + + bool useGlobalWarningConfig() const; + void setUseGlobalWarningConfig(bool useGlobalWarningConfig); + + Core::Id warningConfigId() const; + void setWarningConfigId(const Core::Id &warningConfigId); + +public slots: + void load(); + void store(); + +private: + ProjectExplorer::Project *m_project; + bool m_useGlobalWarningConfig = true; + Core::Id m_warningConfigId; +}; + +} // namespace Internal +} // namespace ClangCodeModel diff --git a/src/plugins/clangcodemodel/clangprojectsettingswidget.cpp b/src/plugins/clangcodemodel/clangprojectsettingswidget.cpp new file mode 100644 index 0000000000..b3c01f1831 --- /dev/null +++ b/src/plugins/clangcodemodel/clangprojectsettingswidget.cpp @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "clangprojectsettingswidget.h" + +#include "clangprojectsettings.h" + +#include <coreplugin/icore.h> + +#include <cpptools/clangdiagnosticconfig.h> +#include <cpptools/clangdiagnosticconfigswidget.h> +#include <cpptools/cppcodemodelsettings.h> +#include <cpptools/cpptoolsreuse.h> + +static const char GLOBAL_PROXY_CONFIG_ID[] = "globalProxyConfig"; + +namespace ClangCodeModel { +namespace Internal { + +static CppTools::ClangDiagnosticConfig +createConfigRepresentingGlobalSetting(const CppTools::ClangDiagnosticConfig &baseConfig) +{ + CppTools::ClangDiagnosticConfig config = baseConfig; + config.setId(GLOBAL_PROXY_CONFIG_ID); + + QString displayName = config.displayName(); + if (config.isReadOnly()) + displayName = CppTools::ClangDiagnosticConfigsModel::displayNameWithBuiltinIndication(config); + displayName = ClangProjectSettingsWidget::tr("Global setting (%1)").arg(displayName); + + config.setDisplayName(displayName); + config.setIsReadOnly(true); + + return config; +} + +static Core::Id globalConfigId(const CppTools::CppCodeModelSettings &settings, + const CppTools::ClangDiagnosticConfigsModel &model) +{ + const Core::Id configId = settings.clangDiagnosticConfigId(); + + if (model.hasConfigWithId(configId)) + return configId; + + return model.at(0).id(); // Config saved in the settings was removed, fallback to first. +} + +static CppTools::ClangDiagnosticConfigsModel +createConfigsModelWithGlobalProxyConfig(const CppTools::CppCodeModelSettings &settings) +{ + using namespace CppTools; + ClangDiagnosticConfigsModel configsModel(settings.clangCustomDiagnosticConfigs()); + + const Core::Id globalId = globalConfigId(settings, configsModel); + const ClangDiagnosticConfig globalConfig = configsModel.configWithId(globalId); + const ClangDiagnosticConfig globalProxy + = createConfigRepresentingGlobalSetting(globalConfig); + + configsModel.prepend(globalProxy); + + return configsModel; +} + +static Core::Id configIdForProject(const ClangProjectSettings &projectSettings) +{ + return projectSettings.useGlobalWarningConfig() + ? Core::Id(GLOBAL_PROXY_CONFIG_ID) + : projectSettings.warningConfigId(); +} + +ClangProjectSettingsWidget::ClangProjectSettingsWidget(ProjectExplorer::Project *project) + : m_projectSettings(project) +{ + m_ui.setupUi(this); + + using namespace CppTools; + + m_diagnosticConfigWidget = new ClangDiagnosticConfigsWidget; + m_diagnosticConfigWidget->setConfigWithUndecoratedDisplayName(Core::Id(GLOBAL_PROXY_CONFIG_ID)); + refreshDiagnosticConfigsWidgetFromSettings(); + connectToCppCodeModelSettingsChanged(); + connect(m_diagnosticConfigWidget.data(), &ClangDiagnosticConfigsWidget::currentConfigChanged, + this, &ClangProjectSettingsWidget::onCurrentWarningConfigChanged); + connect(m_diagnosticConfigWidget.data(), &ClangDiagnosticConfigsWidget::customConfigsChanged, + this, &ClangProjectSettingsWidget::onCustomWarningConfigsChanged); + + m_ui.diagnosticConfigurationGroupBox->layout()->addWidget(m_diagnosticConfigWidget); +} + +void ClangProjectSettingsWidget::onCurrentWarningConfigChanged(const Core::Id ¤tConfigId) +{ + const bool useGlobalConfig = currentConfigId == Core::Id(GLOBAL_PROXY_CONFIG_ID); + + m_projectSettings.setUseGlobalWarningConfig(useGlobalConfig); + m_projectSettings.setWarningConfigId(currentConfigId); + + m_projectSettings.store(); +} + +void ClangProjectSettingsWidget::onCustomWarningConfigsChanged( + const CppTools::ClangDiagnosticConfigs &customConfigs) +{ + disconnectFromCppCodeModelSettingsChanged(); + + const QSharedPointer<CppTools::CppCodeModelSettings> codeModelSettings + = CppTools::codeModelSettings(); + codeModelSettings->setClangCustomDiagnosticConfigs(customConfigs); + codeModelSettings->toSettings(Core::ICore::settings()); + + connectToCppCodeModelSettingsChanged(); +} + +void ClangProjectSettingsWidget::refreshDiagnosticConfigsWidgetFromSettings() +{ + m_diagnosticConfigWidget->refresh( + createConfigsModelWithGlobalProxyConfig(*CppTools::codeModelSettings()), + configIdForProject(m_projectSettings)); +} + +void ClangProjectSettingsWidget::connectToCppCodeModelSettingsChanged() +{ + connect(CppTools::codeModelSettings().data(), &CppTools::CppCodeModelSettings::changed, + this, &ClangProjectSettingsWidget::refreshDiagnosticConfigsWidgetFromSettings); +} + +void ClangProjectSettingsWidget::disconnectFromCppCodeModelSettingsChanged() +{ + disconnect(CppTools::codeModelSettings().data(), &CppTools::CppCodeModelSettings::changed, + this, &ClangProjectSettingsWidget::refreshDiagnosticConfigsWidgetFromSettings); +} + +} // namespace Internal +} // namespace ClangCodeModel diff --git a/src/plugins/clangcodemodel/clangprojectsettingswidget.h b/src/plugins/clangcodemodel/clangprojectsettingswidget.h new file mode 100644 index 0000000000..944a043329 --- /dev/null +++ b/src/plugins/clangcodemodel/clangprojectsettingswidget.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#pragma once + +#include "ui_clangprojectsettingswidget.h" + +#include "clangprojectsettings.h" + +#include <cpptools/clangdiagnosticconfigsmodel.h> + +#include <QPointer> + +namespace ProjectExplorer { class Project; } +namespace CppTools { class ClangDiagnosticConfigsWidget; } + +namespace ClangCodeModel { +namespace Internal { + +class ClangProjectSettingsWidget: public QWidget +{ + Q_OBJECT + +public: + explicit ClangProjectSettingsWidget(ProjectExplorer::Project *project); + +private slots: + void onCurrentWarningConfigChanged(const Core::Id ¤tConfigId); + void onCustomWarningConfigsChanged(const CppTools::ClangDiagnosticConfigs &customConfigs); + +private: + void refreshDiagnosticConfigsWidgetFromSettings(); + void connectToCppCodeModelSettingsChanged(); + void disconnectFromCppCodeModelSettingsChanged(); + +private: + Ui::ClangProjectSettingsWidget m_ui; + ClangProjectSettings m_projectSettings; + QPointer<CppTools::ClangDiagnosticConfigsWidget> m_diagnosticConfigWidget; +}; + +} // namespace Internal +} // namespace ClangCodeModel diff --git a/src/plugins/clangcodemodel/clangprojectsettingswidget.ui b/src/plugins/clangcodemodel/clangprojectsettingswidget.ui new file mode 100644 index 0000000000..085294b840 --- /dev/null +++ b/src/plugins/clangcodemodel/clangprojectsettingswidget.ui @@ -0,0 +1,29 @@ +<?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"> + <item> + <widget class="QGroupBox" name="diagnosticConfigurationGroupBox"> + <property name="title"> + <string>Warnings</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"/> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> |