Perf: Move closer to now-standard option page setup

The aspect widgets need to serve two purposes (global settings,
and in run configurations), but that's still possible with
an IOptionPageWidget base, the in-project use simply never
triggers the apply().

Change-Id: I1344a37b6dba558b950904378443682b5a068214
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2020-01-27 11:39:22 +01:00
parent 56febd062c
commit 218b6ac491
5 changed files with 23 additions and 35 deletions

View File

@@ -62,9 +62,11 @@ public:
const QModelIndex &index) const override; const QModelIndex &index) const override;
}; };
PerfConfigWidget::PerfConfigWidget(PerfSettings *settings, QWidget *parent) : PerfConfigWidget::PerfConfigWidget(PerfSettings *settings, QWidget *parent)
QWidget(parent), m_settings(settings), m_ui(new Ui::PerfConfigWidget) : m_settings(settings), m_ui(new Ui::PerfConfigWidget)
{ {
setParent(parent);
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->useTracePointsButton->setVisible(false); m_ui->useTracePointsButton->setVisible(false);
@@ -178,6 +180,11 @@ void PerfConfigWidget::setTracePointsButtonVisible(bool visible)
m_ui->useTracePointsButton->setVisible(visible); m_ui->useTracePointsButton->setVisible(visible);
} }
void PerfConfigWidget::apply()
{
m_settings->writeGlobalSettings();
}
void PerfConfigWidget::readTracePoints() void PerfConfigWidget::readTracePoints()
{ {
QMessageBox messageBox; QMessageBox messageBox;

View File

@@ -27,24 +27,27 @@
#include "perfsettings.h" #include "perfsettings.h"
#include <QWidget> #include <coreplugin/dialogs/ioptionspage.h>
namespace PerfProfiler { namespace PerfProfiler {
namespace Internal { namespace Internal {
namespace Ui { class PerfConfigWidget; } namespace Ui { class PerfConfigWidget; }
class PerfConfigWidget : public QWidget class PerfConfigWidget : public Core::IOptionsPageWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit PerfConfigWidget(PerfSettings *settings, QWidget *parent = nullptr); explicit PerfConfigWidget(PerfSettings *settings, QWidget *parent = nullptr);
~PerfConfigWidget(); ~PerfConfigWidget();
void updateUi(); void updateUi();
void setTarget(ProjectExplorer::Target *target); void setTarget(ProjectExplorer::Target *target);
void setTracePointsButtonVisible(bool visible); void setTracePointsButtonVisible(bool visible);
private: private:
void apply() final;
void readTracePoints(); void readTracePoints();
void handleProcessFinished(); void handleProcessFinished();
void handleProcessError(QProcess::ProcessError error); void handleProcessError(QProcess::ProcessError error);

View File

@@ -23,40 +23,24 @@
** **
****************************************************************************/ ****************************************************************************/
#include "perfconfigwidget.h"
#include "perfoptionspage.h" #include "perfoptionspage.h"
#include "perfconfigwidget.h"
#include "perfprofilerconstants.h" #include "perfprofilerconstants.h"
#include "perfprofilerplugin.h"
#include <debugger/analyzer/analyzericons.h> #include <debugger/analyzer/analyzericons.h>
namespace PerfProfiler { namespace PerfProfiler {
namespace Internal { namespace Internal {
PerfOptionsPage::PerfOptionsPage() PerfOptionsPage::PerfOptionsPage(PerfSettings *settings)
{ {
setId(Constants::PerfSettingsId); setId(Constants::PerfSettingsId);
setDisplayName(QCoreApplication::translate("PerfProfiler::PerfOptionsPage", "CPU Usage")); setDisplayName(QCoreApplication::translate("PerfProfiler::PerfOptionsPage", "CPU Usage"));
setCategory("T.Analyzer"); setCategory("T.Analyzer");
setDisplayCategory(QCoreApplication::translate("Analyzer", "Analyzer")); setDisplayCategory(QCoreApplication::translate("Analyzer", "Analyzer"));
setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER); setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER);
} setWidgetCreator([settings] { return new PerfConfigWidget(settings); });
QWidget *PerfOptionsPage::widget()
{
if (!m_widget)
m_widget = new PerfConfigWidget(PerfProfilerPlugin::globalSettings());
return m_widget;
}
void PerfOptionsPage::apply()
{
PerfProfilerPlugin::globalSettings()->writeGlobalSettings();
}
void PerfOptionsPage::finish()
{
delete m_widget;
} }
} // namespace Internal } // namespace Internal

View File

@@ -27,23 +27,17 @@
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
#include <QPointer>
namespace PerfProfiler { namespace PerfProfiler {
class PerfSettings;
namespace Internal { namespace Internal {
class PerfOptionsPage : public Core::IOptionsPage class PerfOptionsPage : public Core::IOptionsPage
{ {
Q_OBJECT Q_OBJECT
public: public:
PerfOptionsPage(); explicit PerfOptionsPage(PerfSettings *settings);
QWidget *widget();
void apply();
void finish();
private:
QPointer<QWidget> m_widget;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -73,7 +73,7 @@ public:
{ProjectExplorer::Constants::PERFPROFILER_RUN_MODE} {ProjectExplorer::Constants::PERFPROFILER_RUN_MODE}
}; };
PerfOptionsPage optionsPage; PerfOptionsPage optionsPage{perfGlobalSettings()};
PerfProfilerTool profilerTool; PerfProfilerTool profilerTool;
}; };