Skip to content

Commit acd1529

Browse files
committed
Add startCheck, finishCheck and threadDetailsUpdated signals/slots
1 parent f622793 commit acd1529

6 files changed

Lines changed: 97 additions & 15 deletions

File tree

gui/checkthread.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,14 @@ void CheckThread::run()
147147
while (file && mState == Running) {
148148
const std::string& fname = file->spath();
149149
qDebug() << "Checking file" << QString::fromStdString(fname);
150+
151+
const Details details = { mThreadIndex, fname, QTime::currentTime(), };
152+
emit startCheck(details);
153+
150154
cppcheck.check(*file);
151155
runAddonsAndTools(mSettings, nullptr, QString::fromStdString(fname));
152-
emit fileChecked(QString::fromStdString(fname));
156+
157+
emit finishCheck(details);
153158

154159
if (mState == Running)
155160
mResult.getNextFile(file);
@@ -160,9 +165,15 @@ void CheckThread::run()
160165
while (fileSettings && mState == Running) {
161166
const std::string& fname = fileSettings->filename();
162167
qDebug() << "Checking file" << QString::fromStdString(fname);
163-
cppcheck.check(*fileSettings);
168+
169+
const Details details = { mThreadIndex, fname, QTime::currentTime(), };
170+
emit startCheck(details);
171+
172+
cppcheck.check(*file);
164173
runAddonsAndTools(mSettings, fileSettings, QString::fromStdString(fname));
165-
emit fileChecked(QString::fromStdString(fname));
174+
175+
emit finishCheck(details);
176+
166177

167178
if (mState == Running)
168179
mResult.getNextFileSettings(fileSettings);

gui/checkthread.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <QString>
3737
#include <QStringList>
3838
#include <QThread>
39+
#include <QTime>
3940

4041
class ThreadResult;
4142

@@ -48,6 +49,14 @@ class ThreadResult;
4849
*/
4950
class CheckThread : public QThread {
5051
Q_OBJECT
52+
53+
public:
54+
struct Details {
55+
int index;
56+
std::string file;
57+
QTime startTime;
58+
};
59+
5160
public:
5261
explicit CheckThread(ThreadResult &result);
5362

@@ -104,8 +113,8 @@ class CheckThread : public QThread {
104113
*/
105114
void done();
106115

107-
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
108-
void fileChecked(const QString &file);
116+
void startCheck(CheckThread::Details details);
117+
void finishCheck(CheckThread::Details details);
109118
protected:
110119

111120
/**

gui/threadhandler.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ void ThreadHandler::createThreads(const int count)
150150
mThreads.last()->setThreadIndex(i + 1);
151151
connect(mThreads.last(), &CheckThread::done,
152152
this, &ThreadHandler::threadDone, Qt::QueuedConnection);
153-
connect(mThreads.last(), &CheckThread::fileChecked,
154-
&mResults, &ThreadResult::fileChecked, Qt::QueuedConnection);
153+
connect(mThreads.last(), &CheckThread::finishCheck,
154+
&mResults, &ThreadResult::finishCheck, Qt::QueuedConnection);
155+
connect(mThreads.last(), &CheckThread::startCheck,
156+
this, &ThreadHandler::startCheck, Qt::QueuedConnection);
157+
connect(mThreads.last(), &CheckThread::finishCheck,
158+
this, &ThreadHandler::finishCheck, Qt::QueuedConnection);
155159
}
156160
}
157161

@@ -165,8 +169,12 @@ void ThreadHandler::removeThreads()
165169
}
166170
disconnect(thread, &CheckThread::done,
167171
this, &ThreadHandler::threadDone);
168-
disconnect(thread, &CheckThread::fileChecked,
169-
&mResults, &ThreadResult::fileChecked);
172+
disconnect(thread, &CheckThread::finishCheck,
173+
&mResults, &ThreadResult::finishCheck);
174+
disconnect(mThreads.last(), &CheckThread::startCheck,
175+
this, &ThreadHandler::startCheck);
176+
disconnect(mThreads.last(), &CheckThread::finishCheck,
177+
this, &ThreadHandler::finishCheck);
170178
delete thread;
171179
}
172180

@@ -318,3 +326,29 @@ void ThreadHandler::setCheckStartTime(QDateTime checkStartTime)
318326
{
319327
mCheckStartTime = std::move(checkStartTime);
320328
}
329+
330+
void ThreadHandler::startCheck(CheckThread::Details details)
331+
{
332+
mThreadDetails[details.index] = details;
333+
emit threadDetailsUpdated(buildThreadDetailsText());
334+
}
335+
336+
void ThreadHandler::finishCheck(CheckThread::Details details)
337+
{
338+
mThreadDetails.erase(details.index);
339+
emit threadDetailsUpdated(buildThreadDetailsText());
340+
}
341+
342+
QString ThreadHandler::buildThreadDetailsText() const
343+
{
344+
QString result;
345+
346+
for (const auto &details : mThreadDetails) {
347+
result += QString("Thread %1 (%2): %3\n")
348+
.arg(details.second.index)
349+
.arg(details.second.startTime.toString(Qt::TextDate))
350+
.arg(QString::fromStdString(details.second.file));
351+
}
352+
353+
return result;
354+
}

gui/threadhandler.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,33 @@ class ThreadHandler : public QObject {
191191
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
192192
void debugError(const ErrorItem &item);
193193

194+
/**
195+
* @brief Emitted when thread details are updated.
196+
*
197+
* @param text Text for the ThreadDetails widget to display
198+
*/
199+
void threadDetailsUpdated(const QString &text);
200+
194201
public slots:
195202

196203
/**
197204
* @brief Slot to stop all threads
198205
*
199206
*/
200207
void stop();
208+
209+
/**
210+
* @brief Slot threads use to signal this class that it started checking a file
211+
* @param details Details about what file is being checked and by what thread
212+
*/
213+
void startCheck(CheckThread::Details details);
214+
215+
/**
216+
* @brief Slot threads use to signal this class that it finish checking a file
217+
* @param details Details about what file finished being checked and by what thread
218+
*/
219+
void finishCheck(CheckThread::Details details);
220+
201221
protected slots:
202222
/**
203223
* @brief Slot that a single thread is done
@@ -285,13 +305,21 @@ protected slots:
285305
Settings mCheckSettings;
286306
std::shared_ptr<Suppressions> mCheckSuppressions;
287307
/// @}
308+
309+
/**
310+
* @bried Details about currently running threads
311+
*/
312+
std::map<int, CheckThread::Details> mThreadDetails;
313+
288314
private:
289315

290316
/**
291317
* @brief Check if a file needs to be rechecked. Recursively checks
292318
* included headers. Used by GetReCheckFiles()
293319
*/
294320
bool needsReCheck(const QString &filename, std::set<QString> &modified, std::set<QString> &unmodified) const;
321+
322+
QString buildThreadDetailsText() const;
295323
};
296324
/// @}
297325
#endif // THREADHANDLER_H

gui/threadresult.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ void ThreadResult::reportOut(const std::string &outmsg, Color /*c*/)
3434
emit log(QString::fromStdString(outmsg));
3535
}
3636

37-
void ThreadResult::fileChecked(const QString &file)
37+
void ThreadResult::finishCheck(CheckThread::Details details)
3838
{
3939
std::lock_guard<std::mutex> locker(mutex);
4040

41-
mProgress += QFile(file).size();
41+
mProgress += QFile(QString::fromStdString(details.file)).size();
4242
mFilesChecked++;
4343

4444
if (mMaxProgress > 0) {

gui/threadresult.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ class ThreadResult : public QObject, public ErrorLogger {
8585
}
8686

8787
public slots:
88-
8988
/**
90-
* @brief Slot threads use to signal this class that a specific file is checked
91-
* @param file File that is checked
89+
* @brief Slot threads use to signal this class that it finish checking a file
90+
* @param details Details about what file finished being checked and by what thread
9291
*/
93-
void fileChecked(const QString &file);
92+
void finishCheck(CheckThread::Details details);
93+
9494
signals:
9595
/**
9696
* @brief Progress signal

0 commit comments

Comments
 (0)