Skip to content

Commit 8226a49

Browse files
committed
improved progress output. Show progress messages in the ThreadDetails
1 parent cacd7d3 commit 8226a49

File tree

10 files changed

+74
-29
lines changed

10 files changed

+74
-29
lines changed

gui/checkthread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ class CheckThread : public QThread {
111111
*/
112112
void done();
113113

114-
void startCheck(CheckThread::Details details);
115-
void finishCheck(CheckThread::Details details);
114+
void startCheck(const CheckThread::Details& details);
115+
void finishCheck(const CheckThread::Details& details);
116116
protected:
117117

118118
/**

gui/mainwindow.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,7 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs)
10711071

10721072
settings.exename = QCoreApplication::applicationFilePath().toStdString();
10731073
settings.templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]";
1074+
settings.reportProgress = 10;
10741075

10751076
// default to --check-level=normal for GUI for now
10761077
settings.setCheckLevel(Settings::CheckLevel::normal);
@@ -2118,6 +2119,8 @@ void MainWindow::showThreadDetails()
21182119
auto* threadDetails = new ThreadDetails(this);
21192120
connect(mThread, &ThreadHandler::threadDetailsUpdated,
21202121
threadDetails, &ThreadDetails::threadDetailsUpdated, Qt::QueuedConnection);
2122+
connect(mThread, &ThreadHandler::progress,
2123+
threadDetails, &ThreadDetails::progress, Qt::QueuedConnection);
21212124
threadDetails->setAttribute(Qt::WA_DeleteOnClose);
21222125
threadDetails->show();
21232126
mThread->emitThreadDetailsUpdated();

gui/resultsview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void ResultsView::setResultsSource(ResultsTree::ResultsSource source)
162162
mUI->mTree->setResultsSource(source);
163163
}
164164

165-
void ResultsView::progress(int value, const QString& description)
165+
void ResultsView::filesCheckedProgress(int value, const QString& description)
166166
{
167167
mUI->mProgress->setValue(value);
168168
mUI->mProgress->setFormat(QString("%p% (%1)").arg(description));

gui/resultsview.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public slots:
307307
* @param value Current progress value
308308
* @param description Description to accompany the progress
309309
*/
310-
void progress(int value, const QString& description);
310+
void filesCheckedProgress(int value, const QString& description);
311311

312312
/**
313313
* @brief Slot for new error to be displayed

gui/threaddetails.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "threaddetails.h"
22
#include "ui_threaddetails.h"
33

4+
#include <QMutexLocker>
5+
46
ThreadDetails* ThreadDetails::mInstance;
57

68
ThreadDetails::ThreadDetails(QWidget *parent)
@@ -10,6 +12,8 @@ ThreadDetails::ThreadDetails(QWidget *parent)
1012
mInstance = this;
1113
setWindowFlags(Qt::Window);
1214
mUi->setupUi(this);
15+
connect(&mTimer, &QTimer::timeout, this, &ThreadDetails::updateUI);
16+
mTimer.start(1000);
1317
}
1418

1519
ThreadDetails::~ThreadDetails()
@@ -20,9 +24,28 @@ ThreadDetails::~ThreadDetails()
2024

2125
void ThreadDetails::threadDetailsUpdated(const QMap<int, CheckThread::Details>& threadDetails)
2226
{
23-
QString text("Thread\tStart time\tFile\n");
24-
for (const auto& td: threadDetails) {
25-
text += QString("%1\t%2\t%3\n").arg(td.threadIndex).arg(td.startTime.toString(Qt::TextDate)).arg(td.file);
27+
QMutexLocker locker(&mMutex);
28+
mThreadDetails = threadDetails;
29+
if (threadDetails.empty()) {
30+
mProgress.clear();
31+
}
32+
}
33+
34+
void ThreadDetails::progress(const QString &filename, const QString& stage, const std::size_t value) {
35+
QMutexLocker locker(&mMutex);
36+
mProgress[filename] = {QString(), stage + QString(value > 0 ? ": %1%" : "").arg(value)};
37+
}
38+
39+
void ThreadDetails::updateUI() {
40+
QString text("Thread\tStart time\tFile/Progress\n");
41+
{
42+
QMutexLocker locker(&mMutex);
43+
for (const auto& td: mThreadDetails) {
44+
auto& progress = mProgress[td.file];
45+
if (progress.first.isEmpty() && !progress.second.isEmpty())
46+
progress.first = QTime::currentTime().toString(Qt::TextDate);
47+
text += QString("%1\t%2\t%3\n\t%4\t%5\n").arg(td.threadIndex).arg(td.startTime.toString(Qt::TextDate)).arg(td.file).arg(progress.first).arg(progress.second);
48+
}
2649
}
2750
mUi->plainTextEdit->setPlainText(text);
2851
}

gui/threaddetails.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <QWidget>
55
#include <QMap>
6+
#include <QMutex>
7+
#include <QTimer>
68
#include "checkthread.h"
79

810
namespace Ui {
@@ -23,10 +25,20 @@ class ThreadDetails : public QWidget
2325

2426
public slots:
2527
void threadDetailsUpdated(const QMap<int, CheckThread::Details>& threadDetails);
28+
void progress(const QString &filename, const QString& stage, const std::size_t value);
29+
30+
private slots:
31+
void updateUI();
2632

2733
private:
2834
static ThreadDetails* mInstance;
2935
Ui::ThreadDetails *mUi;
36+
QMap<QString, QPair<QString,QString>> mProgress;
37+
QMap<int, CheckThread::Details> mThreadDetails;
38+
QTimer mTimer;
39+
40+
/** accessing mProgress and mThreadDetails in slots that are triggered from different threads */
41+
QMutex mMutex;
3042
};
3143

3244
#endif // THREADDETAILS_H

gui/threadhandler.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ void ThreadHandler::stop()
223223

224224
void ThreadHandler::initialize(const ResultsView *view)
225225
{
226-
connect(&mResults, &ThreadResult::progress,
227-
view, &ResultsView::progress);
226+
connect(&mResults, &ThreadResult::filesCheckedProgress,
227+
view, &ResultsView::filesCheckedProgress);
228228

229229
connect(&mResults, &ThreadResult::error,
230230
view, &ResultsView::error);
@@ -234,6 +234,9 @@ void ThreadHandler::initialize(const ResultsView *view)
234234

235235
connect(&mResults, &ThreadResult::debugError,
236236
this, &ThreadHandler::debugError);
237+
238+
connect(&mResults, &ThreadResult::progress,
239+
this, &ThreadHandler::progress);
237240
}
238241

239242
void ThreadHandler::loadSettings(const QSettings &settings)

gui/threadhandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ public slots:
221221
*/
222222
void finishCheck(const CheckThread::Details& details);
223223

224+
signals:
225+
void progress(const QString &filename, const QString& stage, const std::size_t value);
226+
224227
protected slots:
225228
/**
226229
* @brief Slot that a single thread is done

gui/threadresult.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ void ThreadResult::finishCheck(const CheckThread::Details& details)
3939
{
4040
std::lock_guard<std::mutex> locker(mutex);
4141

42-
mProgress += QFile(details.file).size();
42+
mCheckedFileSize += QFile(details.file).size();
4343
mFilesChecked++;
4444

45-
if (mMaxProgress > 0) {
46-
const int value = static_cast<int>(PROGRESS_MAX * mProgress / mMaxProgress);
45+
if (mTotalFileSize > 0) {
46+
const int value = static_cast<int>(PROGRESS_MAX * mCheckedFileSize / mTotalFileSize);
4747
const QString description = tr("%1 of %2 files checked").arg(mFilesChecked).arg(mTotalFiles);
4848

49-
emit progress(value, description);
49+
emit filesCheckedProgress(value, description);
5050
}
5151
}
5252

@@ -60,6 +60,10 @@ void ThreadResult::reportErr(const ErrorMessage &msg)
6060
emit debugError(item);
6161
}
6262

63+
void ThreadResult::reportProgress(const std::string &filename, const char stage[], const std::size_t value) {
64+
emit progress(QString::fromStdString(filename), stage, value);
65+
}
66+
6367
void ThreadResult::getNextFile(const FileWithDetails*& file)
6468
{
6569
std::lock_guard<std::mutex> locker(mutex);
@@ -88,15 +92,15 @@ void ThreadResult::setFiles(std::list<FileWithDetails> files)
8892
mTotalFiles = files.size();
8993
mFiles = std::move(files);
9094
mItNextFile = mFiles.cbegin();
91-
mProgress = 0;
95+
mCheckedFileSize = 0;
9296
mFilesChecked = 0;
9397

9498
// Determine the total size of all of the files to check, so that we can
9599
// show an accurate progress estimate
96100
quint64 sizeOfFiles = std::accumulate(mFiles.cbegin(), mFiles.cend(), 0, [](quint64 total, const FileWithDetails& file) {
97101
return total + file.size();
98102
});
99-
mMaxProgress = sizeOfFiles;
103+
mTotalFileSize = sizeOfFiles;
100104
}
101105

102106
void ThreadResult::setProject(const ImportProject &prj)
@@ -106,13 +110,13 @@ void ThreadResult::setProject(const ImportProject &prj)
106110
mItNextFile = mFiles.cbegin();
107111
mFileSettings = prj.fileSettings;
108112
mItNextFileSettings = mFileSettings.cbegin();
109-
mProgress = 0;
113+
mCheckedFileSize = 0;
110114
mFilesChecked = 0;
111115
mTotalFiles = prj.fileSettings.size();
112116

113117
// Determine the total size of all of the files to check, so that we can
114118
// show an accurate progress estimate
115-
mMaxProgress = std::accumulate(prj.fileSettings.begin(), prj.fileSettings.end(), quint64{ 0 }, [](quint64 v, const FileSettings& fs) {
119+
mTotalFileSize = std::accumulate(prj.fileSettings.begin(), prj.fileSettings.end(), quint64{ 0 }, [](quint64 v, const FileSettings& fs) {
116120
return v + QFile(QString::fromStdString(fs.filename())).size();
117121
});
118122
}

gui/threadresult.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class ThreadResult : public QObject, public ErrorLogger {
8484
{
8585
(void) metric;
8686
}
87+
void reportProgress(const std::string &filename, const char stage[], const std::size_t value) override;
8788

8889
public slots:
8990

@@ -97,10 +98,10 @@ public slots:
9798
/**
9899
* @brief Files checked progress
99100
* @param value Current progress (0 - PROGRESS_MAX)
100-
* @param description Description of the current stage (example: 13/45 files checked)
101+
* @param description Description of the current stage (example: "13/45 files checked")
101102
*/
102103
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
103-
void progress(int value, const QString& description);
104+
void filesCheckedProgress(int value, const QString& description);
104105

105106
/**
106107
* @brief Signal of a new error
@@ -126,6 +127,8 @@ public slots:
126127
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
127128
void debugError(const ErrorItem &item);
128129

130+
void progress(const QString &filename, const QString& stage, const std::size_t value);
131+
129132
protected:
130133

131134
/**
@@ -144,17 +147,11 @@ public slots:
144147
std::list<FileSettings> mFileSettings;
145148
std::list<FileSettings>::const_iterator mItNextFileSettings{mFileSettings.cbegin()};
146149

147-
/**
148-
* @brief Max progress
149-
*
150-
*/
151-
quint64 mMaxProgress{};
150+
/** @brief Total file size */
151+
quint64 mTotalFileSize{};
152152

153-
/**
154-
* @brief Current progress
155-
*
156-
*/
157-
quint64 mProgress{};
153+
/** @brief File size of checked files */
154+
quint64 mCheckedFileSize{};
158155

159156
/**
160157
* @brief Current number of files checked

0 commit comments

Comments
 (0)