Core: PagedSettings, next attempt

We cannnot pass the LayoutItem directly but need the lambda
to postpone creation of aspect subwidgets until the settings
page gets into view.

Change-Id: I420e82f66fd5c4781451d6851cc38368e7501abc
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2023-05-10 12:59:35 +02:00
parent 72e30b69c5
commit 47e0e9be29
2 changed files with 14 additions and 17 deletions

View File

@@ -136,9 +136,6 @@ QWidget *IOptionsPage::widget()
if (!m_widget) {
if (m_widgetCreator) {
m_widget = m_widgetCreator();
} else if (m_layouter) {
m_widget = new QWidget;
m_layouter(m_widget);
} else {
QTC_CHECK(false);
}
@@ -157,9 +154,10 @@ QWidget *IOptionsPage::widget()
void IOptionsPage::apply()
{
if (auto widget = qobject_cast<IOptionsPageWidget *>(m_widget)) {
if (auto widget = qobject_cast<IOptionsPageWidget *>(m_widget))
widget->apply();
} else if (m_settings) {
if (m_settings) {
if (m_settings->isDirty()) {
m_settings->apply();
m_settings->writeSettings(ICore::settings());
@@ -180,7 +178,8 @@ void IOptionsPage::finish()
{
if (auto widget = qobject_cast<IOptionsPageWidget *>(m_widget))
widget->finish();
else if (m_settings)
if (m_settings)
m_settings->finish();
delete m_widget;
@@ -202,14 +201,10 @@ void IOptionsPage::setSettings(AspectContainer *settings)
void IOptionsPage::setLayouter(const std::function<void(QWidget *w)> &layouter)
{
m_layouter = layouter;
}
void IOptionsPage::setLayout(const Layouting::LayoutItem &layout)
{
using namespace Layouting;
m_layouter = [layout](QWidget *widget) {
Column { Row { Column { layout, st }, st } }.attachTo(widget);
m_widgetCreator = [layouter] {
auto widget = new IOptionsPageWidget;
layouter(widget);
return widget;
};
}
@@ -306,4 +301,8 @@ QIcon IOptionsPageProvider::categoryIcon() const
return m_categoryIcon.icon();
}
// PagedSettings
PagedSettings::PagedSettings() = default;
} // Core

View File

@@ -75,7 +75,6 @@ protected:
void setCategoryIconPath(const Utils::FilePath &categoryIconPath);
void setSettings(Utils::AspectContainer *settings);
void setLayouter(const std::function<void(QWidget *w)> &layouter);
void setLayout(const Layouting::LayoutItem &layout);
// Used in FontSettingsPage. FIXME?
QPointer<QWidget> m_widget; // Used in conjunction with m_widgetCreator
@@ -92,7 +91,6 @@ private:
mutable QStringList m_keywords;
Utils::AspectContainer *m_settings = nullptr;
std::function<void(QWidget *w)> m_layouter;
};
/*
@@ -133,7 +131,7 @@ protected:
class CORE_EXPORT PagedSettings : public Utils::AspectContainer, public IOptionsPage
{
public:
PagedSettings() = default;
PagedSettings();
};
} // namespace Core