Skip to content

Commit 643d400

Browse files
committed
GUI: Refactoring progress/finished handling.
Progress signal had also item count with it and then the handler determined that check is ready when max count of progress was done. Also progressbar was practically reset in every progress signal. This was simply fragile code. After this patch progress signal has only the current progress count. Total count of items is given when initializing the checking. And there is separate function for handling check finishing. This also fixes the bug that progressbar was not hidden after checking or when interrupting the checking.
1 parent acbf5af commit 643d400

6 files changed

Lines changed: 50 additions & 51 deletions

File tree

gui/mainwindow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void MainWindow::DoCheckFiles(const QStringList &files)
221221
return;
222222
}
223223

224-
mUI.mResults->CheckingStarted();
224+
mUI.mResults->CheckingStarted(fileNames.count());
225225

226226
mThread->SetFiles(RemoveUnacceptedFiles(fileNames));
227227
QFileInfo inf(fileNames[0]);
@@ -386,6 +386,7 @@ QStringList MainWindow::RemoveUnacceptedFiles(const QStringList &list)
386386

387387
void MainWindow::CheckDone()
388388
{
389+
mUI.mResults->CheckingFinished();
389390
EnableCheckButtons(true);
390391
mUI.mActionSettings->setEnabled(true);
391392
if (mUI.mResults->HasResults())

gui/resultsview.cpp

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -61,48 +61,9 @@ void ResultsView::Clear()
6161
mUI.mProgress->setValue(0);
6262
}
6363

64-
65-
66-
void ResultsView::Progress(int value, int max)
64+
void ResultsView::Progress(int value)
6765
{
68-
mUI.mProgress->setMaximum(max);
6966
mUI.mProgress->setValue(value);
70-
if (value >= max)
71-
{
72-
mUI.mProgress->setVisible(false);
73-
//Should we inform user of non visible/not found errors?
74-
if (mShowNoErrorsMessage)
75-
{
76-
//Tell user that we found no errors
77-
if (!mErrorsFound)
78-
{
79-
QMessageBox msg(QMessageBox::Information,
80-
tr("Cppcheck"),
81-
tr("No errors found."),
82-
QMessageBox::Ok,
83-
this);
84-
85-
msg.exec();
86-
} //If we have errors but they aren't visible, tell user about it
87-
else if (!mUI.mTree->HasVisibleResults())
88-
{
89-
QString text = tr("Errors were found, but they are configured to be hidden.\n"\
90-
"To toggle what kind of errors are shown, open view menu.");
91-
QMessageBox msg(QMessageBox::Information,
92-
tr("Cppcheck"),
93-
text,
94-
QMessageBox::Ok,
95-
this);
96-
97-
msg.exec();
98-
}
99-
}
100-
}
101-
else
102-
{
103-
mUI.mProgress->setVisible(true);
104-
mUI.mProgress->setEnabled(true);
105-
}
10667
}
10768

10869
void ResultsView::Error(const QString &file,
@@ -194,9 +155,42 @@ void ResultsView::SetCheckDirectory(const QString &dir)
194155
mUI.mTree->SetCheckDirectory(dir);
195156
}
196157

197-
void ResultsView::CheckingStarted()
158+
void ResultsView::CheckingStarted(int count)
198159
{
199160
mUI.mProgress->setVisible(true);
161+
mUI.mProgress->setMaximum(count);
162+
}
163+
164+
void ResultsView::CheckingFinished()
165+
{
166+
mUI.mProgress->setVisible(false);
167+
//Should we inform user of non visible/not found errors?
168+
if (mShowNoErrorsMessage)
169+
{
170+
//Tell user that we found no errors
171+
if (!mErrorsFound)
172+
{
173+
QMessageBox msg(QMessageBox::Information,
174+
tr("Cppcheck"),
175+
tr("No errors found."),
176+
QMessageBox::Ok,
177+
this);
178+
179+
msg.exec();
180+
} //If we have errors but they aren't visible, tell user about it
181+
else if (!mUI.mTree->HasVisibleResults())
182+
{
183+
QString text = tr("Errors were found, but they are configured to be hidden.\n"\
184+
"To toggle what kind of errors are shown, open view menu.");
185+
QMessageBox msg(QMessageBox::Information,
186+
tr("Cppcheck"),
187+
text,
188+
QMessageBox::Ok,
189+
this);
190+
191+
msg.exec();
192+
}
193+
}
200194
}
201195

202196
bool ResultsView::HasVisibleResults() const

gui/resultsview.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,15 @@ class ResultsView : public QWidget
9292
/**
9393
* @brief Inform the view that checking has started
9494
*
95-
* At the moment this only displays the progressbar
95+
* @param count Count of files to be checked.
9696
*/
97-
void CheckingStarted();
97+
void CheckingStarted(int count);
98+
99+
/**
100+
* @brief Inform the view that checking finished.
101+
*
102+
*/
103+
void CheckingFinished();
98104

99105
/**
100106
* @brief Do we have visible results to show?
@@ -138,9 +144,8 @@ public slots:
138144
* @brief Slot for updating the checking progress
139145
*
140146
* @param value Current progress value
141-
* @param max Maximum progress value
142147
*/
143-
void Progress(int value, int max);
148+
void Progress(int value);
144149

145150
/**
146151
* @brief Slot for new error to be displayed

gui/threadhandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ void ThreadHandler::Stop()
138138
void ThreadHandler::Initialize(ResultsView *view)
139139
{
140140

141-
connect(&mResults, SIGNAL(Progress(int, int)),
142-
view, SLOT(Progress(int, int)));
141+
connect(&mResults, SIGNAL(Progress(int)),
142+
view, SLOT(Progress(int)));
143143

144144
connect(&mResults, SIGNAL(Error(const QString &,
145145
const QString &,

gui/threadresult.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void ThreadResult::FileChecked(const QString &file)
4040
QMutexLocker locker(&mutex);
4141
Q_UNUSED(file); //For later use maybe?
4242
mProgress++;
43-
emit Progress(mProgress, mMaxProgress);
43+
emit Progress(mProgress);
4444
}
4545

4646
void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)

gui/threadresult.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ public slots:
8181
/**
8282
* @brief Progress signal
8383
* @param value Current progress
84-
* @param max Maximum progress
8584
*/
86-
void Progress(int value, int max);
85+
void Progress(int value);
8786

8887
/**
8988
* @brief Signal of a new error

0 commit comments

Comments
 (0)