QmlProfiler: Use IOptionPage::setWidgetCreator() for settings

Change-Id: If9371820abf4e86e7041a7a5555c0a043de5ae3f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-04-20 10:58:51 +02:00
parent 16100acdc9
commit 977689b4a9
2 changed files with 26 additions and 47 deletions

View File

@@ -17,24 +17,32 @@
using namespace Utils; using namespace Utils;
namespace QmlProfiler { namespace QmlProfiler::Internal {
namespace Internal {
static QWidget *createQmlConfigWidget(QmlProfilerSettings *settings) class QmlProfilerOptionsPageWidget : public Core::IOptionsPageWidget
{ {
QmlProfilerSettings &s = *settings; public:
using namespace Layouting; explicit QmlProfilerOptionsPageWidget(QmlProfilerSettings *settings)
{
QmlProfilerSettings &s = *settings;
return Form { using namespace Layouting;
s.flushEnabled, Form {
s.flushInterval, s.flushEnabled,
s.aggregateTraces s.flushInterval,
}.emerge(); s.aggregateTraces
} }.attachTo(this);
}
void apply() final
{
QmlProfilerPlugin::globalSettings()->writeGlobalSettings();
}
};
QmlProfilerSettings::QmlProfilerSettings() QmlProfilerSettings::QmlProfilerSettings()
{ {
setConfigWidgetCreator([this] { return createQmlConfigWidget(this); }); setConfigWidgetCreator([this] { return new QmlProfilerOptionsPageWidget(this); });
setSettingsGroup(Constants::ANALYZER); setSettingsGroup(Constants::ANALYZER);
@@ -85,25 +93,9 @@ QmlProfilerOptionsPage::QmlProfilerOptionsPage()
setCategory("T.Analyzer"); setCategory("T.Analyzer");
setDisplayCategory(::Debugger::Tr::tr("Analyzer")); setDisplayCategory(::Debugger::Tr::tr("Analyzer"));
setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER); setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER);
setWidgetCreator([] {
return new QmlProfilerOptionsPageWidget(QmlProfilerPlugin::globalSettings());
});
} }
QWidget *QmlProfilerOptionsPage::widget() } // QmlProfiler::Internal
{
// We cannot parent the widget to the options page as it expects a QWidget as parent
if (!m_widget)
m_widget = createQmlConfigWidget(QmlProfilerPlugin::globalSettings());
return m_widget;
}
void QmlProfilerOptionsPage::apply()
{
QmlProfilerPlugin::globalSettings()->writeGlobalSettings();
}
void QmlProfilerOptionsPage::finish()
{
delete m_widget;
}
} // Internal
} // QmlProfiler

View File

@@ -7,15 +7,10 @@
#include <projectexplorer/runconfiguration.h> #include <projectexplorer/runconfiguration.h>
#include <QPointer> namespace QmlProfiler::Internal {
namespace QmlProfiler {
namespace Internal {
class QmlProfilerSettings : public ProjectExplorer::ISettingsAspect class QmlProfilerSettings : public ProjectExplorer::ISettingsAspect
{ {
Q_OBJECT
public: public:
QmlProfilerSettings(); QmlProfilerSettings();
@@ -31,14 +26,6 @@ class QmlProfilerOptionsPage final : public Core::IOptionsPage
{ {
public: public:
QmlProfilerOptionsPage(); QmlProfilerOptionsPage();
QWidget *widget() override;
void apply() override;
void finish() override;
private:
QPointer<QWidget> m_widget;
}; };
} // Internal } // QmlProfiler::Internal
} // QmlProfiler