PerfProfiler: Move towards the canonical plugin setup pattern

Change-Id: I5d2f468c35c154664550175aefd21307b8107bba
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-03-13 13:07:09 +01:00
parent 164ae1428e
commit d0c052d23a
7 changed files with 42 additions and 24 deletions

View File

@@ -33,7 +33,7 @@
namespace PerfProfiler { namespace PerfProfiler {
namespace Internal { namespace Internal {
PerfOptionsPage::PerfOptionsPage(QObject *parent) : Core::IOptionsPage(parent) PerfOptionsPage::PerfOptionsPage()
{ {
setId(Constants::PerfSettingsId); setId(Constants::PerfSettingsId);
setDisplayName(QCoreApplication::translate("PerfProfiler::PerfOptionsPage", "CPU Usage")); setDisplayName(QCoreApplication::translate("PerfProfiler::PerfOptionsPage", "CPU Usage"));

View File

@@ -36,7 +36,7 @@ class PerfOptionsPage : public Core::IOptionsPage
{ {
Q_OBJECT Q_OBJECT
public: public:
PerfOptionsPage(QObject *parent = nullptr); PerfOptionsPage();
QWidget *widget(); QWidget *widget();
void apply(); void apply();

View File

@@ -52,32 +52,44 @@
#include <QAction> #include <QAction>
#include <QDebug> #include <QDebug>
#include <QMenu> #include <QMenu>
#include <QtPlugin>
using namespace ProjectExplorer; using namespace ProjectExplorer;
namespace PerfProfiler { namespace PerfProfiler {
namespace Internal {
Q_GLOBAL_STATIC(PerfSettings, perfGlobalSettings) Q_GLOBAL_STATIC(PerfSettings, perfGlobalSettings)
class PerfProfilerPluginPrivate
{
public:
PerfProfilerPluginPrivate()
{
RunConfiguration::registerAspect<PerfRunConfigurationAspect>();
RunControl::registerWorkerCreator(ProjectExplorer::Constants::PERFPROFILER_RUN_MODE,
[](RunControl *runControl){ return new PerfProfilerRunner(runControl); });
auto constraint = [](RunConfiguration *) { return true; };
RunControl::registerWorker<PerfProfilerRunner>
(ProjectExplorer::Constants::PERFPROFILER_RUN_MODE, constraint);
}
PerfOptionsPage optionsPage;
PerfProfilerTool profilerTool;
};
PerfProfilerPlugin::~PerfProfilerPlugin()
{
delete d;
}
bool PerfProfilerPlugin::initialize(const QStringList &arguments, QString *errorString) bool PerfProfilerPlugin::initialize(const QStringList &arguments, QString *errorString)
{ {
Q_UNUSED(arguments) Q_UNUSED(arguments)
Q_UNUSED(errorString) Q_UNUSED(errorString)
(void) new Internal::PerfOptionsPage(this); d = new PerfProfilerPluginPrivate;
RunConfiguration::registerAspect<PerfRunConfigurationAspect>();
(void) new Internal::PerfProfilerTool(this);
RunControl::registerWorkerCreator(ProjectExplorer::Constants::PERFPROFILER_RUN_MODE,
[](RunControl *runControl){ return new Internal::PerfProfilerRunner(runControl); });
auto constraint = [](RunConfiguration *) { return true; };
RunControl::registerWorker<Internal::PerfProfilerRunner>
(ProjectExplorer::Constants::PERFPROFILER_RUN_MODE, constraint);
return true; return true;
} }
@@ -85,19 +97,20 @@ void PerfProfilerPlugin::extensionsInitialized()
{ {
} }
PerfProfiler::PerfSettings *PerfProfilerPlugin::globalSettings() PerfSettings *PerfProfilerPlugin::globalSettings()
{ {
return perfGlobalSettings(); return perfGlobalSettings();
} }
QList<QObject *> PerfProfiler::PerfProfilerPlugin::createTestObjects() const QList<QObject *> PerfProfilerPlugin::createTestObjects() const
{ {
QList<QObject *> tests; QList<QObject *> tests;
#if WITH_TESTS #if WITH_TESTS
tests << new Internal::PerfProfilerTraceFileTest; tests << new PerfProfilerTraceFileTest;
tests << new Internal::PerfResourceCounterTest; tests << new PerfResourceCounterTest;
#endif // WITH_TESTS #endif // WITH_TESTS
return tests; return tests;
} }
} // namespace Internal
} // namespace PerfProfiler } // namespace PerfProfiler

View File

@@ -30,6 +30,7 @@
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
namespace PerfProfiler { namespace PerfProfiler {
namespace Internal {
class PerfProfilerPlugin : public ExtensionSystem::IPlugin class PerfProfilerPlugin : public ExtensionSystem::IPlugin
{ {
@@ -37,11 +38,16 @@ class PerfProfilerPlugin : public ExtensionSystem::IPlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "PerfProfiler.json") Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "PerfProfiler.json")
public: public:
~PerfProfilerPlugin();
bool initialize(const QStringList &arguments, QString *errorString) final; bool initialize(const QStringList &arguments, QString *errorString) final;
void extensionsInitialized() final; void extensionsInitialized() final;
QList<QObject *> createTestObjects() const final; QList<QObject *> createTestObjects() const final;
static PerfSettings *globalSettings(); static PerfSettings *globalSettings();
class PerfProfilerPluginPrivate *d = nullptr;
}; };
} // namespace Internal
} // namespace PerfProfiler } // namespace PerfProfiler

View File

@@ -69,8 +69,7 @@ namespace Internal {
static PerfProfilerTool *s_instance; static PerfProfilerTool *s_instance;
PerfProfilerTool::PerfProfilerTool(QObject *parent) : PerfProfilerTool::PerfProfilerTool()
QObject(parent)
{ {
s_instance = this; s_instance = this;
m_traceManager = new PerfProfilerTraceManager(this); m_traceManager = new PerfProfilerTraceManager(this);

View File

@@ -48,7 +48,7 @@ class PerfProfilerTool : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
PerfProfilerTool(QObject *parent = nullptr); PerfProfilerTool();
static PerfProfilerTool *instance(); static PerfProfilerTool *instance();
PerfProfilerTraceManager *traceManager() const; PerfProfilerTraceManager *traceManager() const;

View File

@@ -35,7 +35,7 @@ namespace PerfProfiler {
PerfRunConfigurationAspect::PerfRunConfigurationAspect(ProjectExplorer::Target *target) PerfRunConfigurationAspect::PerfRunConfigurationAspect(ProjectExplorer::Target *target)
{ {
setProjectSettings(new PerfSettings(target)); setProjectSettings(new PerfSettings(target));
setGlobalSettings(PerfProfilerPlugin::globalSettings()); setGlobalSettings(Internal::PerfProfilerPlugin::globalSettings());
setId(Constants::PerfSettingsId); setId(Constants::PerfSettingsId);
setDisplayName(QCoreApplication::translate("PerfProfiler::PerfRunConfigurationAspect", setDisplayName(QCoreApplication::translate("PerfProfiler::PerfRunConfigurationAspect",
"Performance Analyzer Settings")); "Performance Analyzer Settings"));