QtcProcess: Make the class final

Currently, as a result of many refactorings, the QtcProcess
is designed so that if you want to customize the behavior
you should implement custom ProcessInterface subclass.
Adding virtual methods directly to QtcProcess caused tons of
unpredicted side effects and nasty bugs, which were hard to
track and hard to fix, as provided fixes were usually fixing
particular case while introducing regressions in not related
code paths.

Consider also aggregating QtcProcess object instead of
deriving from it when some additional methods are required.

This patch removes the last virtual methods from QtcProcess API
and makes the class final in order to prevent from adding
any new virtual methods to this class in the future.

This commit message should make it clear that having subclasses
of QtcProcess is not a desired design. It's a post-mortem
conclusion. So: don't derive from QtcProcess - we mean it!

Change-Id: I1e43ed45be326b366422fd7db6e05ba48ea5fb98
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-05-06 11:59:17 +02:00
parent 2856091c75
commit 6455d7fcf3
4 changed files with 21 additions and 63 deletions

View File

@@ -989,16 +989,6 @@ QtcProcess::~QtcProcess()
delete d;
}
void QtcProcess::emitStarted()
{
emit started();
}
void QtcProcess::emitFinished()
{
emit finished();
}
void QtcProcess::setProcessImpl(ProcessImpl processImpl)
{
d->m_setup.m_processImpl = processImpl;
@@ -1099,19 +1089,14 @@ void QtcProcess::start()
QTC_ASSERT(state() == QProcess::NotRunning, return);
d->clearForRun();
d->m_state = QProcess::Starting;
startImpl();
}
void QtcProcess::startImpl()
{
ProcessInterface *processImpl = nullptr;
if (d->m_setup.m_commandLine.executable().needsDevice()) {
QTC_ASSERT(s_deviceHooks.processImplHook, return);
QTC_ASSERT(s_deviceHooks.processImplHook, d->m_state = QProcess::NotRunning; return);
processImpl = s_deviceHooks.processImplHook(commandLine().executable());
} else {
processImpl = d->createProcessInterface();
}
QTC_ASSERT(processImpl, return);
QTC_ASSERT(processImpl, d->m_state = QProcess::NotRunning; return);
d->setProcessInterface(processImpl);
d->m_process->m_setup = d->m_setup;
d->m_process->m_setup.m_commandLine = d->fullCommandLine();
@@ -2001,13 +1986,13 @@ void QtcProcessPrivate::handleError()
void QtcProcessPrivate::emitStarted()
{
CALL_STACK_GUARD();
q->emitStarted();
emit q->started();
}
void QtcProcessPrivate::emitFinished()
{
CALL_STACK_GUARD();
q->emitFinished();
emit q->finished();
}
void QtcProcessPrivate::emitErrorOccurred(QProcess::ProcessError error)