diff --git a/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp b/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp index c7cae10404a..189ec286374 100644 --- a/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp @@ -3,8 +3,10 @@ #include "qmlprofilerruncontrol.h" +#include "qmlprofilerclientmanager.h" #include "qmlprofilerstatemanager.h" #include "qmlprofilertool.h" +#include "qmlprofilertr.h" #include #include @@ -24,6 +26,8 @@ #include #include +#include + using namespace Core; using namespace ProjectExplorer; @@ -63,7 +67,7 @@ void QmlProfilerRunner::start() if (d->m_profilerState) disconnect(d->m_profilerState, &QmlProfilerStateManager::stateChanged, this, nullptr); - QmlProfilerTool::instance()->finalizeRunControl(this); + QmlProfilerTool::instance()->finalizeRunControl(runControl()); connect(this, &QmlProfilerRunner::stopped, QmlProfilerTool::instance(), &QmlProfilerTool::handleStop); d->m_profilerState = QmlProfilerTool::instance()->stateManager(); @@ -73,6 +77,66 @@ void QmlProfilerRunner::start() if (d->m_profilerState->currentState() == QmlProfilerStateManager::Idle) reportStopped(); }); + + QmlProfilerClientManager *clientManager = QmlProfilerTool::instance()->clientManager(); + connect(clientManager, &QmlProfilerClientManager::connectionFailed, this, [this, clientManager] { + auto infoBox = new QMessageBox(ICore::dialogParent()); + infoBox->setIcon(QMessageBox::Critical); + infoBox->setWindowTitle(QGuiApplication::applicationDisplayName()); + + const int interval = clientManager->retryInterval(); + const int retries = clientManager->maximumRetries(); + + infoBox->setText(Tr::tr("Could not connect to the in-process QML profiler " + "within %1 s.\n" + "Do you want to retry and wait %2 s?") + .arg(interval * retries / 1000.0) + .arg(interval * 2 * retries / 1000.0)); + infoBox->setStandardButtons(QMessageBox::Retry | QMessageBox::Cancel | QMessageBox::Help); + infoBox->setDefaultButton(QMessageBox::Retry); + infoBox->setModal(true); + + connect(infoBox, &QDialog::finished, this, [this, clientManager, interval](int result) { + const auto cancelProcess = [this] { + QTC_ASSERT(d->m_profilerState, return); + + switch (d->m_profilerState->currentState()) { + case QmlProfilerStateManager::Idle: + break; + case QmlProfilerStateManager::AppRunning: + d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppDying); + break; + default: { + const QString message = QString::fromLatin1("Unexpected process termination requested with state %1 in %2:%3") + .arg(d->m_profilerState->currentStateAsString(), QString::fromLatin1(__FILE__), QString::number(__LINE__)); + qWarning("%s", qPrintable(message)); + return; + } + } + runControl()->initiateStop(); + }; + + switch (result) { + case QMessageBox::Retry: + clientManager->setRetryInterval(interval * 2); + clientManager->retryConnect(); + break; + case QMessageBox::Help: + HelpManager::showHelpUrl( + "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(Tr::tr("Failed to connect.")); + cancelProcess(); + break; + } + }); + + infoBox->show(); + }, Qt::QueuedConnection); // Queue any connection failures after reportStarted() + clientManager->connectToServer(runControl()->qmlChannel()); + reportStarted(); } @@ -105,26 +169,6 @@ void QmlProfilerRunner::stop() } } -void QmlProfilerRunner::cancelProcess() -{ - QTC_ASSERT(d->m_profilerState, return); - - switch (d->m_profilerState->currentState()) { - case QmlProfilerStateManager::Idle: - break; - case QmlProfilerStateManager::AppRunning: - d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppDying); - break; - default: { - const QString message = QString::fromLatin1("Unexpected process termination requested with state %1 in %2:%3") - .arg(d->m_profilerState->currentStateAsString(), QString::fromLatin1(__FILE__), QString::number(__LINE__)); - qWarning("%s", qPrintable(message)); - return; - } - } - runControl()->initiateStop(); -} - RunWorker *createLocalQmlProfilerWorker(RunControl *runControl) { auto worker = new ProcessRunner(runControl); diff --git a/src/plugins/qmlprofiler/qmlprofilerruncontrol.h b/src/plugins/qmlprofiler/qmlprofilerruncontrol.h index f2a4ea1656f..03e738e9b8a 100644 --- a/src/plugins/qmlprofiler/qmlprofilerruncontrol.h +++ b/src/plugins/qmlprofiler/qmlprofilerruncontrol.h @@ -20,8 +20,6 @@ public: QmlProfilerRunner(ProjectExplorer::RunControl *runControl); ~QmlProfilerRunner() override; - void cancelProcess(); - private: void start() override; void stop() override; diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index 1588106480c..86942cad882 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -350,10 +350,9 @@ void QmlProfilerTool::updateRunActions() } } -void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker) +void QmlProfilerTool::finalizeRunControl(RunControl *runControl) { d->m_toolBusy = true; - auto runControl = runWorker->runControl(); if (auto aspect = runControl->aspectData()) { if (auto settings = static_cast(aspect->currentSettings)) { d->m_profilerConnections->setFlushInterval(settings->flushEnabled() ? @@ -366,52 +365,7 @@ void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker) updateRunActions(); - // - // Initialize m_projectFinder - // - d->m_profilerModelManager->populateFileFinder(runControl->target()); - - connect(d->m_profilerConnections, &QmlProfilerClientManager::connectionFailed, - runWorker, [this, runWorker] { - auto infoBox = new QMessageBox(ICore::dialogParent()); - infoBox->setIcon(QMessageBox::Critical); - infoBox->setWindowTitle(QGuiApplication::applicationDisplayName()); - - const int interval = d->m_profilerConnections->retryInterval(); - const int retries = d->m_profilerConnections->maximumRetries(); - - infoBox->setText(Tr::tr("Could not connect to the in-process QML profiler " - "within %1 s.\n" - "Do you want to retry and wait %2 s?") - .arg(interval * retries / 1000.0) - .arg(interval * 2 * retries / 1000.0)); - infoBox->setStandardButtons(QMessageBox::Retry | QMessageBox::Cancel | QMessageBox::Help); - infoBox->setDefaultButton(QMessageBox::Retry); - infoBox->setModal(true); - - connect(infoBox, &QDialog::finished, runWorker, [this, runWorker, interval](int result) { - switch (result) { - case QMessageBox::Retry: - d->m_profilerConnections->setRetryInterval(interval * 2); - d->m_profilerConnections->retryConnect(); - break; - case QMessageBox::Help: - HelpManager::showHelpUrl( - "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(Tr::tr("Failed to connect.")); - runWorker->cancelProcess(); - break; - } - }); - - infoBox->show(); - }, Qt::QueuedConnection); // Queue any connection failures after reportStarted() - - d->m_profilerConnections->connectToServer(runControl->qmlChannel()); d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppRunning); } diff --git a/src/plugins/qmlprofiler/qmlprofilertool.h b/src/plugins/qmlprofiler/qmlprofilertool.h index 7477937d3f7..66fb34fcdd8 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.h +++ b/src/plugins/qmlprofiler/qmlprofilertool.h @@ -17,7 +17,6 @@ class QmlProfilerStateManager; namespace Internal { -class QmlProfilerRunner; class QmlProfilerClientManager; class QMLPROFILER_EXPORT QmlProfilerTool : public QObject @@ -30,7 +29,7 @@ public: static QmlProfilerTool *instance(); - void finalizeRunControl(QmlProfilerRunner *runWorker); + void finalizeRunControl(ProjectExplorer::RunControl *runControl); void handleStop(); bool prepareTool();