Qbs: Use IOptionPage::setWidgetCreator() for settings

Change-Id: Idae8c17a8922b60ad9dee3595176d11e0b96fee8
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-04-20 10:56:28 +02:00
parent 55d51e8b5e
commit 498bad56b2
4 changed files with 20 additions and 77 deletions

View File

@@ -26,8 +26,7 @@
using namespace ProjectExplorer;
namespace QbsProjectManager {
namespace Internal {
namespace QbsProjectManager::Internal {
class ProfileTreeItem : public Utils::TypedTreeItem<ProfileTreeItem, ProfileTreeItem>
{
@@ -53,7 +52,6 @@ private:
class ProfileModel : public Utils::TreeModel<ProfileTreeItem>
{
Q_OBJECT
public:
ProfileModel() : TreeModel(static_cast<QObject *>(nullptr))
{
@@ -91,13 +89,14 @@ public:
}
};
class QbsProfilesSettingsWidget : public QWidget
class QbsProfilesSettingsWidget : public Core::IOptionsPageWidget
{
Q_OBJECT
public:
QbsProfilesSettingsWidget();
private:
void apply() final {}
void refreshKitsList();
void displayCurrentProfile();
@@ -112,19 +111,7 @@ QbsProfilesSettingsPage::QbsProfilesSettingsPage()
setId("Y.QbsProfiles");
setDisplayName(Tr::tr("Profiles"));
setCategory(Constants::QBS_SETTINGS_CATEGORY);
}
QWidget *QbsProfilesSettingsPage::widget()
{
if (!m_widget)
m_widget = new QbsProfilesSettingsWidget;
return m_widget;
}
void QbsProfilesSettingsPage::finish()
{
delete m_widget;
m_widget = nullptr;
setWidgetCreator([] { return new QbsProfilesSettingsWidget; });
}
QbsProfilesSettingsWidget::QbsProfilesSettingsWidget()
@@ -211,7 +198,4 @@ void QbsProfilesSettingsWidget::displayCurrentProfile()
}
}
} // namespace Internal
} // namespace QbsProjectManager
#include "qbsprofilessettingspage.moc"
} // QbsProjectManager::Internal

View File

@@ -5,22 +5,12 @@
#include <coreplugin/dialogs/ioptionspage.h>
namespace QbsProjectManager {
namespace Internal {
class QbsProfilesSettingsWidget;
namespace QbsProjectManager::Internal {
class QbsProfilesSettingsPage : public Core::IOptionsPage
{
public:
QbsProfilesSettingsPage();
private:
QWidget *widget() override;
void apply() override { }
void finish() override;
QbsProfilesSettingsWidget *m_widget = nullptr;
};
} // namespace Internal
} // namespace QbsProjectManager
} // QbsProjectManager::Internal

View File

@@ -21,8 +21,7 @@
using namespace Utils;
namespace QbsProjectManager {
namespace Internal {
namespace QbsProjectManager::Internal {
const char QBS_EXE_KEY[] = "QbsProjectManager/QbsExecutable";
const char QBS_DEFAULT_INSTALL_DIR_KEY[] = "QbsProjectManager/DefaultInstallDir";
@@ -142,10 +141,10 @@ void QbsSettings::storeSettings() const
s->setValue(USE_CREATOR_SETTINGS_KEY, m_settings.useCreatorSettings);
}
class QbsSettingsPage::SettingsWidget : public QWidget
class QbsSettingsPageWidget : public Core::IOptionsPageWidget
{
public:
SettingsWidget()
QbsSettingsPageWidget()
{
m_qbsExePathChooser.setExpectedKind(PathChooser::ExistingCommand);
m_qbsExePathChooser.setFilePath(QbsSettings::qbsExecutableFilePath());
@@ -166,7 +165,7 @@ public:
});
}
void apply()
void apply() final
{
QbsSettingsData settings = QbsSettings::rawSettingsData();
if (m_qbsExePathChooser.filePath() != QbsSettings::qbsExecutableFilePath())
@@ -197,26 +196,7 @@ QbsSettingsPage::QbsSettingsPage()
setCategory(Constants::QBS_SETTINGS_CATEGORY);
setDisplayCategory(Tr::tr(Constants::QBS_SETTINGS_TR_CATEGORY));
setCategoryIconPath(":/qbsprojectmanager/images/settingscategory_qbsprojectmanager.png");
setWidgetCreator([] { return new QbsSettingsPageWidget; });
}
QWidget *QbsSettingsPage::widget()
{
if (!m_widget)
m_widget = new SettingsWidget;
return m_widget;
}
void QbsSettingsPage::apply()
{
if (m_widget)
m_widget->apply();
}
void QbsSettingsPage::finish()
{
delete m_widget;
}
} // namespace Internal
} // namespace QbsProjectManager
} // QbsProjectManager::Internal

View File

@@ -4,16 +4,15 @@
#pragma once
#include <coreplugin/dialogs/ioptionspage.h>
#include <utils/fileutils.h>
#include <QObject>
#include <QPointer>
#include <utils/filepath.h>
#include <QVersionNumber>
namespace QbsProjectManager {
namespace Internal {
namespace QbsProjectManager::Internal {
class QbsSettingsData {
class QbsSettingsData
{
public:
Utils::FilePath qbsExecutableFilePath;
QString defaultInstallDirTemplate;
@@ -51,18 +50,8 @@ private:
class QbsSettingsPage : public Core::IOptionsPage
{
Q_OBJECT
public:
QbsSettingsPage();
private:
QWidget *widget() override;
void apply() override;
void finish() override;
class SettingsWidget;
QPointer<SettingsWidget> m_widget;
};
} // namespace Internal
} // namespace QbsProjectManager
} // QbsProjectManager::Internal