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

View File

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