forked from qt-creator/qt-creator
RunControl: Remove initiateFinish() / finished()
The only difference between initiateFinish() and initiateStop() is that the initiateFinish() deletes the RunControl automatically after the final state was reached. Add setAutoDeleteOnStop() property and reuse initiateStop() and stopped() instead. Change-Id: I8e842978831b19587a8658b4443c96a04eb7a6df Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -589,7 +589,6 @@ void TestRunner::debugTests()
|
||||
runControl, &RunControl::initiateStop);
|
||||
|
||||
connect(runControl, &RunControl::stopped, this, &TestRunner::onFinished);
|
||||
m_finishDebugConnect = connect(runControl, &RunControl::finished, this, &TestRunner::onFinished);
|
||||
ProjectExplorerPlugin::startRunControl(runControl);
|
||||
if (useOutputProcessor && TestSettings::instance()->popupOnStart())
|
||||
AutotestPlugin::popupResultsPane();
|
||||
@@ -705,7 +704,6 @@ void TestRunner::onFinished()
|
||||
if (m_taskTree)
|
||||
m_taskTree.release()->deleteLater();
|
||||
disconnect(m_stopDebugConnect);
|
||||
disconnect(m_finishDebugConnect);
|
||||
disconnect(m_targetConnect);
|
||||
qDeleteAll(m_selectedTests);
|
||||
m_selectedTests.clear();
|
||||
|
@@ -79,7 +79,6 @@ private:
|
||||
QMetaObject::Connection m_buildConnect;
|
||||
// temporarily used when debugging
|
||||
QMetaObject::Connection m_stopDebugConnect;
|
||||
QMetaObject::Connection m_finishDebugConnect;
|
||||
// temporarily used for handling of switching the current target
|
||||
QMetaObject::Connection m_targetConnect;
|
||||
QTimer m_cancelTimer;
|
||||
|
@@ -545,10 +545,12 @@ void DebuggerRunTool::start()
|
||||
m_engine->setRunId(d->runId);
|
||||
m_engine->setRunTool(this);
|
||||
m_engine->setCompanionEngine(m_engine2);
|
||||
connect(m_engine, &DebuggerEngine::requestRunControlFinish,
|
||||
runControl(), &RunControl::initiateFinish);
|
||||
connect(m_engine, &DebuggerEngine::requestRunControlStop,
|
||||
runControl(), &RunControl::initiateStop);
|
||||
auto rc = runControl();
|
||||
connect(m_engine, &DebuggerEngine::requestRunControlFinish, rc, [rc] {
|
||||
rc->setAutoDeleteOnStop(true);
|
||||
rc->initiateStop();
|
||||
}, Qt::QueuedConnection);
|
||||
connect(m_engine, &DebuggerEngine::requestRunControlStop, rc, &RunControl::initiateStop);
|
||||
connect(m_engine, &DebuggerEngine::engineStarted,
|
||||
this, [this] { handleEngineStarted(m_engine); });
|
||||
connect(m_engine, &DebuggerEngine::engineFinished,
|
||||
@@ -575,10 +577,11 @@ void DebuggerRunTool::start()
|
||||
m_engine2->setRunTool(this);
|
||||
m_engine2->setCompanionEngine(m_engine);
|
||||
m_engine2->setSecondaryEngine();
|
||||
connect(m_engine2, &DebuggerEngine::requestRunControlFinish,
|
||||
runControl(), &RunControl::initiateFinish);
|
||||
connect(m_engine2, &DebuggerEngine::requestRunControlStop,
|
||||
runControl(), &RunControl::initiateStop);
|
||||
connect(m_engine2, &DebuggerEngine::requestRunControlFinish, rc, [rc] {
|
||||
rc->setAutoDeleteOnStop(true);
|
||||
rc->initiateStop();
|
||||
}, Qt::QueuedConnection);
|
||||
connect(m_engine2, &DebuggerEngine::requestRunControlStop, rc, &RunControl::initiateStop);
|
||||
connect(m_engine2, &DebuggerEngine::engineStarted,
|
||||
this, [this] { handleEngineStarted(m_engine2); });
|
||||
connect(m_engine2, &DebuggerEngine::engineFinished,
|
||||
|
@@ -185,8 +185,6 @@ void PerfProfilerRunner::start()
|
||||
&PerfProfilerTool::onRunControlStarted);
|
||||
connect(runControl(), &RunControl::stopped, PerfProfilerTool::instance(),
|
||||
&PerfProfilerTool::onRunControlFinished);
|
||||
connect(runControl(), &RunControl::finished, PerfProfilerTool::instance(),
|
||||
&PerfProfilerTool::onRunControlFinished);
|
||||
|
||||
PerfDataReader *reader = m_perfParserWorker->reader();
|
||||
if (auto prw = qobject_cast<LocalPerfRecordWorker *>(m_perfRecordWorker)) {
|
||||
|
@@ -406,8 +406,10 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
|
||||
});
|
||||
if (tab != m_runControlTabs.end()) {
|
||||
// Reuse this tab
|
||||
if (tab->runControl)
|
||||
tab->runControl->initiateFinish();
|
||||
if (tab->runControl) {
|
||||
tab->runControl->setAutoDeleteOnStop(true);
|
||||
tab->runControl->initiateStop();
|
||||
}
|
||||
tab->runControl = rc;
|
||||
tab->window->reset();
|
||||
rc->setupFormatter(tab->window->outputFormatter());
|
||||
@@ -642,8 +644,10 @@ void AppOutputPane::closeTab(int tabIndex, CloseTabMode closeTabMode)
|
||||
m_tabWidget->removeTab(tabIndex);
|
||||
delete window;
|
||||
|
||||
if (runControl)
|
||||
runControl->initiateFinish(); // Will self-destruct.
|
||||
if (runControl) {
|
||||
runControl->setAutoDeleteOnStop(true);
|
||||
runControl->initiateStop();
|
||||
}
|
||||
Utils::erase(m_runControlTabs, [tab](const RunControlTab &t) {
|
||||
return t.runControl == tab->runControl; });
|
||||
updateCloseActions();
|
||||
|
@@ -211,9 +211,7 @@ enum class RunControlState
|
||||
Starting, // Actual process/tool starts.
|
||||
Running, // All good and running.
|
||||
Stopping, // initiateStop() was called, stop application/tool
|
||||
Stopped, // all good, but stopped. Can possibly be re-started
|
||||
Finishing, // Application tab manually closed
|
||||
Finished // Final state, will self-destruct with deleteLater()
|
||||
Stopped // all good, but stopped. Can possibly be re-started
|
||||
};
|
||||
|
||||
static QString stateName(RunControlState s)
|
||||
@@ -225,8 +223,6 @@ static QString stateName(RunControlState s)
|
||||
SN(RunControlState::Running)
|
||||
SN(RunControlState::Stopping)
|
||||
SN(RunControlState::Stopped)
|
||||
SN(RunControlState::Finishing)
|
||||
SN(RunControlState::Finished)
|
||||
}
|
||||
return QString("<unknown: %1>").arg(int(s));
|
||||
# undef SN
|
||||
@@ -259,6 +255,7 @@ public:
|
||||
QList<QPointer<RunWorker>> m_workers;
|
||||
RunControlState state = RunControlState::Initialized;
|
||||
bool printEnvironment = false;
|
||||
bool autoDelete = false;
|
||||
};
|
||||
|
||||
class RunControlPrivate : public QObject, public RunControlPrivateData
|
||||
@@ -274,7 +271,7 @@ public:
|
||||
|
||||
~RunControlPrivate() override
|
||||
{
|
||||
QTC_CHECK(state == RunControlState::Finished || state == RunControlState::Initialized);
|
||||
QTC_CHECK(state == RunControlState::Stopped || state == RunControlState::Initialized);
|
||||
disconnect();
|
||||
q = nullptr;
|
||||
qDeleteAll(m_workers);
|
||||
@@ -407,6 +404,11 @@ RunControl::~RunControl()
|
||||
#endif
|
||||
}
|
||||
|
||||
void RunControl::setAutoDeleteOnStop(bool autoDelete)
|
||||
{
|
||||
d->autoDelete = autoDelete;
|
||||
}
|
||||
|
||||
void RunControl::initiateStart()
|
||||
{
|
||||
emit aboutToStart();
|
||||
@@ -429,11 +431,6 @@ void RunControl::forceStop()
|
||||
d->forceStop();
|
||||
}
|
||||
|
||||
void RunControl::initiateFinish()
|
||||
{
|
||||
QTimer::singleShot(0, d.get(), &RunControlPrivate::initiateFinish);
|
||||
}
|
||||
|
||||
RunWorker *RunControl::createWorker(Id workerId)
|
||||
{
|
||||
const Id deviceType = DeviceTypeKitAspect::deviceTypeId(d->kit);
|
||||
@@ -542,7 +539,7 @@ void RunControlPrivate::continueStart()
|
||||
|
||||
void RunControlPrivate::initiateStop()
|
||||
{
|
||||
if (state != RunControlState::Starting && state != RunControlState::Running)
|
||||
if (state == RunControlState::Initialized)
|
||||
qDebug() << "Unexpected initiateStop() in state" << stateName(state);
|
||||
|
||||
setState(RunControlState::Stopping);
|
||||
@@ -596,12 +593,8 @@ void RunControlPrivate::continueStopOrFinish()
|
||||
}
|
||||
|
||||
RunControlState targetState;
|
||||
if (state == RunControlState::Finishing) {
|
||||
targetState = RunControlState::Finished;
|
||||
} else {
|
||||
checkState(RunControlState::Stopping);
|
||||
if (state == RunControlState::Stopping)
|
||||
targetState = RunControlState::Stopped;
|
||||
}
|
||||
|
||||
if (allDone) {
|
||||
debugMessage("All Stopped");
|
||||
@@ -613,7 +606,7 @@ void RunControlPrivate::continueStopOrFinish()
|
||||
|
||||
void RunControlPrivate::forceStop()
|
||||
{
|
||||
if (state == RunControlState::Finished) {
|
||||
if (state == RunControlState::Stopped) {
|
||||
debugMessage("Was finished, too late to force Stop");
|
||||
return;
|
||||
}
|
||||
@@ -648,14 +641,6 @@ void RunControlPrivate::forceStop()
|
||||
debugMessage("All Stopped");
|
||||
}
|
||||
|
||||
void RunControlPrivate::initiateFinish()
|
||||
{
|
||||
setState(RunControlState::Finishing);
|
||||
debugMessage("Ramping down");
|
||||
|
||||
continueStopOrFinish();
|
||||
}
|
||||
|
||||
void RunControlPrivate::onWorkerStarted(RunWorker *worker)
|
||||
{
|
||||
worker->d->state = RunWorkerState::Running;
|
||||
@@ -688,11 +673,9 @@ void RunControlPrivate::onWorkerFailed(RunWorker *worker, const QString &msg)
|
||||
initiateStop();
|
||||
break;
|
||||
case RunControlState::Stopping:
|
||||
case RunControlState::Finishing:
|
||||
continueStopOrFinish();
|
||||
break;
|
||||
case RunControlState::Stopped:
|
||||
case RunControlState::Finished:
|
||||
QTC_CHECK(false); // Should not happen.
|
||||
continueStopOrFinish();
|
||||
break;
|
||||
@@ -723,7 +706,7 @@ void RunControlPrivate::onWorkerStopped(RunWorker *worker)
|
||||
break;
|
||||
}
|
||||
|
||||
if (state == RunControlState::Finishing || state == RunControlState::Stopping) {
|
||||
if (state == RunControlState::Stopping) {
|
||||
continueStopOrFinish();
|
||||
return;
|
||||
} else if (worker->isEssential()) {
|
||||
@@ -1078,26 +1061,15 @@ bool RunControlPrivate::isAllowedTransition(RunControlState from, RunControlStat
|
||||
{
|
||||
switch (from) {
|
||||
case RunControlState::Initialized:
|
||||
return to == RunControlState::Starting
|
||||
|| to == RunControlState::Finishing;
|
||||
return to == RunControlState::Starting;
|
||||
case RunControlState::Starting:
|
||||
return to == RunControlState::Running
|
||||
|| to == RunControlState::Stopping
|
||||
|| to == RunControlState::Finishing;
|
||||
return to == RunControlState::Running || to == RunControlState::Stopping;
|
||||
case RunControlState::Running:
|
||||
return to == RunControlState::Stopping
|
||||
|| to == RunControlState::Stopped
|
||||
|| to == RunControlState::Finishing;
|
||||
return to == RunControlState::Stopping || to == RunControlState::Stopped;
|
||||
case RunControlState::Stopping:
|
||||
return to == RunControlState::Stopped
|
||||
|| to == RunControlState::Finishing;
|
||||
return to == RunControlState::Stopped;
|
||||
case RunControlState::Stopped:
|
||||
return to == RunControlState::Starting
|
||||
|| to == RunControlState::Finishing;
|
||||
case RunControlState::Finishing:
|
||||
return to == RunControlState::Finished;
|
||||
case RunControlState::Finished:
|
||||
return false;
|
||||
return to != RunControlState::Initialized;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1125,14 +1097,14 @@ void RunControlPrivate::setState(RunControlState newState)
|
||||
emit q->started();
|
||||
break;
|
||||
case RunControlState::Stopped:
|
||||
q->setApplicationProcessHandle(Utils::ProcessHandle());
|
||||
if (autoDelete) {
|
||||
debugMessage("All finished. Deleting myself");
|
||||
q->deleteLater();
|
||||
} else {
|
||||
q->setApplicationProcessHandle(Utils::ProcessHandle());
|
||||
}
|
||||
emit q->stopped();
|
||||
break;
|
||||
case RunControlState::Finished:
|
||||
emit q->finished();
|
||||
debugMessage("All finished. Deleting myself");
|
||||
q->deleteLater();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -156,11 +156,12 @@ public:
|
||||
void copyDataFromRunConfiguration(RunConfiguration *runConfig);
|
||||
void copyDataFromRunControl(RunControl *runControl);
|
||||
|
||||
void setAutoDeleteOnStop(bool autoDelete);
|
||||
|
||||
void initiateStart();
|
||||
void initiateReStart();
|
||||
void initiateStop();
|
||||
void forceStop();
|
||||
void initiateFinish();
|
||||
|
||||
bool promptToStop(bool *optionalPrompt = nullptr) const;
|
||||
void setPromptToStop(const std::function<bool(bool *)> &promptToStop);
|
||||
@@ -237,7 +238,6 @@ signals:
|
||||
void aboutToStart();
|
||||
void started();
|
||||
void stopped();
|
||||
void finished();
|
||||
void applicationProcessHandleChanged(QPrivateSignal); // Use setApplicationProcessHandle
|
||||
|
||||
private:
|
||||
|
@@ -297,7 +297,10 @@ void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker)
|
||||
}
|
||||
}
|
||||
|
||||
auto handleStop = [this, runControl]() {
|
||||
auto handleStop = [this, runControl] {
|
||||
if (!d->m_toolBusy)
|
||||
return;
|
||||
|
||||
d->m_toolBusy = false;
|
||||
updateRunActions();
|
||||
disconnect(d->m_stopAction, &QAction::triggered, runControl, &RunControl::initiateStop);
|
||||
@@ -311,11 +314,6 @@ void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker)
|
||||
};
|
||||
|
||||
connect(runControl, &RunControl::stopped, this, handleStop);
|
||||
connect(runControl, &RunControl::finished, this, [this, handleStop] {
|
||||
if (d->m_toolBusy)
|
||||
handleStop();
|
||||
});
|
||||
|
||||
connect(d->m_stopAction, &QAction::triggered, runControl, &RunControl::initiateStop);
|
||||
|
||||
updateRunActions();
|
||||
|
@@ -66,10 +66,6 @@ void LocalQmlProfilerRunnerTest::testRunner()
|
||||
running = false;
|
||||
started = false;
|
||||
});
|
||||
connect(runControl, &RunControl::finished, this, [&]{
|
||||
running = false;
|
||||
started = false;
|
||||
});
|
||||
};
|
||||
|
||||
connectRunner();
|
||||
@@ -84,7 +80,8 @@ void LocalQmlProfilerRunnerTest::testRunner()
|
||||
QCOMPARE(stopCount, 1);
|
||||
QCOMPARE(runCount, 0);
|
||||
|
||||
runControl->initiateFinish();
|
||||
runControl->setAutoDeleteOnStop(true);
|
||||
runControl->initiateStop();
|
||||
QTRY_VERIFY(runControl.isNull());
|
||||
QVERIFY(profiler.isNull());
|
||||
|
||||
@@ -104,7 +101,8 @@ void LocalQmlProfilerRunnerTest::testRunner()
|
||||
QCOMPARE(stopCount, 2);
|
||||
QCOMPARE(runCount, 1);
|
||||
|
||||
runControl->initiateFinish();
|
||||
runControl->setAutoDeleteOnStop(true);
|
||||
runControl->initiateStop();
|
||||
QTRY_VERIFY(runControl.isNull());
|
||||
QVERIFY(profiler.isNull());
|
||||
|
||||
@@ -123,7 +121,8 @@ void LocalQmlProfilerRunnerTest::testRunner()
|
||||
QCOMPARE(stopCount, 3);
|
||||
QCOMPARE(runCount, 2);
|
||||
|
||||
runControl->initiateFinish();
|
||||
runControl->setAutoDeleteOnStop(true);
|
||||
runControl->initiateStop();
|
||||
QTRY_VERIFY(runControl.isNull());
|
||||
QVERIFY(profiler.isNull());
|
||||
|
||||
@@ -146,7 +145,8 @@ void LocalQmlProfilerRunnerTest::testRunner()
|
||||
QCOMPARE(stopCount, 4);
|
||||
QCOMPARE(runCount, 3);
|
||||
|
||||
runControl->initiateFinish();
|
||||
runControl->setAutoDeleteOnStop(true);
|
||||
runControl->initiateStop();
|
||||
QTRY_VERIFY(runControl.isNull());
|
||||
QVERIFY(profiler.isNull());
|
||||
}
|
||||
|
Reference in New Issue
Block a user