From da475f400dcf1cf309d0d1622f57b76a136db281 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 3 Jan 2025 15:33:53 +0100 Subject: [PATCH] QmlProfiler: Simplify QmlProfilerRunner Remove registerProfilerStateManager() and connect to state manager's signal directly from the start() function. Remove Q_OBJECT macro. Change-Id: Id03486f077c81909fbe0889bb342ee7595631e9d Reviewed-by: Ulf Hermann Reviewed-by: hjk --- .../qmlprofiler/qmlprofilerruncontrol.cpp | 41 +++++-------------- .../qmlprofiler/qmlprofilerruncontrol.h | 7 ---- src/plugins/qmlprofiler/qmlprofilertool.cpp | 5 +-- 3 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp b/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp index e745af59d7d..5b12e2e2f5d 100644 --- a/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerruncontrol.cpp @@ -3,6 +3,7 @@ #include "qmlprofilerruncontrol.h" +#include "qmlprofilerstatemanager.h" #include "qmlprofilertool.h" #include @@ -23,8 +24,6 @@ #include #include -#include - using namespace Core; using namespace ProjectExplorer; @@ -61,9 +60,17 @@ QmlProfilerRunner::~QmlProfilerRunner() void QmlProfilerRunner::start() { - if (!d->m_profilerState) - QmlProfilerTool::instance()->finalizeRunControl(this); + if (d->m_profilerState) + disconnect(d->m_profilerState, &QmlProfilerStateManager::stateChanged, this, nullptr); + + QmlProfilerTool::instance()->finalizeRunControl(this); + d->m_profilerState = QmlProfilerTool::instance()->stateManager(); QTC_ASSERT(d->m_profilerState, return); + + connect(d->m_profilerState, &QmlProfilerStateManager::stateChanged, this, [this] { + if (d->m_profilerState->currentState() == QmlProfilerStateManager::Idle) + reportStopped(); + }); reportStarted(); } @@ -116,32 +123,6 @@ void QmlProfilerRunner::cancelProcess() runControl()->initiateStop(); } -void QmlProfilerRunner::registerProfilerStateManager( QmlProfilerStateManager *profilerState ) -{ - // disconnect old - if (d->m_profilerState) - disconnect(d->m_profilerState, &QmlProfilerStateManager::stateChanged, - this, &QmlProfilerRunner::profilerStateChanged); - - d->m_profilerState = profilerState; - - // connect - if (d->m_profilerState) - connect(d->m_profilerState, &QmlProfilerStateManager::stateChanged, - this, &QmlProfilerRunner::profilerStateChanged); -} - -void QmlProfilerRunner::profilerStateChanged() -{ - switch (d->m_profilerState->currentState()) { - case QmlProfilerStateManager::Idle: - reportStopped(); - break; - default: - break; - } -} - RunWorker *createLocalQmlProfilerWorker(RunControl *runControl) { auto worker = new ProcessRunner(runControl); diff --git a/src/plugins/qmlprofiler/qmlprofilerruncontrol.h b/src/plugins/qmlprofiler/qmlprofilerruncontrol.h index dcc374c9892..f2a4ea1656f 100644 --- a/src/plugins/qmlprofiler/qmlprofilerruncontrol.h +++ b/src/plugins/qmlprofiler/qmlprofilerruncontrol.h @@ -3,8 +3,6 @@ #pragma once -#include "qmlprofilerstatemanager.h" - #include #include @@ -18,21 +16,16 @@ namespace Internal { class QmlProfilerRunner : public ProjectExplorer::RunWorker { - Q_OBJECT - public: QmlProfilerRunner(ProjectExplorer::RunControl *runControl); ~QmlProfilerRunner() override; - void registerProfilerStateManager( QmlProfilerStateManager *profilerState ); void cancelProcess(); private: void start() override; void stop() override; - void profilerStateChanged(); - class QmlProfilerRunnerPrivate; QmlProfilerRunnerPrivate *d; }; diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index efc3fcd0641..810d373887f 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -178,7 +178,7 @@ QmlProfilerTool::QmlProfilerTool() d->m_clearButton->setIcon(Utils::Icons::CLEAN_TOOLBAR.icon()); d->m_clearButton->setToolTip(Tr::tr("Discard data")); - connect(d->m_clearButton, &QAbstractButton::clicked, [this](){ + connect(d->m_clearButton, &QAbstractButton::clicked, [this] { if (checkForUnsavedNotes()) clearData(); }); @@ -382,7 +382,6 @@ void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker) connect(d->m_stopAction, &QAction::triggered, runControl, &RunControl::initiateStop); updateRunActions(); - runWorker->registerProfilerStateManager(d->m_profilerState); // // Initialize m_projectFinder @@ -391,7 +390,7 @@ void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker) d->m_profilerModelManager->populateFileFinder(runControl->target()); connect(d->m_profilerConnections, &QmlProfilerClientManager::connectionFailed, - runWorker, [this, runWorker]() { + runWorker, [this, runWorker] { auto infoBox = new QMessageBox(ICore::dialogParent()); infoBox->setIcon(QMessageBox::Critical); infoBox->setWindowTitle(QGuiApplication::applicationDisplayName());