Skip to content

Commit 179f04a

Browse files
danmarludviggunne
andauthored
Fix #14290 (GUI: detailed progress view that shows what files the threads are working on) (#8217)
Co-authored-by: Ludvig Gunne Lindström <ludviggunnelindstrom@gmail.com>
1 parent 1f72150 commit 179f04a

17 files changed

+314
-51
lines changed

.selfcheck_suppressions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ funcArgNamesDifferent:*/moc_resultsview.cpp
1010
funcArgNamesDifferent:*/moc_threadhandler.cpp
1111
funcArgNamesDifferent:*/moc_threadresult.cpp
1212
naming-varname:*/gui/ui_*.h
13-
functionStatic:*/ui_fileview.h
13+
functionStatic:*/gui/ui_*.h
1414

1515
# --debug-warnings suppressions
1616
valueFlowBailout

gui/checkthread.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ int CheckThread::executeCommand(std::string exe, std::vector<std::string> args,
105105
}
106106

107107

108-
CheckThread::CheckThread(ThreadResult &result) :
109-
mResult(result)
108+
CheckThread::CheckThread(ThreadResult &result, int threadIndex)
109+
: mResult(result)
110+
, mThreadIndex(threadIndex)
110111
{}
111112

112113
void CheckThread::setSettings(const Settings &settings, std::shared_ptr<Suppressions> supprs)
@@ -147,9 +148,14 @@ void CheckThread::run()
147148
while (file && mState == Running) {
148149
const std::string& fname = file->spath();
149150
qDebug() << "Checking file" << QString::fromStdString(fname);
151+
152+
const Details details{ mThreadIndex, QString::fromStdString(fname), QTime::currentTime(), };
153+
emit startCheck(details);
154+
150155
cppcheck.check(*file);
151156
runAddonsAndTools(mSettings, nullptr, QString::fromStdString(fname));
152-
emit fileChecked(QString::fromStdString(fname));
157+
158+
emit finishCheck(details);
153159

154160
if (mState == Running)
155161
mResult.getNextFile(file);
@@ -160,9 +166,15 @@ void CheckThread::run()
160166
while (fileSettings && mState == Running) {
161167
const std::string& fname = fileSettings->filename();
162168
qDebug() << "Checking file" << QString::fromStdString(fname);
163-
cppcheck.check(*fileSettings);
169+
170+
const Details details{ mThreadIndex, QString::fromStdString(fname), QTime::currentTime(), };
171+
emit startCheck(details);
172+
173+
cppcheck.check(*file);
164174
runAddonsAndTools(mSettings, fileSettings, QString::fromStdString(fname));
165-
emit fileChecked(QString::fromStdString(fname));
175+
176+
emit finishCheck(details);
177+
166178

167179
if (mState == Running)
168180
mResult.getNextFileSettings(fileSettings);
@@ -486,3 +498,4 @@ QString CheckThread::clangTidyCmd()
486498

487499
return QString();
488500
}
501+

gui/checkthread.h

Lines changed: 13 additions & 3 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

@@ -49,7 +50,14 @@ class ThreadResult;
4950
class CheckThread : public QThread {
5051
Q_OBJECT
5152
public:
52-
explicit CheckThread(ThreadResult &result);
53+
struct Details {
54+
int threadIndex;
55+
QString file;
56+
QTime startTime;
57+
};
58+
59+
public:
60+
CheckThread(ThreadResult &result, int threadIndex);
5361

5462
/**
5563
* @brief Set settings for cppcheck
@@ -102,8 +110,8 @@ class CheckThread : public QThread {
102110
*/
103111
void done();
104112

105-
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
106-
void fileChecked(const QString &file);
113+
void startCheck(CheckThread::Details details);
114+
void finishCheck(CheckThread::Details details);
107115
protected:
108116

109117
/**
@@ -126,6 +134,7 @@ class CheckThread : public QThread {
126134
std::atomic<State> mState{Ready};
127135

128136
ThreadResult &mResult;
137+
int mThreadIndex{};
129138

130139
Settings mSettings;
131140
std::shared_ptr<Suppressions> mSuppressions;
@@ -150,5 +159,6 @@ class CheckThread : public QThread {
150159
QStringList mClangIncludePaths;
151160
QList<SuppressionList::Suppression> mSuppressionsUi;
152161
};
162+
Q_DECLARE_METATYPE(CheckThread::Details);
153163
/// @}
154164
#endif // CHECKTHREAD_H

gui/gui.pro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ FORMS = about.ui \
7070
librarydialog.ui \
7171
libraryaddfunctiondialog.ui \
7272
libraryeditargdialog.ui \
73-
newsuppressiondialog.ui
73+
newsuppressiondialog.ui \
74+
threaddetails.ui
7475

7576
TRANSLATIONS = cppcheck_de.ts \
7677
cppcheck_es.ts \
@@ -156,6 +157,7 @@ HEADERS += aboutdialog.h \
156157
settingsdialog.h \
157158
showtypes.h \
158159
statsdialog.h \
160+
threaddetails.h \
159161
threadhandler.h \
160162
threadresult.h \
161163
translationhandler.h \
@@ -199,6 +201,7 @@ SOURCES += aboutdialog.cpp \
199201
settingsdialog.cpp \
200202
showtypes.cpp \
201203
statsdialog.cpp \
204+
threaddetails.cpp \
202205
threadhandler.cpp \
203206
threadresult.cpp \
204207
translationhandler.cpp \

gui/mainwindow.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "threadresult.h"
5454
#include "translationhandler.h"
5555
#include "utils.h"
56+
#include "threaddetails.h"
5657

5758
#include "ui_mainwindow.h"
5859

@@ -183,6 +184,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
183184
connect(mUI->mActionShowHidden, &QAction::triggered, mUI->mResults, &ResultsView::showHiddenResults);
184185
connect(mUI->mActionViewStats, &QAction::triggered, this, &MainWindow::showStatistics);
185186
connect(mUI->mActionLibraryEditor, &QAction::triggered, this, &MainWindow::showLibraryEditor);
187+
connect(mUI->mActionShowThreadDetails, &QAction::triggered, this, &MainWindow::showThreadDetails);
186188

187189
connect(mUI->mActionReanalyzeModified, &QAction::triggered, this, &MainWindow::reAnalyzeModified);
188190
connect(mUI->mActionReanalyzeAll, &QAction::triggered, this, &MainWindow::reAnalyzeAll);
@@ -1069,6 +1071,7 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs)
10691071

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

10731076
// default to --check-level=normal for GUI for now
10741077
settings.setCheckLevel(Settings::CheckLevel::normal);
@@ -2109,6 +2112,20 @@ void MainWindow::showLibraryEditor()
21092112
libraryDialog.exec();
21102113
}
21112114

2115+
void MainWindow::showThreadDetails()
2116+
{
2117+
if (ThreadDetails::instance())
2118+
return;
2119+
auto* threadDetails = new ThreadDetails(this);
2120+
connect(mThread, &ThreadHandler::threadDetailsUpdated,
2121+
threadDetails, &ThreadDetails::threadDetailsUpdated, Qt::QueuedConnection);
2122+
connect(mThread, &ThreadHandler::progress,
2123+
threadDetails, &ThreadDetails::progress, Qt::QueuedConnection);
2124+
threadDetails->setAttribute(Qt::WA_DeleteOnClose);
2125+
threadDetails->show();
2126+
mThread->emitThreadDetailsUpdated();
2127+
}
2128+
21122129
void MainWindow::filterResults()
21132130
{
21142131
mUI->mResults->filterResults(mLineEditFilter->text());

gui/mainwindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ public slots:
200200
/** @brief Slot for showing the library editor */
201201
void showLibraryEditor();
202202

203+
/** @brief Slot for showing the thread details window */
204+
void showThreadDetails();
205+
203206
private slots:
204207

205208
/** @brief Slot for checkthread's done signal */

gui/mainwindow.ui

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<item>
6565
<layout class="QHBoxLayout" name="mLayoutInformation">
6666
<property name="sizeConstraint">
67-
<enum>QLayout::SetDefaultConstraint</enum>
67+
<enum>QLayout::SizeConstraint::SetDefaultConstraint</enum>
6868
</property>
6969
<item>
7070
<widget class="QLabel" name="mLabelInformation">
@@ -84,13 +84,13 @@
8484
<string>Checking for updates</string>
8585
</property>
8686
<property name="textFormat">
87-
<enum>Qt::RichText</enum>
87+
<enum>Qt::TextFormat::RichText</enum>
8888
</property>
8989
<property name="openExternalLinks">
9090
<bool>true</bool>
9191
</property>
9292
<property name="textInteractionFlags">
93-
<set>Qt::TextBrowserInteraction</set>
93+
<set>Qt::TextInteractionFlag::TextBrowserInteraction</set>
9494
</property>
9595
</widget>
9696
</item>
@@ -104,7 +104,7 @@
104104
<item>
105105
<spacer name="horizontalSpacer">
106106
<property name="orientation">
107-
<enum>Qt::Horizontal</enum>
107+
<enum>Qt::Orientation::Horizontal</enum>
108108
</property>
109109
<property name="sizeHint" stdset="0">
110110
<size>
@@ -124,7 +124,7 @@
124124
<x>0</x>
125125
<y>0</y>
126126
<width>640</width>
127-
<height>22</height>
127+
<height>21</height>
128128
</rect>
129129
</property>
130130
<widget class="QMenu" name="mMenuFile">
@@ -192,6 +192,7 @@
192192
<addaction name="mActionShowScratchpad"/>
193193
<addaction name="mActionViewStats"/>
194194
<addaction name="mActionLibraryEditor"/>
195+
<addaction name="mActionShowThreadDetails"/>
195196
</widget>
196197
<widget class="QMenu" name="mMenuHelp">
197198
<property name="title">
@@ -1040,6 +1041,14 @@
10401041
<string>EULA...</string>
10411042
</property>
10421043
</action>
1044+
<action name="mActionShowThreadDetails">
1045+
<property name="text">
1046+
<string>Thread Details</string>
1047+
</property>
1048+
<property name="toolTip">
1049+
<string>Show thread details</string>
1050+
</property>
1051+
</action>
10431052
</widget>
10441053
<customwidgets>
10451054
<customwidget>

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/test/resultstree/testresultstree.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ void ThreadHandler::stop() {
9393
void ThreadHandler::threadDone() {
9494
throw 1;
9595
}
96+
// NOLINTBEGIN(performance-unnecessary-value-param)
97+
void ThreadHandler::startCheck(CheckThread::Details /*unused*/) {
98+
throw 1;
99+
}
100+
void ThreadHandler::finishCheck(CheckThread::Details /*unused*/) {
101+
throw 1;
102+
}
103+
// NOLINTEND(performance-unnecessary-value-param)
96104
Application& ApplicationList::getApplication(const int /*unused*/) {
97105
throw 1;
98106
}
@@ -106,7 +114,8 @@ QString XmlReport::unquoteMessage(const QString &message) {
106114
return message;
107115
}
108116
XmlReport::XmlReport(const QString& filename) : Report(filename) {}
109-
void ThreadResult::fileChecked(const QString & /*unused*/) {
117+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
118+
void ThreadResult::finishCheck(CheckThread::Details /*unused*/) {
110119
throw 1;
111120
}
112121
void ThreadResult::reportOut(const std::string & /*unused*/, Color /*unused*/) {
@@ -115,6 +124,9 @@ void ThreadResult::reportOut(const std::string & /*unused*/, Color /*unused*/) {
115124
void ThreadResult::reportErr(const ErrorMessage & /*unused*/) {
116125
throw 1;
117126
}
127+
void ThreadResult::reportProgress(const std::string &/*filename*/, const char /*stage*/[], const std::size_t /*value*/) {
128+
throw 1;
129+
}
118130

119131
// Test...
120132

0 commit comments

Comments
 (0)