Skip to content

Commit baecc05

Browse files
ludviggunnedanmar
authored andcommitted
Fix #14290 (GUI: detailed progress view that shows what files the threads are working on)
1 parent 3dc52dc commit baecc05

15 files changed

Lines changed: 253 additions & 26 deletions

.selfcheck_suppressions

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

1717
# --debug-warnings suppressions
1818
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

@@ -48,8 +49,16 @@ class ThreadResult;
4849
*/
4950
class CheckThread : public QThread {
5051
Q_OBJECT
52+
53+
public:
54+
struct Details {
55+
int threadIndex;
56+
QString file;
57+
QTime startTime;
58+
};
59+
5160
public:
52-
explicit CheckThread(ThreadResult &result);
61+
CheckThread(ThreadResult &result, int threadIndex);
5362

5463
/**
5564
* @brief Set settings for cppcheck
@@ -102,8 +111,8 @@ class CheckThread : public QThread {
102111
*/
103112
void done();
104113

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

109118
/**
@@ -126,6 +135,7 @@ class CheckThread : public QThread {
126135
std::atomic<State> mState{Ready};
127136

128137
ThreadResult &mResult;
138+
int mThreadIndex{};
129139

130140
Settings mSettings;
131141
std::shared_ptr<Suppressions> mSuppressions;

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: 14 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);
@@ -2109,6 +2111,18 @@ void MainWindow::showLibraryEditor()
21092111
libraryDialog.exec();
21102112
}
21112113

2114+
void MainWindow::showThreadDetails()
2115+
{
2116+
if (ThreadDetails::instance())
2117+
return;
2118+
auto* threadDetails = new ThreadDetails(this);
2119+
connect(mThread, &ThreadHandler::threadDetailsUpdated,
2120+
threadDetails, &ThreadDetails::threadDetailsUpdated, Qt::QueuedConnection);
2121+
threadDetails->setAttribute(Qt::WA_DeleteOnClose);
2122+
threadDetails->show();
2123+
mThread->emitThreadDetailsUpdated();
2124+
}
2125+
21122126
void MainWindow::filterResults()
21132127
{
21142128
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/test/resultstree/testresultstree.cpp

Lines changed: 10 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*/) {

gui/threaddetails.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "threaddetails.h"
2+
#include "ui_threaddetails.h"
3+
4+
ThreadDetails* ThreadDetails::mInstance;
5+
6+
ThreadDetails::ThreadDetails(QWidget *parent)
7+
: QWidget(parent)
8+
, mUi(new Ui::ThreadDetails)
9+
{
10+
mInstance = this;
11+
setWindowFlags(Qt::Window);
12+
mUi->setupUi(this);
13+
}
14+
15+
ThreadDetails::~ThreadDetails()
16+
{
17+
mInstance = nullptr;
18+
delete mUi;
19+
}
20+
21+
void ThreadDetails::threadDetailsUpdated(QMap<int, CheckThread::Details> threadDetails)
22+
{
23+
mUi->tableWidget->setRowCount(threadDetails.size());
24+
int row = 0;
25+
for (const auto& td: threadDetails) {
26+
mUi->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(td.threadIndex)));
27+
mUi->tableWidget->setItem(row, 1, new QTableWidgetItem(QString(td.startTime.toString(Qt::TextDate))));
28+
mUi->tableWidget->setItem(row, 2, new QTableWidgetItem(td.file));
29+
++row;
30+
}
31+
}

gui/threaddetails.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef THREADDETAILS_H
2+
#define THREADDETAILS_H
3+
4+
#include <QWidget>
5+
#include <QMap>
6+
#include "checkthread.h"
7+
8+
namespace Ui {
9+
class ThreadDetails;
10+
}
11+
12+
class ThreadDetails : public QWidget
13+
{
14+
Q_OBJECT
15+
16+
public:
17+
explicit ThreadDetails(QWidget *parent = nullptr);
18+
~ThreadDetails() override;
19+
20+
static ThreadDetails* instance() {
21+
return mInstance;
22+
}
23+
24+
public slots:
25+
void threadDetailsUpdated(QMap<int, CheckThread::Details> threadDetails);
26+
27+
private:
28+
static ThreadDetails* mInstance;
29+
Ui::ThreadDetails *mUi;
30+
};
31+
32+
#endif // THREADDETAILS_H

0 commit comments

Comments
 (0)