aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2018-01-09 14:50:12 +0100
committerUlf Hermann <ulf.hermann@qt.io>2018-01-11 14:04:13 +0000
commite1ad7a1784501f034de48e26796100eeb5240429 (patch)
tree131e3d6ad61e6902312029b9aebfd4a1cc465571
parent7d039de7a8da94c59ada808ecc7fd8f86cea3437 (diff)
QmlProfiler: Drop static accessors from QmlProfilerTool
It wasn't really a singleton even before. For testing purposes make the client/state/model managers accessible. Change-Id: Ie5efbc47a6b9119495f999e4e05877d4789da407 Reviewed-by: hjk <hjk@qt.io>
-rw-r--r--src/plugins/qmlprofiler/qmlprofilerplugin.cpp15
-rw-r--r--src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp54
-rw-r--r--src/plugins/qmlprofiler/qmlprofilerruncontrol.h10
-rw-r--r--src/plugins/qmlprofiler/qmlprofilertool.cpp57
-rw-r--r--src/plugins/qmlprofiler/qmlprofilertool.h10
-rw-r--r--src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp8
-rw-r--r--src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp4
7 files changed, 90 insertions, 68 deletions
diff --git a/src/plugins/qmlprofiler/qmlprofilerplugin.cpp b/src/plugins/qmlprofiler/qmlprofilerplugin.cpp
index 794dad95be..3f738a3fc5 100644
--- a/src/plugins/qmlprofiler/qmlprofilerplugin.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilerplugin.cpp
@@ -106,10 +106,17 @@ void QmlProfilerPlugin::extensionsInitialized()
};
RunControl::registerWorkerCreator(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE,
- [](RunControl *runControl) { return new QmlProfilerRunner(runControl); });
-
- RunControl::registerWorker<LocalQmlProfilerSupport>
- (ProjectExplorer::Constants::QML_PROFILER_RUN_MODE, constraint);
+ [this](RunControl *runControl) {
+ QmlProfilerRunner *runner = new QmlProfilerRunner(runControl);
+ connect(runner, &QmlProfilerRunner::starting,
+ m_profilerTool, &QmlProfilerTool::finalizeRunControl);
+ return runner;
+ });
+
+ RunControl::registerWorker(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE,
+ [this](ProjectExplorer::RunControl *runControl) {
+ return new LocalQmlProfilerSupport(m_profilerTool, runControl);
+ }, constraint);
}
ExtensionSystem::IPlugin::ShutdownFlag QmlProfilerPlugin::aboutToShutdown()
diff --git a/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp b/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp
index 46d7bfa756..ff828ae11e 100644
--- a/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp
@@ -28,8 +28,6 @@
#include "qmlprofilerclientmanager.h"
#include "qmlprofilertool.h"
-#include <app/app_version.h>
-
#include <coreplugin/icore.h>
#include <coreplugin/helpmanager.h>
@@ -57,6 +55,7 @@ using namespace ProjectExplorer;
using namespace QmlProfiler::Internal;
namespace QmlProfiler {
+namespace Internal {
static QString QmlServerUrl = "QmlServerUrl";
@@ -92,46 +91,8 @@ QmlProfilerRunner::~QmlProfilerRunner()
void QmlProfilerRunner::start()
{
- Internal::QmlProfilerTool::instance()->finalizeRunControl(this);
+ emit starting(this);
QTC_ASSERT(d->m_profilerState, return);
-
- QUrl serverUrl = this->serverUrl();
-
- QmlProfilerClientManager *clientManager = Internal::QmlProfilerTool::clientManager();
-
- connect(clientManager, &QmlProfilerClientManager::connectionFailed,
- this, [this, clientManager] {
- QMessageBox *infoBox = new QMessageBox(ICore::mainWindow());
- infoBox->setIcon(QMessageBox::Critical);
- infoBox->setWindowTitle(Core::Constants::IDE_DISPLAY_NAME);
- infoBox->setText(QmlProfilerTool::tr("Could not connect to the in-process QML profiler.\n"
- "Do you want to retry?"));
- infoBox->setStandardButtons(QMessageBox::Retry | QMessageBox::Cancel | QMessageBox::Help);
- infoBox->setDefaultButton(QMessageBox::Retry);
- infoBox->setModal(true);
-
- connect(infoBox, &QDialog::finished, this, [clientManager, this](int result) {
- switch (result) {
- case QMessageBox::Retry:
- clientManager->retryConnect();
- break;
- case QMessageBox::Help:
- HelpManager::handleHelpRequest(
- "qthelp://org.qt-project.qtcreator/doc/creator-debugging-qml.html");
- Q_FALLTHROUGH();
- case QMessageBox::Cancel:
- // The actual error message has already been logged.
- QmlProfilerTool::logState(QmlProfilerTool::tr("Failed to connect."));
- cancelProcess();
- break;
- }
- });
-
- infoBox->show();
- }, Qt::QueuedConnection); // Queue any connection failures after reportStarted()
-
- clientManager->connectToServer(serverUrl);
- d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppRunning);
reportStarted();
}
@@ -261,18 +222,22 @@ static QUrl localServerUrl(RunControl *runControl)
return serverUrl;
}
-LocalQmlProfilerSupport::LocalQmlProfilerSupport(RunControl *runControl)
- : LocalQmlProfilerSupport(runControl, localServerUrl(runControl))
+LocalQmlProfilerSupport::LocalQmlProfilerSupport(QmlProfilerTool *profilerTool,
+ RunControl *runControl)
+ : LocalQmlProfilerSupport(profilerTool, runControl, localServerUrl(runControl))
{
}
-LocalQmlProfilerSupport::LocalQmlProfilerSupport(RunControl *runControl, const QUrl &serverUrl)
+LocalQmlProfilerSupport::LocalQmlProfilerSupport(QmlProfilerTool *profilerTool,
+ RunControl *runControl, const QUrl &serverUrl)
: SimpleTargetRunner(runControl)
{
setDisplayName("LocalQmlProfilerSupport");
m_profiler = new QmlProfilerRunner(runControl);
m_profiler->setServerUrl(serverUrl);
+ connect(m_profiler, &QmlProfilerRunner::starting,
+ profilerTool, &QmlProfilerTool::finalizeRunControl);
addStopDependency(m_profiler);
// We need to open the local server before the application tries to connect.
@@ -301,4 +266,5 @@ LocalQmlProfilerSupport::LocalQmlProfilerSupport(RunControl *runControl, const Q
setRunnable(debuggee);
}
+} // namespace Internal
} // namespace QmlProfiler
diff --git a/src/plugins/qmlprofiler/qmlprofilerruncontrol.h b/src/plugins/qmlprofiler/qmlprofilerruncontrol.h
index de423c7e77..1236961049 100644
--- a/src/plugins/qmlprofiler/qmlprofilerruncontrol.h
+++ b/src/plugins/qmlprofiler/qmlprofilerruncontrol.h
@@ -36,7 +36,9 @@
#include <qmldebug/qmloutputparser.h>
namespace QmlProfiler {
+namespace Internal {
+class QmlProfilerTool;
class QmlProfilerRunner : public ProjectExplorer::RunWorker
{
Q_OBJECT
@@ -53,6 +55,9 @@ public:
void cancelProcess();
void notifyRemoteFinished();
+signals:
+ void starting(QmlProfilerRunner *self);
+
private:
void start() override;
void stop() override;
@@ -68,12 +73,13 @@ class LocalQmlProfilerSupport : public ProjectExplorer::SimpleTargetRunner
Q_OBJECT
public:
- LocalQmlProfilerSupport(ProjectExplorer::RunControl *runControl);
- LocalQmlProfilerSupport(ProjectExplorer::RunControl *runControl,
+ LocalQmlProfilerSupport(QmlProfilerTool *profilerTool, ProjectExplorer::RunControl *runControl);
+ LocalQmlProfilerSupport(QmlProfilerTool *profilerTool, ProjectExplorer::RunControl *runControl,
const QUrl &serverUrl);
private:
QmlProfilerRunner *m_profiler;
};
+} // namespace Internal
} // namespace QmlProfiler
diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp
index cb2bcb59a8..9cfc21d6a7 100644
--- a/src/plugins/qmlprofiler/qmlprofilertool.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp
@@ -38,6 +38,8 @@
#include "qmlprofilerplugin.h"
#include "qmlprofilertextmark.h"
+#include <app/app_version.h>
+
#include <debugger/debuggericons.h>
#include <debugger/analyzer/analyzermanager.h>
@@ -129,12 +131,9 @@ public:
bool m_toolBusy = false;
};
-static QmlProfilerTool *s_instance;
-
QmlProfilerTool::QmlProfilerTool(QObject *parent)
: QObject(parent), d(new QmlProfilerToolPrivate)
{
- s_instance = this;
setObjectName(QLatin1String("QmlProfilerTool"));
d->m_profilerState = new QmlProfilerStateManager(this);
@@ -341,11 +340,6 @@ QmlProfilerTool::~QmlProfilerTool()
delete d;
}
-QmlProfilerTool *QmlProfilerTool::instance()
-{
- return s_instance;
-}
-
void QmlProfilerTool::updateRunActions()
{
if (d->m_toolBusy) {
@@ -396,6 +390,40 @@ void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker)
d->m_profilerModelManager->populateFileFinder(runConfiguration ? runConfiguration->target()
: nullptr);
+
+ connect(d->m_profilerConnections, &QmlProfilerClientManager::connectionFailed,
+ runWorker, [this, runWorker]() {
+ QMessageBox *infoBox = new QMessageBox(ICore::mainWindow());
+ infoBox->setIcon(QMessageBox::Critical);
+ infoBox->setWindowTitle(Core::Constants::IDE_DISPLAY_NAME);
+ infoBox->setText(QmlProfilerTool::tr("Could not connect to the in-process QML profiler.\n"
+ "Do you want to retry?"));
+ infoBox->setStandardButtons(QMessageBox::Retry | QMessageBox::Cancel | QMessageBox::Help);
+ infoBox->setDefaultButton(QMessageBox::Retry);
+ infoBox->setModal(true);
+
+ connect(infoBox, &QDialog::finished, runWorker, [this, runWorker](int result) {
+ switch (result) {
+ case QMessageBox::Retry:
+ d->m_profilerConnections->retryConnect();
+ break;
+ case QMessageBox::Help:
+ HelpManager::handleHelpRequest(
+ "qthelp://org.qt-project.qtcreator/doc/creator-debugging-qml.html");
+ Q_FALLTHROUGH();
+ case QMessageBox::Cancel:
+ // The actual error message has already been logged.
+ QmlProfilerTool::logState(QmlProfilerTool::tr("Failed to connect."));
+ runWorker->cancelProcess();
+ break;
+ }
+ });
+
+ infoBox->show();
+ }, Qt::QueuedConnection); // Queue any connection failures after reportStarted()
+
+ d->m_profilerConnections->connectToServer(runWorker->serverUrl());
+ d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppRunning);
}
void QmlProfilerTool::recordingButtonChanged(bool recording)
@@ -573,6 +601,7 @@ ProjectExplorer::RunControl *QmlProfilerTool::attachToWaitingApplication()
auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
auto profiler = new QmlProfilerRunner(runControl);
profiler->setServerUrl(serverUrl);
+ connect(profiler, &QmlProfilerRunner::starting, this, &QmlProfilerTool::finalizeRunControl);
connect(d->m_profilerConnections, &QmlProfilerClientManager::connectionClosed,
runControl, &RunControl::initiateStop);
@@ -819,7 +848,17 @@ void QmlProfilerTool::showNonmodalWarning(const QString &warningMsg)
QmlProfilerClientManager *QmlProfilerTool::clientManager()
{
- return s_instance->d->m_profilerConnections;
+ return d->m_profilerConnections;
+}
+
+QmlProfilerModelManager *QmlProfilerTool::modelManager()
+{
+ return d->m_profilerModelManager;
+}
+
+QmlProfilerStateManager *QmlProfilerTool::stateManager()
+{
+ return d->m_profilerState;
}
void QmlProfilerTool::profilerStateChanged()
diff --git a/src/plugins/qmlprofiler/qmlprofilertool.h b/src/plugins/qmlprofiler/qmlprofilertool.h
index 0c21087400..3211e1a8bf 100644
--- a/src/plugins/qmlprofiler/qmlprofilertool.h
+++ b/src/plugins/qmlprofiler/qmlprofilertool.h
@@ -40,10 +40,12 @@ class RunControl;
namespace QmlProfiler {
-class QmlProfilerRunner;
+class QmlProfilerModelManager;
+class QmlProfilerStateManager;
namespace Internal {
+class QmlProfilerRunner;
class QmlProfilerClientManager;
class QMLPROFILER_EXPORT QmlProfilerTool : public QObject
@@ -54,8 +56,6 @@ public:
explicit QmlProfilerTool(QObject *parent);
~QmlProfilerTool();
- static QmlProfilerTool *instance();
-
void finalizeRunControl(QmlProfilerRunner *runWorker);
bool prepareTool();
@@ -68,7 +68,9 @@ public:
static void logError(const QString &msg);
static void showNonmodalWarning(const QString &warningMsg);
- static QmlProfilerClientManager *clientManager();
+ QmlProfilerClientManager *clientManager();
+ QmlProfilerModelManager *modelManager();
+ QmlProfilerStateManager *stateManager();
void profilerStateChanged();
void serverRecordingChanged();
diff --git a/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp b/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp
index f212234932..007dac486a 100644
--- a/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp
+++ b/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp
@@ -28,6 +28,7 @@
#include <debugger/analyzer/analyzermanager.h>
#include <projectexplorer/runnables.h>
#include <qmlprofiler/qmlprofilerruncontrol.h>
+#include <qmlprofiler/qmlprofilertool.h>
#include <utils/url.h>
@@ -43,6 +44,7 @@ LocalQmlProfilerRunnerTest::LocalQmlProfilerRunnerTest(QObject *parent) : QObjec
void LocalQmlProfilerRunnerTest::testRunner()
{
+ QmlProfilerTool tool(nullptr);
QPointer<ProjectExplorer::RunControl> runControl;
QPointer<LocalQmlProfilerSupport> profiler;
ProjectExplorer::StandardRunnable debuggee;
@@ -64,7 +66,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
runControl = new ProjectExplorer::RunControl(nullptr,
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setRunnable(debuggee);
- profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
+ profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
auto connectRunner = [&]() {
connect(runControl, &ProjectExplorer::RunControl::aboutToStart, this, [&]() {
@@ -112,7 +114,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
runControl = new ProjectExplorer::RunControl(nullptr,
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setRunnable(debuggee);
- profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
+ profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
connectRunner();
runControl->initiateStart();
@@ -132,7 +134,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
runControl = new ProjectExplorer::RunControl(nullptr,
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setRunnable(debuggee);
- profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
+ profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
connectRunner();
runControl->initiateStart();
diff --git a/src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp b/src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp
index 2d5fd1cdaa..f596169cf1 100644
--- a/src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp
+++ b/src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp
@@ -39,7 +39,7 @@ namespace Internal {
void QmlProfilerToolTest::testAttachToWaitingApplication()
{
- QmlProfilerTool *profilerTool = QmlProfilerTool::instance();
+ QmlProfilerTool profilerTool(nullptr);
QTcpServer server;
QUrl serverUrl = Utils::urlFromLocalHostAndFreePort();
QVERIFY(serverUrl.port() >= 0);
@@ -63,7 +63,7 @@ void QmlProfilerToolTest::testAttachToWaitingApplication()
});
timer.start();
- ProjectExplorer::RunControl *runControl = profilerTool->attachToWaitingApplication();
+ ProjectExplorer::RunControl *runControl = profilerTool.attachToWaitingApplication();
QVERIFY(runControl);
QTRY_VERIFY(connection);