CMake: Use IOptionPage convenience pattern

du -s .obj: 108344 -> 106748

Change-Id: I3c3ce0af0f0ba2e32e349d38e8a0a24feeb57485
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2020-01-10 13:05:44 +01:00
parent f1d0b41a7b
commit fae66e781a
6 changed files with 42 additions and 85 deletions

View File

@@ -29,6 +29,7 @@
#include "cmakeproject.h"
#include "cmakeprojectconstants.h"
#include "cmakeprojectplugin.h"
#include "cmakespecificsettings.h"
#include <android/androidconstants.h>

View File

@@ -37,6 +37,7 @@
#include "cmakesettingspage.h"
#include "cmaketoolmanager.h"
#include "cmakekitinformation.h"
#include "cmakespecificsettings.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>

View File

@@ -524,7 +524,8 @@ void CMakeToolItemConfigWidget::load(const CMakeToolTreeItem *item)
class CMakeToolConfigWidget : public Core::IOptionsPageWidget
{
Q_OBJECT
Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::Internal::CMakeToolConfigWidget)
public:
CMakeToolConfigWidget()
{
@@ -689,12 +690,10 @@ void CMakeToolConfigWidget::currentCMakeToolChanged(const QModelIndex &newCurren
CMakeSettingsPage::CMakeSettingsPage()
{
setId(Constants::CMAKE_SETTINGSPAGE_ID);
setDisplayName(tr("CMake"));
setDisplayName(CMakeToolConfigWidget::tr("CMake"));
setCategory(ProjectExplorer::Constants::KITS_SETTINGS_CATEGORY);
setWidgetCreator([] { return new CMakeToolConfigWidget; });
}
} // namespace Internal
} // namespace CMakeProjectManager
#include "cmakesettingspage.moc"

View File

@@ -32,8 +32,6 @@ namespace Internal {
class CMakeSettingsPage : public Core::IOptionsPage
{
Q_OBJECT
public:
CMakeSettingsPage();
};

View File

@@ -24,6 +24,8 @@
****************************************************************************/
#include "cmakespecificsettingspage.h"
#include "cmakespecificsettings.h"
#include "ui_cmakespecificsettingspage.h"
#include <coreplugin/icore.h>
#include <projectexplorer/projectexplorerconstants.h>
@@ -31,7 +33,23 @@
namespace CMakeProjectManager {
namespace Internal {
CMakeSpecificSettingWidget::CMakeSpecificSettingWidget()
class CMakeSpecificSettingWidget final : public Core::IOptionsPageWidget
{
Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::Internal::CMakeSpecificSettingWidget)
public:
explicit CMakeSpecificSettingWidget(CMakeSpecificSettings *settings);
void apply() final;
void finish() 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,
@@ -40,68 +58,37 @@ CMakeSpecificSettingWidget::CMakeSpecificSettingWidget()
AfterAddFileAction::NEVER_COPY_FILE_PATH);
m_ui.newFileAddedCopyToCpliSettingGroup->setId(m_ui.alwaysCopyRadio,
AfterAddFileAction::COPY_FILE_PATH);
}
void CMakeSpecificSettingWidget::setSettings(const CMakeSpecificSettings &settings)
{
setProjectPopupSetting(settings.afterAddFileSetting());
}
CMakeSpecificSettings CMakeSpecificSettingWidget::settings() const
{
CMakeSpecificSettings set;
int popupSetting = m_ui.newFileAddedCopyToCpliSettingGroup->checkedId();
set.setAfterAddFileSetting(popupSetting == -1 ? AfterAddFileAction::ASK_USER
: static_cast<AfterAddFileAction>(popupSetting));
return set;
}
void CMakeSpecificSettingWidget::setProjectPopupSetting(AfterAddFileAction mode)
{
const AfterAddFileAction mode = settings->afterAddFileSetting();
switch (mode) {
case CMakeProjectManager::Internal::ASK_USER:
case ASK_USER:
m_ui.alwaysAskRadio->setChecked(true);
break;
case CMakeProjectManager::Internal::COPY_FILE_PATH:
case COPY_FILE_PATH:
m_ui.alwaysCopyRadio->setChecked(true);
break;
case CMakeProjectManager::Internal::NEVER_COPY_FILE_PATH:
case NEVER_COPY_FILE_PATH:
m_ui.neverCopyRadio->setChecked(true);
break;
}
}
CMakeSpecificSettingsPage::CMakeSpecificSettingsPage(CMakeSpecificSettings *settings)
: m_settings(settings)
void CMakeSpecificSettingWidget::apply()
{
setId("CMakeSpecificSettings");
setDisplayName(tr("CMake"));
setCategory(ProjectExplorer::Constants::BUILD_AND_RUN_SETTINGS_CATEGORY);
}
QWidget *CMakeSpecificSettingsPage::widget()
{
if (!m_widget) {
m_widget = new CMakeSpecificSettingWidget();
m_widget->setSettings(*m_settings);
}
return m_widget;
}
void CMakeSpecificSettingsPage::apply()
{
if (!m_widget) // page was never shown
return;
const CMakeSpecificSettings newSettings = m_widget->settings();
*m_settings = newSettings;
int popupSetting = m_ui.newFileAddedCopyToCpliSettingGroup->checkedId();
m_settings->setAfterAddFileSetting(popupSetting == -1 ? AfterAddFileAction::ASK_USER
: static_cast<AfterAddFileAction>(popupSetting));
m_settings->toSettings(Core::ICore::settings());
}
void CMakeSpecificSettingsPage::finish()
// CMakeSpecificSettingsPage
CMakeSpecificSettingsPage::CMakeSpecificSettingsPage(CMakeSpecificSettings *settings)
{
delete m_widget;
m_widget = nullptr;
setId("CMakeSpecificSettings");
setDisplayName(CMakeSpecificSettingWidget::tr("CMake"));
setCategory(ProjectExplorer::Constants::BUILD_AND_RUN_SETTINGS_CATEGORY);
setWidgetCreator([settings] { return new CMakeSpecificSettingWidget(settings); });
}
} // Internal

View File

@@ -25,46 +25,17 @@
#pragma once
#include "cmakespecificsettings.h"
#include "ui_cmakespecificsettingspage.h"
#include <coreplugin/dialogs/ioptionspage.h>
#include <QPointer>
namespace CMakeProjectManager {
namespace Internal {
class CMakeSpecificSettingWidget : public QWidget
class CMakeSpecificSettings;
class CMakeSpecificSettingsPage final : public Core::IOptionsPage
{
Q_OBJECT
public:
CMakeSpecificSettingWidget();
void setSettings(const CMakeSpecificSettings &settings);
CMakeSpecificSettings settings() const;
private:
Ui::CMakeSpecificSettingForm m_ui;
void setProjectPopupSetting(AfterAddFileAction mode);
};
class CMakeSpecificSettingsPage : public Core::IOptionsPage
{
Q_OBJECT
public:
explicit CMakeSpecificSettingsPage(CMakeSpecificSettings *settings);
QWidget *widget() override;
void apply() override;
void finish() override;
private:
CMakeSpecificSettings * const m_settings = nullptr;
QPointer<CMakeSpecificSettingWidget> m_widget;
};
} // Internal