From beda74932642c730f1fb24d1ac2a9617f5b10a40 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 23 Mar 2021 15:58:16 +0100 Subject: [PATCH] CMake: Aspectify CMakeSpecificSettings Change-Id: I2e094c5a392964fdaf49ac30c2e0ae0f57a3b11d Reviewed-by: Cristian Adam --- .../cmakeprojectmanager/CMakeLists.txt | 1 - .../cmakebuildconfiguration.cpp | 2 +- .../cmakeprojectmanager/cmakebuildsystem.cpp | 2 +- .../cmakeprojectmanager.pro | 5 - .../cmakeprojectmanager.qbs | 3 - .../cmakeprojectplugin.cpp | 3 +- .../cmakespecificsettings.cpp | 106 ++++++++++++++---- .../cmakespecificsettings.h | 52 +++++---- .../cmakespecificsettingspage.cpp | 99 ---------------- .../cmakespecificsettingspage.h | 42 ------- .../cmakespecificsettingspage.ui | 100 ----------------- 11 files changed, 120 insertions(+), 295 deletions(-) delete mode 100644 src/plugins/cmakeprojectmanager/cmakespecificsettingspage.cpp delete mode 100644 src/plugins/cmakeprojectmanager/cmakespecificsettingspage.h delete mode 100644 src/plugins/cmakeprojectmanager/cmakespecificsettingspage.ui diff --git a/src/plugins/cmakeprojectmanager/CMakeLists.txt b/src/plugins/cmakeprojectmanager/CMakeLists.txt index d8a7479e3d5..259db24cac6 100644 --- a/src/plugins/cmakeprojectmanager/CMakeLists.txt +++ b/src/plugins/cmakeprojectmanager/CMakeLists.txt @@ -27,7 +27,6 @@ add_qtc_plugin(CMakeProjectManager cmakeprojectplugin.cpp cmakeprojectplugin.h cmakesettingspage.cpp cmakesettingspage.h cmakespecificsettings.cpp cmakespecificsettings.h - cmakespecificsettingspage.cpp cmakespecificsettingspage.h cmakespecificsettingspage.ui cmaketool.cpp cmaketool.h cmaketoolmanager.cpp cmaketoolmanager.h cmaketoolsettingsaccessor.cpp cmaketoolsettingsaccessor.h diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp index 0a80f87341b..86826432401 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp @@ -200,7 +200,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc) QDialogButtonBox::Yes); settings->setAskBeforeReConfigureInitialParams(!doNotAsk); - settings->toSettings(Core::ICore::settings()); + settings->writeSettings(Core::ICore::settings()); if (reply != QDialogButtonBox::Yes) { return; diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp index 0b879c04b1e..e22d55c8086 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp @@ -122,7 +122,7 @@ void noAutoAdditionNotify(const QStringList &filePaths, const ProjectExplorer::P settings->setAfterAddFileSetting( CMakeProjectManager::Internal::AfterAddFileAction::NEVER_COPY_FILE_PATH); - settings->toSettings(Core::ICore::settings()); + settings->writeSettings(Core::ICore::settings()); } if (QDialogButtonBox::Yes == reply) { diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro index 1ba791a64b8..95eec930518 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro @@ -27,7 +27,6 @@ HEADERS = builddirparameters.h \ cmakeindenter.h \ cmakeautocompleter.h \ cmakespecificsettings.h \ - cmakespecificsettingspage.h \ configmodel.h \ configmodelitemdelegate.h \ fileapidataextractor.h \ @@ -58,7 +57,6 @@ SOURCES = builddirparameters.cpp \ cmakeindenter.cpp \ cmakeautocompleter.cpp \ cmakespecificsettings.cpp \ - cmakespecificsettingspage.cpp \ configmodel.cpp \ configmodelitemdelegate.cpp \ fileapidataextractor.cpp \ @@ -67,6 +65,3 @@ SOURCES = builddirparameters.cpp \ projecttreehelper.cpp RESOURCES += cmakeproject.qrc - -FORMS += \ - cmakespecificsettingspage.ui diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs index 31c61263398..751efd49bd4 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs @@ -69,9 +69,6 @@ QtcPlugin { "cmakeautocompleter.cpp", "cmakespecificsettings.h", "cmakespecificsettings.cpp", - "cmakespecificsettingspage.h", - "cmakespecificsettingspage.cpp", - "cmakespecificsettingspage.ui", "configmodel.cpp", "configmodel.h", "configmodelitemdelegate.cpp", diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp index 1dae39f0362..c1cce18df94 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp @@ -37,7 +37,6 @@ #include "cmakeprojectnodes.h" #include "cmakesettingspage.h" #include "cmakespecificsettings.h" -#include "cmakespecificsettingspage.h" #include "cmaketoolmanager.h" #include @@ -100,7 +99,7 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString * Q_UNUSED(errorMessage) d = new CMakeProjectPluginPrivate; - projectTypeSpecificSettings()->fromSettings(ICore::settings()); + projectTypeSpecificSettings()->readSettings(ICore::settings()); const Context projectContext{CMakeProjectManager::Constants::CMAKE_PROJECT_ID}; diff --git a/src/plugins/cmakeprojectmanager/cmakespecificsettings.cpp b/src/plugins/cmakeprojectmanager/cmakespecificsettings.cpp index 070610fd7d7..de11b911b40 100644 --- a/src/plugins/cmakeprojectmanager/cmakespecificsettings.cpp +++ b/src/plugins/cmakeprojectmanager/cmakespecificsettings.cpp @@ -25,37 +25,99 @@ #include "cmakespecificsettings.h" +#include + +#include + +#include + +using namespace Utils; + namespace CMakeProjectManager { namespace Internal { -namespace { -static const char SETTINGS_KEY[] = "CMakeSpecificSettings"; -static const char AFTER_ADD_FILE_ACTION_KEY[] = "ProjectPopupSetting"; -static const char NINJA_PATH[] = "NinjaPath"; -static const char PACKAGE_MANAGER_AUTO_SETUP[] = "PackageManagerAutoSetup"; -static const char ASK_RECONFIGURE_INITIAL_PARAMS[] = "AskReConfigureInitialParams"; -} - -void CMakeSpecificSettings::fromSettings(QSettings *settings) +CMakeSpecificSettings::CMakeSpecificSettings() { - const QString rootKey = QString(SETTINGS_KEY) + '/'; - m_afterAddFileToProjectSetting = static_cast( - settings->value(rootKey + AFTER_ADD_FILE_ACTION_KEY, - static_cast(AfterAddFileAction::ASK_USER)).toInt()); + setSettingsGroup("CMakeSpecificSettings"); + setAutoApply(false); - m_ninjaPath = Utils::FilePath::fromUserInput( - settings->value(rootKey + NINJA_PATH, QString()).toString()); + registerAspect(&m_afterAddFileToProjectSetting); + m_afterAddFileToProjectSetting.setSettingsKey("ProjectPopupSetting"); + m_afterAddFileToProjectSetting.setDefaultValue(AfterAddFileAction::ASK_USER); + m_afterAddFileToProjectSetting.addOption(tr("Ask about copying file paths")); + m_afterAddFileToProjectSetting.addOption(tr("Do not copy file paths")); + m_afterAddFileToProjectSetting.addOption(tr("Copy file paths")); + m_afterAddFileToProjectSetting.setToolTip(tr("Determines whether file paths are copied " + "to the clipboard for pasting to the CMakeLists.txt file when you " + "add new files to CMake projects.")); - m_packageManagerAutoSetup = settings->value(rootKey + PACKAGE_MANAGER_AUTO_SETUP, true).toBool(); + registerAspect(&m_ninjaPath); + m_ninjaPath.setSettingsKey("NinjaPath"); + + registerAspect(&m_packageManagerAutoSetup); + m_packageManagerAutoSetup.setSettingsKey("PackageManagerAutoSetup"); + m_packageManagerAutoSetup.setDefaultValue(true); + m_packageManagerAutoSetup.setLabelText(tr("Package manager auto setup")); + m_packageManagerAutoSetup.setToolTip(tr("Add the CMAKE_PROJECT_INCLUDE_BEFORE variable " + "pointing to a CMake script that will install dependencies from the conanfile.txt, " + "conanfile.py, or vcpkg.json file from the project source directory.")); + + registerAspect(&m_askBeforeReConfigureInitialParams); + m_askBeforeReConfigureInitialParams.setSettingsKey("AskReConfigureInitialParams"); + m_askBeforeReConfigureInitialParams.setDefaultValue(true); + m_askBeforeReConfigureInitialParams.setLabelText(tr("Ask before re-configuring with " + "initial parameters")); } -void CMakeSpecificSettings::toSettings(QSettings *settings) const +// CMakeSpecificSettingWidget + +class CMakeSpecificSettingWidget final : public Core::IOptionsPageWidget { - settings->beginGroup(QString(SETTINGS_KEY)); - settings->setValue(QString(AFTER_ADD_FILE_ACTION_KEY), static_cast(m_afterAddFileToProjectSetting)); - settings->setValue(QString(PACKAGE_MANAGER_AUTO_SETUP), m_packageManagerAutoSetup); - settings->setValue(QString(ASK_RECONFIGURE_INITIAL_PARAMS), m_askBeforeReConfigureInitialParams); - settings->endGroup(); + Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::Internal::CMakeSpecificSettingWidget) + +public: + explicit CMakeSpecificSettingWidget(CMakeSpecificSettings *settings); + + void apply() final; + +private: + CMakeSpecificSettings *m_settings; +}; + +CMakeSpecificSettingWidget::CMakeSpecificSettingWidget(CMakeSpecificSettings *settings) + : m_settings(settings) +{ + CMakeSpecificSettings &s = *m_settings; + using namespace Layouting; + + Column { + Group { + Title(tr("Adding Files")), + s.m_afterAddFileToProjectSetting + }, + s.m_packageManagerAutoSetup, + s.m_askBeforeReConfigureInitialParams, + Stretch(), + }.attachTo(this); } + +void CMakeSpecificSettingWidget::apply() +{ + if (m_settings->isDirty()) { + m_settings->apply(); + m_settings->writeSettings(Core::ICore::settings()); + } } + +// CMakeSpecificSettingsPage + +CMakeSpecificSettingsPage::CMakeSpecificSettingsPage(CMakeSpecificSettings *settings) +{ + setId("CMakeSpecificSettings"); + setDisplayName(CMakeSpecificSettingWidget::tr("CMake")); + setCategory(ProjectExplorer::Constants::BUILD_AND_RUN_SETTINGS_CATEGORY); + setWidgetCreator([settings] { return new CMakeSpecificSettingWidget(settings); }); } + +} // Internal +} // CMakeProjectManager diff --git a/src/plugins/cmakeprojectmanager/cmakespecificsettings.h b/src/plugins/cmakeprojectmanager/cmakespecificsettings.h index 273ae7937e1..753d3c9950f 100644 --- a/src/plugins/cmakeprojectmanager/cmakespecificsettings.h +++ b/src/plugins/cmakeprojectmanager/cmakespecificsettings.h @@ -25,9 +25,9 @@ #pragma once -#include +#include -#include +#include namespace CMakeProjectManager { namespace Internal { @@ -38,29 +38,43 @@ enum AfterAddFileAction : int { NEVER_COPY_FILE_PATH }; -class CMakeSpecificSettings +class CMakeSpecificSettings : public Utils::AspectContainer { + Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::Internal::CMakeSpecificSettings) + public: - CMakeSpecificSettings() = default; - void fromSettings(QSettings *settings); - void toSettings(QSettings *settings) const; + CMakeSpecificSettings(); - void setAfterAddFileSetting(AfterAddFileAction settings) { m_afterAddFileToProjectSetting = settings; } - AfterAddFileAction afterAddFileSetting() const { return m_afterAddFileToProjectSetting; } + void setAfterAddFileSetting(AfterAddFileAction settings) { + m_afterAddFileToProjectSetting.setValue(settings); + } + AfterAddFileAction afterAddFileSetting() const { + return static_cast(m_afterAddFileToProjectSetting.value()); + } - Utils::FilePath ninjaPath() const { return m_ninjaPath; } + Utils::FilePath ninjaPath() const { return m_ninjaPath.filePath(); } - void setPackageManagerAutoSetup(bool checked) { m_packageManagerAutoSetup = checked; } - bool packageManagerAutoSetup() const { return m_packageManagerAutoSetup; } + void setPackageManagerAutoSetup(bool checked) { m_packageManagerAutoSetup.setValue(checked); } + bool packageManagerAutoSetup() const { return m_packageManagerAutoSetup.value(); } + + void setAskBeforeReConfigureInitialParams(bool doAsk) { m_askBeforeReConfigureInitialParams.setValue(doAsk); } + bool askBeforeReConfigureInitialParams() const { return m_askBeforeReConfigureInitialParams.value(); } - bool askBeforeReConfigureInitialParams() const { return m_askBeforeReConfigureInitialParams; } - void setAskBeforeReConfigureInitialParams(bool doAsk) { m_askBeforeReConfigureInitialParams = doAsk; } private: - AfterAddFileAction m_afterAddFileToProjectSetting; - Utils::FilePath m_ninjaPath; - bool m_packageManagerAutoSetup = true; - bool m_askBeforeReConfigureInitialParams = true; + friend class CMakeSpecificSettingWidget; + + Utils::SelectionAspect m_afterAddFileToProjectSetting; + Utils::StringAspect m_ninjaPath; + Utils::BoolAspect m_packageManagerAutoSetup; + Utils::BoolAspect m_askBeforeReConfigureInitialParams; }; -} -} + +class CMakeSpecificSettingsPage final : public Core::IOptionsPage +{ +public: + explicit CMakeSpecificSettingsPage(CMakeSpecificSettings *settings); +}; + +} // Internal +} // CMakeProjectManager diff --git a/src/plugins/cmakeprojectmanager/cmakespecificsettingspage.cpp b/src/plugins/cmakeprojectmanager/cmakespecificsettingspage.cpp deleted file mode 100644 index 9653e32b7cd..00000000000 --- a/src/plugins/cmakeprojectmanager/cmakespecificsettingspage.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 "cmakespecificsettingspage.h" -#include "cmakespecificsettings.h" -#include "ui_cmakespecificsettingspage.h" - -#include -#include - -namespace CMakeProjectManager { -namespace Internal { - -class CMakeSpecificSettingWidget final : public Core::IOptionsPageWidget -{ - Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::Internal::CMakeSpecificSettingWidget) - -public: - explicit CMakeSpecificSettingWidget(CMakeSpecificSettings *settings); - - void apply() final; - -private: - Ui::CMakeSpecificSettingForm m_ui; - CMakeSpecificSettings *m_settings; -}; - -CMakeSpecificSettingWidget::CMakeSpecificSettingWidget(CMakeSpecificSettings *settings) - : m_settings(settings) -{ - m_ui.setupUi(this); - m_ui.newFileAddedCopyToCpliSettingGroup->setId(m_ui.alwaysAskRadio, - AfterAddFileAction::ASK_USER); - m_ui.newFileAddedCopyToCpliSettingGroup->setId(m_ui.neverCopyRadio, - AfterAddFileAction::NEVER_COPY_FILE_PATH); - m_ui.newFileAddedCopyToCpliSettingGroup->setId(m_ui.alwaysCopyRadio, - AfterAddFileAction::COPY_FILE_PATH); - - const AfterAddFileAction mode = settings->afterAddFileSetting(); - switch (mode) { - case ASK_USER: - m_ui.alwaysAskRadio->setChecked(true); - break; - case COPY_FILE_PATH: - m_ui.alwaysCopyRadio->setChecked(true); - break; - case NEVER_COPY_FILE_PATH: - m_ui.neverCopyRadio->setChecked(true); - break; - } - - m_ui.packageManagerAutoSetup->setChecked(settings->packageManagerAutoSetup()); - m_ui.askBeforeReConfigureWithInitialParams->setChecked(settings->askBeforeReConfigureInitialParams()); -} - -void CMakeSpecificSettingWidget::apply() -{ - int popupSetting = m_ui.newFileAddedCopyToCpliSettingGroup->checkedId(); - m_settings->setAfterAddFileSetting(popupSetting == -1 ? AfterAddFileAction::ASK_USER - : static_cast(popupSetting)); - m_settings->setPackageManagerAutoSetup(m_ui.packageManagerAutoSetup->isChecked()); - m_settings->setAskBeforeReConfigureInitialParams(m_ui.askBeforeReConfigureWithInitialParams->isChecked()); - m_settings->toSettings(Core::ICore::settings()); -} - -// CMakeSpecificSettingsPage - -CMakeSpecificSettingsPage::CMakeSpecificSettingsPage(CMakeSpecificSettings *settings) -{ - setId("CMakeSpecificSettings"); - setDisplayName(CMakeSpecificSettingWidget::tr("CMake")); - setCategory(ProjectExplorer::Constants::BUILD_AND_RUN_SETTINGS_CATEGORY); - setWidgetCreator([settings] { return new CMakeSpecificSettingWidget(settings); }); -} - -} // Internal -} // CMakeProjectManager diff --git a/src/plugins/cmakeprojectmanager/cmakespecificsettingspage.h b/src/plugins/cmakeprojectmanager/cmakespecificsettingspage.h deleted file mode 100644 index b277b5de89a..00000000000 --- a/src/plugins/cmakeprojectmanager/cmakespecificsettingspage.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -namespace CMakeProjectManager { -namespace Internal { - -class CMakeSpecificSettings; - -class CMakeSpecificSettingsPage final : public Core::IOptionsPage -{ -public: - explicit CMakeSpecificSettingsPage(CMakeSpecificSettings *settings); -}; - -} // Internal -} // CMakeProjectManager diff --git a/src/plugins/cmakeprojectmanager/cmakespecificsettingspage.ui b/src/plugins/cmakeprojectmanager/cmakespecificsettingspage.ui deleted file mode 100644 index b232685974c..00000000000 --- a/src/plugins/cmakeprojectmanager/cmakespecificsettingspage.ui +++ /dev/null @@ -1,100 +0,0 @@ - - - CMakeProjectManager::Internal::CMakeSpecificSettingForm - - - - 0 - 0 - 852 - 567 - - - - Form - - - - - - Determines whether file paths are copied to the clipboard for pasting to the CMakeLists.txt file when you add new files to CMake projects. - - - Adding Files - - - - - - - - Ask about copying file paths - - - newFileAddedCopyToCpliSettingGroup - - - - - - - Do not copy file paths - - - newFileAddedCopyToCpliSettingGroup - - - - - - - Copy file paths - - - newFileAddedCopyToCpliSettingGroup - - - - - - - - - - - - Add the CMAKE_PROJECT_INCLUDE_BEFORE variable pointing to a CMake script that will install dependencies from the conanfile.txt, conanfile.py, or vcpkg.json file from the project source directory. - - - Package manager auto setup - - - - - - - Ask before re-configuring with initial parameters - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - -