CMake: Aspectify CMakeSpecificSettings

Change-Id: I2e094c5a392964fdaf49ac30c2e0ae0f57a3b11d
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
hjk
2021-03-23 15:58:16 +01:00
parent a25ea9febe
commit beda749326
11 changed files with 120 additions and 295 deletions

View File

@@ -27,7 +27,6 @@ add_qtc_plugin(CMakeProjectManager
cmakeprojectplugin.cpp cmakeprojectplugin.h cmakeprojectplugin.cpp cmakeprojectplugin.h
cmakesettingspage.cpp cmakesettingspage.h cmakesettingspage.cpp cmakesettingspage.h
cmakespecificsettings.cpp cmakespecificsettings.h cmakespecificsettings.cpp cmakespecificsettings.h
cmakespecificsettingspage.cpp cmakespecificsettingspage.h cmakespecificsettingspage.ui
cmaketool.cpp cmaketool.h cmaketool.cpp cmaketool.h
cmaketoolmanager.cpp cmaketoolmanager.h cmaketoolmanager.cpp cmaketoolmanager.h
cmaketoolsettingsaccessor.cpp cmaketoolsettingsaccessor.h cmaketoolsettingsaccessor.cpp cmaketoolsettingsaccessor.h

View File

@@ -200,7 +200,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
QDialogButtonBox::Yes); QDialogButtonBox::Yes);
settings->setAskBeforeReConfigureInitialParams(!doNotAsk); settings->setAskBeforeReConfigureInitialParams(!doNotAsk);
settings->toSettings(Core::ICore::settings()); settings->writeSettings(Core::ICore::settings());
if (reply != QDialogButtonBox::Yes) { if (reply != QDialogButtonBox::Yes) {
return; return;

View File

@@ -122,7 +122,7 @@ void noAutoAdditionNotify(const QStringList &filePaths, const ProjectExplorer::P
settings->setAfterAddFileSetting( settings->setAfterAddFileSetting(
CMakeProjectManager::Internal::AfterAddFileAction::NEVER_COPY_FILE_PATH); CMakeProjectManager::Internal::AfterAddFileAction::NEVER_COPY_FILE_PATH);
settings->toSettings(Core::ICore::settings()); settings->writeSettings(Core::ICore::settings());
} }
if (QDialogButtonBox::Yes == reply) { if (QDialogButtonBox::Yes == reply) {

View File

@@ -27,7 +27,6 @@ HEADERS = builddirparameters.h \
cmakeindenter.h \ cmakeindenter.h \
cmakeautocompleter.h \ cmakeautocompleter.h \
cmakespecificsettings.h \ cmakespecificsettings.h \
cmakespecificsettingspage.h \
configmodel.h \ configmodel.h \
configmodelitemdelegate.h \ configmodelitemdelegate.h \
fileapidataextractor.h \ fileapidataextractor.h \
@@ -58,7 +57,6 @@ SOURCES = builddirparameters.cpp \
cmakeindenter.cpp \ cmakeindenter.cpp \
cmakeautocompleter.cpp \ cmakeautocompleter.cpp \
cmakespecificsettings.cpp \ cmakespecificsettings.cpp \
cmakespecificsettingspage.cpp \
configmodel.cpp \ configmodel.cpp \
configmodelitemdelegate.cpp \ configmodelitemdelegate.cpp \
fileapidataextractor.cpp \ fileapidataextractor.cpp \
@@ -67,6 +65,3 @@ SOURCES = builddirparameters.cpp \
projecttreehelper.cpp projecttreehelper.cpp
RESOURCES += cmakeproject.qrc RESOURCES += cmakeproject.qrc
FORMS += \
cmakespecificsettingspage.ui

View File

@@ -69,9 +69,6 @@ QtcPlugin {
"cmakeautocompleter.cpp", "cmakeautocompleter.cpp",
"cmakespecificsettings.h", "cmakespecificsettings.h",
"cmakespecificsettings.cpp", "cmakespecificsettings.cpp",
"cmakespecificsettingspage.h",
"cmakespecificsettingspage.cpp",
"cmakespecificsettingspage.ui",
"configmodel.cpp", "configmodel.cpp",
"configmodel.h", "configmodel.h",
"configmodelitemdelegate.cpp", "configmodelitemdelegate.cpp",

View File

@@ -37,7 +37,6 @@
#include "cmakeprojectnodes.h" #include "cmakeprojectnodes.h"
#include "cmakesettingspage.h" #include "cmakesettingspage.h"
#include "cmakespecificsettings.h" #include "cmakespecificsettings.h"
#include "cmakespecificsettingspage.h"
#include "cmaketoolmanager.h" #include "cmaketoolmanager.h"
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
@@ -100,7 +99,7 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
Q_UNUSED(errorMessage) Q_UNUSED(errorMessage)
d = new CMakeProjectPluginPrivate; d = new CMakeProjectPluginPrivate;
projectTypeSpecificSettings()->fromSettings(ICore::settings()); projectTypeSpecificSettings()->readSettings(ICore::settings());
const Context projectContext{CMakeProjectManager::Constants::CMAKE_PROJECT_ID}; const Context projectContext{CMakeProjectManager::Constants::CMAKE_PROJECT_ID};

View File

@@ -25,37 +25,99 @@
#include "cmakespecificsettings.h" #include "cmakespecificsettings.h"
#include <coreplugin/icore.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/layoutbuilder.h>
using namespace Utils;
namespace CMakeProjectManager { namespace CMakeProjectManager {
namespace Internal { namespace Internal {
namespace { CMakeSpecificSettings::CMakeSpecificSettings()
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)
{ {
const QString rootKey = QString(SETTINGS_KEY) + '/'; setSettingsGroup("CMakeSpecificSettings");
m_afterAddFileToProjectSetting = static_cast<AfterAddFileAction>( setAutoApply(false);
settings->value(rootKey + AFTER_ADD_FILE_ACTION_KEY,
static_cast<int>(AfterAddFileAction::ASK_USER)).toInt());
m_ninjaPath = Utils::FilePath::fromUserInput( registerAspect(&m_afterAddFileToProjectSetting);
settings->value(rootKey + NINJA_PATH, QString()).toString()); 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)); Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::Internal::CMakeSpecificSettingWidget)
settings->setValue(QString(AFTER_ADD_FILE_ACTION_KEY), static_cast<int>(m_afterAddFileToProjectSetting));
settings->setValue(QString(PACKAGE_MANAGER_AUTO_SETUP), m_packageManagerAutoSetup); public:
settings->setValue(QString(ASK_RECONFIGURE_INITIAL_PARAMS), m_askBeforeReConfigureInitialParams); explicit CMakeSpecificSettingWidget(CMakeSpecificSettings *settings);
settings->endGroup();
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

View File

@@ -25,9 +25,9 @@
#pragma once #pragma once
#include <utils/fileutils.h> #include <coreplugin/dialogs/ioptionspage.h>
#include <QSettings> #include <utils/aspects.h>
namespace CMakeProjectManager { namespace CMakeProjectManager {
namespace Internal { namespace Internal {
@@ -38,29 +38,43 @@ enum AfterAddFileAction : int {
NEVER_COPY_FILE_PATH NEVER_COPY_FILE_PATH
}; };
class CMakeSpecificSettings class CMakeSpecificSettings : public Utils::AspectContainer
{ {
Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::Internal::CMakeSpecificSettings)
public: public:
CMakeSpecificSettings() = default; CMakeSpecificSettings();
void fromSettings(QSettings *settings);
void toSettings(QSettings *settings) const;
void setAfterAddFileSetting(AfterAddFileAction settings) { m_afterAddFileToProjectSetting = settings; } void setAfterAddFileSetting(AfterAddFileAction settings) {
AfterAddFileAction afterAddFileSetting() const { return m_afterAddFileToProjectSetting; } m_afterAddFileToProjectSetting.setValue(settings);
}
AfterAddFileAction afterAddFileSetting() const {
return static_cast<AfterAddFileAction>(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; } void setPackageManagerAutoSetup(bool checked) { m_packageManagerAutoSetup.setValue(checked); }
bool packageManagerAutoSetup() const { return m_packageManagerAutoSetup; } 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: private:
AfterAddFileAction m_afterAddFileToProjectSetting; friend class CMakeSpecificSettingWidget;
Utils::FilePath m_ninjaPath;
bool m_packageManagerAutoSetup = true; Utils::SelectionAspect m_afterAddFileToProjectSetting;
bool m_askBeforeReConfigureInitialParams = true; 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

View File

@@ -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 <coreplugin/icore.h>
#include <projectexplorer/projectexplorerconstants.h>
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<AfterAddFileAction>(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

View File

@@ -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 <coreplugin/dialogs/ioptionspage.h>
namespace CMakeProjectManager {
namespace Internal {
class CMakeSpecificSettings;
class CMakeSpecificSettingsPage final : public Core::IOptionsPage
{
public:
explicit CMakeSpecificSettingsPage(CMakeSpecificSettings *settings);
};
} // Internal
} // CMakeProjectManager

View File

@@ -1,100 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CMakeProjectManager::Internal::CMakeSpecificSettingForm</class>
<widget class="QWidget" name="CMakeProjectManager::Internal::CMakeSpecificSettingForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>852</width>
<height>567</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="toolTip">
<string>Determines whether file paths are copied to the clipboard for pasting to the CMakeLists.txt file when you add new files to CMake projects.</string>
</property>
<property name="title">
<string>Adding Files</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="alwaysAskRadio">
<property name="text">
<string>Ask about copying file paths</string>
</property>
<attribute name="buttonGroup">
<string notr="true">newFileAddedCopyToCpliSettingGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="neverCopyRadio">
<property name="text">
<string>Do not copy file paths</string>
</property>
<attribute name="buttonGroup">
<string notr="true">newFileAddedCopyToCpliSettingGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="alwaysCopyRadio">
<property name="text">
<string>Copy file paths</string>
</property>
<attribute name="buttonGroup">
<string notr="true">newFileAddedCopyToCpliSettingGroup</string>
</attribute>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="packageManagerAutoSetup">
<property name="toolTip">
<string>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.</string>
</property>
<property name="text">
<string>Package manager auto setup</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="askBeforeReConfigureWithInitialParams">
<property name="text">
<string>Ask before re-configuring with initial parameters</string>
</property>
</widget>
</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>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="newFileAddedCopyToCpliSettingGroup"/>
</buttongroups>
</ui>