QmlProfiler: Shuffle tool widget creation around

Put the border between plugin code and view code in a more
natural place.

Change-Id: Ib5250a30e52ec9899dcb01bac23cdad62a2d5c5e
Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
This commit is contained in:
hjk
2016-03-03 10:47:02 +01:00
parent 3cffacdd0f
commit 55dcec95f7
3 changed files with 103 additions and 124 deletions

View File

@@ -29,7 +29,6 @@
#include "qmlprofilertool.h" #include "qmlprofilertool.h"
#include "qmlprofilertimelinemodel.h" #include "qmlprofilertimelinemodel.h"
#include <debugger/analyzer/analyzermanager.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
@@ -61,41 +60,10 @@ void QmlProfilerPlugin::extensionsInitialized()
{ {
factory = ExtensionSystem::PluginManager::getObject<QmlProfilerTimelineModelFactory>(); factory = ExtensionSystem::PluginManager::getObject<QmlProfilerTimelineModelFactory>();
auto tool = new QmlProfilerTool(this); (void) new QmlProfilerTool(this);
auto runControlCreator = [tool](ProjectExplorer::RunConfiguration *runConfiguration, Core::Id) {
return tool->createRunControl(runConfiguration);
};
QString description = QmlProfilerTool::tr(
"The QML Profiler can be used to find performance bottlenecks in "
"applications using QML.");
ActionDescription desc;
desc.setText(tr("QML Profiler"));
desc.setToolTip(description);
desc.setPerspectiveId(Constants::QmlProfilerPerspectiveId);
desc.setRunControlCreator(runControlCreator);
desc.setToolPreparer([tool] { return tool->prepareTool(); });
desc.setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
AnalyzerManager::registerAction(Constants::QmlProfilerLocalActionId, desc);
desc.setText(tr("QML Profiler (External)"));
desc.setToolTip(description);
desc.setPerspectiveId(Constants::QmlProfilerPerspectiveId);
desc.setRunControlCreator(runControlCreator);
desc.setCustomToolStarter([tool](ProjectExplorer::RunConfiguration *rc) {
tool->startRemoteTool(rc);
});
desc.setToolPreparer([tool] { return tool->prepareTool(); });
desc.setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
AnalyzerManager::registerAction(Constants::QmlProfilerRemoteActionId, desc);
addAutoReleasedObject(new QmlProfilerRunControlFactory()); addAutoReleasedObject(new QmlProfilerRunControlFactory());
addAutoReleasedObject(new Internal::QmlProfilerOptionsPage()); addAutoReleasedObject(new Internal::QmlProfilerOptionsPage());
AnalyzerManager::registerToolbar(Constants::QmlProfilerPerspectiveId, tool->createWidgets());
} }
ExtensionSystem::IPlugin::ShutdownFlag QmlProfilerPlugin::aboutToShutdown() ExtensionSystem::IPlugin::ShutdownFlag QmlProfilerPlugin::aboutToShutdown()

View File

@@ -94,32 +94,32 @@ namespace Internal {
class QmlProfilerTool::QmlProfilerToolPrivate class QmlProfilerTool::QmlProfilerToolPrivate
{ {
public: public:
QmlProfilerStateManager *m_profilerState; QmlProfilerStateManager *m_profilerState = 0;
QmlProfilerClientManager *m_profilerConnections; QmlProfilerClientManager *m_profilerConnections = 0;
QmlProfilerModelManager *m_profilerModelManager; QmlProfilerModelManager *m_profilerModelManager = 0;
QmlProfilerViewManager *m_viewContainer; QmlProfilerViewManager *m_viewContainer = 0;
Utils::FileInProjectFinder m_projectFinder; Utils::FileInProjectFinder m_projectFinder;
QToolButton *m_recordButton; QToolButton *m_recordButton = 0;
QMenu *m_recordFeaturesMenu; QMenu *m_recordFeaturesMenu = 0;
QToolButton *m_clearButton; QToolButton *m_clearButton = 0;
// elapsed time display // elapsed time display
QTimer m_recordingTimer; QTimer m_recordingTimer;
QTime m_recordingElapsedTime; QTime m_recordingElapsedTime;
QLabel *m_timeLabel; QLabel *m_timeLabel = 0;
// open search // open search
QToolButton *m_searchButton; QToolButton *m_searchButton = 0;
// hide and show categories // hide and show categories
QToolButton *m_displayFeaturesButton; QToolButton *m_displayFeaturesButton = 0;
QMenu *m_displayFeaturesMenu; QMenu *m_displayFeaturesMenu = 0;
// save and load actions // save and load actions
QAction *m_saveQmlTrace; QAction *m_saveQmlTrace = 0;
QAction *m_loadQmlTrace; QAction *m_loadQmlTrace = 0;
}; };
QmlProfilerTool::QmlProfilerTool(QObject *parent) QmlProfilerTool::QmlProfilerTool(QObject *parent)
@@ -127,16 +127,6 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent)
{ {
setObjectName(QLatin1String("QmlProfilerTool")); setObjectName(QLatin1String("QmlProfilerTool"));
d->m_profilerState = 0;
d->m_viewContainer = 0;
d->m_recordButton = 0;
d->m_recordFeaturesMenu = 0;
d->m_clearButton = 0;
d->m_timeLabel = 0;
d->m_searchButton = 0;
d->m_displayFeaturesButton = 0;
d->m_displayFeaturesMenu = 0;
d->m_profilerState = new QmlProfilerStateManager(this); d->m_profilerState = new QmlProfilerStateManager(this);
connect(d->m_profilerState, &QmlProfilerStateManager::stateChanged, connect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
this, &QmlProfilerTool::profilerStateChanged); this, &QmlProfilerTool::profilerStateChanged);
@@ -186,72 +176,6 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent)
d->m_recordingTimer.setInterval(100); d->m_recordingTimer.setInterval(100);
connect(&d->m_recordingTimer, &QTimer::timeout, this, &QmlProfilerTool::updateTimeDisplay); connect(&d->m_recordingTimer, &QTimer::timeout, this, &QmlProfilerTool::updateTimeDisplay);
}
QmlProfilerTool::~QmlProfilerTool()
{
delete d;
}
static QString sysroot(RunConfiguration *runConfig)
{
QTC_ASSERT(runConfig, return QString());
Kit *k = runConfig->target()->kit();
if (k && SysRootKitInformation::hasSysRoot(k))
return SysRootKitInformation::sysRoot(runConfig->target()->kit()).toString();
return QString();
}
AnalyzerRunControl *QmlProfilerTool::createRunControl(RunConfiguration *runConfiguration)
{
QmlProfilerRunConfigurationAspect *aspect = static_cast<QmlProfilerRunConfigurationAspect *>(
runConfiguration->extraAspect(Constants::SETTINGS));
QTC_ASSERT(aspect, return 0);
QmlProfilerSettings *settings = static_cast<QmlProfilerSettings *>(aspect->currentSettings());
QTC_ASSERT(settings, return 0);
d->m_profilerConnections->setFlushInterval(settings->flushEnabled() ?
settings->flushInterval() : 0);
d->m_profilerConnections->setAggregateTraces(settings->aggregateTraces());
return new QmlProfilerRunControl(runConfiguration, this);
}
void QmlProfilerTool::finalizeRunControl(QmlProfilerRunControl *runControl)
{
runControl->registerProfilerStateManager(d->m_profilerState);
// FIXME: Check that there's something sensible in sp.connParams
auto connection = runControl->connection().as<AnalyzerConnection>();
if (!connection.analyzerSocket.isEmpty())
d->m_profilerConnections->setLocalSocket(connection.analyzerSocket);
else
d->m_profilerConnections->setTcpConnection(connection.analyzerHost, connection.analyzerPort);
//
// Initialize m_projectFinder
//
RunConfiguration *runConfiguration = runControl->runConfiguration();
QString projectDirectory;
if (runConfiguration) {
Project *project = runConfiguration->target()->project();
projectDirectory = project->projectDirectory().toString();
}
populateFileFinder(projectDirectory, sysroot(runConfiguration));
if (connection.analyzerSocket.isEmpty())
connect(runControl, &QmlProfilerRunControl::processRunning,
d->m_profilerConnections, &QmlProfilerClientManager::connectTcpClient);
connect(d->m_profilerConnections, &QmlProfilerClientManager::connectionFailed,
runControl, &QmlProfilerRunControl::cancelProcess);
}
QWidget *QmlProfilerTool::createWidgets()
{
QTC_ASSERT(!d->m_viewContainer, return 0);
d->m_viewContainer = new QmlProfilerViewManager(this, d->m_viewContainer = new QmlProfilerViewManager(this,
@@ -332,7 +256,95 @@ QWidget *QmlProfilerTool::createWidgets()
// is available, then we can populate the file finder // is available, then we can populate the file finder
populateFileFinder(); populateFileFinder();
return toolbarWidget; auto runControlCreator = [this](RunConfiguration *runConfiguration, Core::Id) {
return createRunControl(runConfiguration);
};
QString description = tr("The QML Profiler can be used to find performance "
"bottlenecks in applications using QML.");
ActionDescription desc;
desc.setText(tr("QML Profiler"));
desc.setToolTip(description);
desc.setPerspectiveId(Constants::QmlProfilerPerspectiveId);
desc.setRunControlCreator(runControlCreator);
desc.setToolPreparer([this] { return prepareTool(); });
desc.setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);
AnalyzerManager::registerAction(Constants::QmlProfilerLocalActionId, desc);
desc.setText(tr("QML Profiler (External)"));
desc.setToolTip(description);
desc.setPerspectiveId(Constants::QmlProfilerPerspectiveId);
desc.setRunControlCreator(runControlCreator);
desc.setCustomToolStarter([this](RunConfiguration *rc) { startRemoteTool(rc); });
desc.setToolPreparer([this] { return prepareTool(); });
desc.setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
desc.setMenuGroup(Analyzer::Constants::G_ANALYZER_REMOTE_TOOLS);
AnalyzerManager::registerAction(Constants::QmlProfilerRemoteActionId, desc);
AnalyzerManager::registerToolbar(Constants::QmlProfilerPerspectiveId, toolbarWidget);
}
QmlProfilerTool::~QmlProfilerTool()
{
delete d;
}
static QString sysroot(RunConfiguration *runConfig)
{
QTC_ASSERT(runConfig, return QString());
Kit *k = runConfig->target()->kit();
if (k && SysRootKitInformation::hasSysRoot(k))
return SysRootKitInformation::sysRoot(runConfig->target()->kit()).toString();
return QString();
}
AnalyzerRunControl *QmlProfilerTool::createRunControl(RunConfiguration *runConfiguration)
{
QmlProfilerRunConfigurationAspect *aspect = static_cast<QmlProfilerRunConfigurationAspect *>(
runConfiguration->extraAspect(Constants::SETTINGS));
QTC_ASSERT(aspect, return 0);
QmlProfilerSettings *settings = static_cast<QmlProfilerSettings *>(aspect->currentSettings());
QTC_ASSERT(settings, return 0);
d->m_profilerConnections->setFlushInterval(settings->flushEnabled() ?
settings->flushInterval() : 0);
d->m_profilerConnections->setAggregateTraces(settings->aggregateTraces());
return new QmlProfilerRunControl(runConfiguration, this);
}
void QmlProfilerTool::finalizeRunControl(QmlProfilerRunControl *runControl)
{
runControl->registerProfilerStateManager(d->m_profilerState);
// FIXME: Check that there's something sensible in sp.connParams
auto connection = runControl->connection().as<AnalyzerConnection>();
if (!connection.analyzerSocket.isEmpty())
d->m_profilerConnections->setLocalSocket(connection.analyzerSocket);
else
d->m_profilerConnections->setTcpConnection(connection.analyzerHost, connection.analyzerPort);
//
// Initialize m_projectFinder
//
RunConfiguration *runConfiguration = runControl->runConfiguration();
QString projectDirectory;
if (runConfiguration) {
Project *project = runConfiguration->target()->project();
projectDirectory = project->projectDirectory().toString();
}
populateFileFinder(projectDirectory, sysroot(runConfiguration));
if (connection.analyzerSocket.isEmpty())
connect(runControl, &QmlProfilerRunControl::processRunning,
d->m_profilerConnections, &QmlProfilerClientManager::connectTcpClient);
connect(d->m_profilerConnections, &QmlProfilerClientManager::connectionFailed,
runControl, &QmlProfilerRunControl::cancelProcess);
} }
void QmlProfilerTool::populateFileFinder(QString projectDirectory, QString activeSysroot) void QmlProfilerTool::populateFileFinder(QString projectDirectory, QString activeSysroot)

View File

@@ -54,7 +54,6 @@ public:
Analyzer::AnalyzerRunControl *createRunControl(ProjectExplorer::RunConfiguration *runConfiguration = 0); Analyzer::AnalyzerRunControl *createRunControl(ProjectExplorer::RunConfiguration *runConfiguration = 0);
void finalizeRunControl(QmlProfilerRunControl *runControl); void finalizeRunControl(QmlProfilerRunControl *runControl);
QWidget *createWidgets();
bool prepareTool(); bool prepareTool();
void startRemoteTool(ProjectExplorer::RunConfiguration *rc); void startRemoteTool(ProjectExplorer::RunConfiguration *rc);