ClangToolRunWorker: Avoid using sender()

Change-Id: I299fa6464b77aed3852d3b5a7ce4817678d5f369
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2022-07-21 19:04:33 +02:00
parent 14c5390ffc
commit 3071524607
2 changed files with 23 additions and 21 deletions

View File

@@ -345,9 +345,9 @@ void ClangToolRunWorker::analyzeNextFile()
}
}
void ClangToolRunWorker::onRunnerFinishedWithSuccess(const QString &filePath)
void ClangToolRunWorker::onRunnerFinishedWithSuccess(ClangToolRunner *runner,
const QString &filePath)
{
auto runner = qobject_cast<ClangToolRunner *>(sender());
const QString outputFilePath = runner->outputFilePath();
qCDebug(LOG) << "onRunnerFinishedWithSuccess:" << outputFilePath;
@@ -363,7 +363,7 @@ void ClangToolRunWorker::onRunnerFinishedWithSuccess(const QString &filePath)
m_filesAnalyzed.remove(filePath);
m_filesNotAnalyzed.insert(filePath);
qCDebug(LOG) << "onRunnerFinishedWithSuccess: Error reading log file:" << errorMessage;
const QString filePath = qobject_cast<ClangToolRunner *>(sender())->fileToAnalyze();
const QString filePath = runner->fileToAnalyze();
appendMessage(tr("Failed to analyze \"%1\": %2").arg(filePath, errorMessage),
Utils::StdErrFormat);
} else {
@@ -377,19 +377,19 @@ void ClangToolRunWorker::onRunnerFinishedWithSuccess(const QString &filePath)
}
}
handleFinished();
handleFinished(runner);
}
void ClangToolRunWorker::onRunnerFinishedWithFailure(const QString &errorMessage,
const QString &errorDetails)
void ClangToolRunWorker::onRunnerFinishedWithFailure(ClangToolRunner *runner,
const QString &errorMessage,
const QString &errorDetails)
{
qCDebug(LOG).noquote() << "onRunnerFinishedWithFailure:"
<< errorMessage << '\n' << errorDetails;
qCDebug(LOG).noquote() << "onRunnerFinishedWithFailure:" << errorMessage
<< '\n' << errorDetails;
emit runnerFinished();
auto *toolRunner = qobject_cast<ClangToolRunner *>(sender());
const QString fileToAnalyze = toolRunner->fileToAnalyze();
const QString fileToAnalyze = runner->fileToAnalyze();
m_filesAnalyzed.remove(fileToAnalyze);
m_filesNotAnalyzed.insert(fileToAnalyze);
@@ -397,14 +397,14 @@ void ClangToolRunWorker::onRunnerFinishedWithFailure(const QString &errorMessage
const QString message = tr("Failed to analyze \"%1\": %2").arg(fileToAnalyze, errorMessage);
appendMessage(message, Utils::StdErrFormat);
appendMessage(errorDetails, Utils::StdErrFormat);
handleFinished();
handleFinished(runner);
}
void ClangToolRunWorker::handleFinished()
void ClangToolRunWorker::handleFinished(ClangToolRunner *runner)
{
m_runners.remove(qobject_cast<ClangToolRunner *>(sender()));
m_runners.remove(runner);
updateProgressValue();
sender()->deleteLater();
runner->deleteLater();
analyzeNextFile();
}
@@ -449,12 +449,13 @@ void ClangToolRunWorker::finalize()
template<class T>
ClangToolRunner *ClangToolRunWorker::createRunner()
{
using namespace std::placeholders;
auto runner = new T(m_diagnosticConfig, this);
runner->init(m_temporaryDir.path(), m_environment);
connect(runner, &ClangToolRunner::finishedWithSuccess,
this, &ClangToolRunWorker::onRunnerFinishedWithSuccess);
connect(runner, &ClangToolRunner::finishedWithFailure,
this, &ClangToolRunWorker::onRunnerFinishedWithFailure);
connect(runner, &ClangToolRunner::finishedWithSuccess, this,
std::bind(&ClangToolRunWorker::onRunnerFinishedWithSuccess, this, runner, _1));
connect(runner, &ClangToolRunner::finishedWithFailure, this,
std::bind(&ClangToolRunWorker::onRunnerFinishedWithFailure, this, runner, _1, _2));
return runner;
}

View File

@@ -84,8 +84,9 @@ signals:
void startFailed();
protected:
void onRunnerFinishedWithSuccess(const QString &filePath);
void onRunnerFinishedWithFailure(const QString &errorMessage, const QString &errorDetails);
void onRunnerFinishedWithSuccess(ClangToolRunner *runner, const QString &filePath);
void onRunnerFinishedWithFailure(ClangToolRunner *runner, const QString &errorMessage,
const QString &errorDetails);
private:
void start() final;
@@ -98,7 +99,7 @@ private:
const QString &clangVersion);
void analyzeNextFile();
void handleFinished();
void handleFinished(ClangToolRunner *runner);
void onProgressCanceled();
void updateProgressValue();