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.
This commit is contained in:
parent
acbf5af586
commit
643d400716
|
@ -221,7 +221,7 @@ void MainWindow::DoCheckFiles(const QStringList &files)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mUI.mResults->CheckingStarted();
|
mUI.mResults->CheckingStarted(fileNames.count());
|
||||||
|
|
||||||
mThread->SetFiles(RemoveUnacceptedFiles(fileNames));
|
mThread->SetFiles(RemoveUnacceptedFiles(fileNames));
|
||||||
QFileInfo inf(fileNames[0]);
|
QFileInfo inf(fileNames[0]);
|
||||||
|
@ -386,6 +386,7 @@ QStringList MainWindow::RemoveUnacceptedFiles(const QStringList &list)
|
||||||
|
|
||||||
void MainWindow::CheckDone()
|
void MainWindow::CheckDone()
|
||||||
{
|
{
|
||||||
|
mUI.mResults->CheckingFinished();
|
||||||
EnableCheckButtons(true);
|
EnableCheckButtons(true);
|
||||||
mUI.mActionSettings->setEnabled(true);
|
mUI.mActionSettings->setEnabled(true);
|
||||||
if (mUI.mResults->HasResults())
|
if (mUI.mResults->HasResults())
|
||||||
|
|
|
@ -61,48 +61,9 @@ void ResultsView::Clear()
|
||||||
mUI.mProgress->setValue(0);
|
mUI.mProgress->setValue(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResultsView::Progress(int value)
|
||||||
|
|
||||||
void ResultsView::Progress(int value, int max)
|
|
||||||
{
|
{
|
||||||
mUI.mProgress->setMaximum(max);
|
|
||||||
mUI.mProgress->setValue(value);
|
mUI.mProgress->setValue(value);
|
||||||
if (value >= max)
|
|
||||||
{
|
|
||||||
mUI.mProgress->setVisible(false);
|
|
||||||
//Should we inform user of non visible/not found errors?
|
|
||||||
if (mShowNoErrorsMessage)
|
|
||||||
{
|
|
||||||
//Tell user that we found no errors
|
|
||||||
if (!mErrorsFound)
|
|
||||||
{
|
|
||||||
QMessageBox msg(QMessageBox::Information,
|
|
||||||
tr("Cppcheck"),
|
|
||||||
tr("No errors found."),
|
|
||||||
QMessageBox::Ok,
|
|
||||||
this);
|
|
||||||
|
|
||||||
msg.exec();
|
|
||||||
} //If we have errors but they aren't visible, tell user about it
|
|
||||||
else if (!mUI.mTree->HasVisibleResults())
|
|
||||||
{
|
|
||||||
QString text = tr("Errors were found, but they are configured to be hidden.\n"\
|
|
||||||
"To toggle what kind of errors are shown, open view menu.");
|
|
||||||
QMessageBox msg(QMessageBox::Information,
|
|
||||||
tr("Cppcheck"),
|
|
||||||
text,
|
|
||||||
QMessageBox::Ok,
|
|
||||||
this);
|
|
||||||
|
|
||||||
msg.exec();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mUI.mProgress->setVisible(true);
|
|
||||||
mUI.mProgress->setEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResultsView::Error(const QString &file,
|
void ResultsView::Error(const QString &file,
|
||||||
|
@ -194,9 +155,42 @@ void ResultsView::SetCheckDirectory(const QString &dir)
|
||||||
mUI.mTree->SetCheckDirectory(dir);
|
mUI.mTree->SetCheckDirectory(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResultsView::CheckingStarted()
|
void ResultsView::CheckingStarted(int count)
|
||||||
{
|
{
|
||||||
mUI.mProgress->setVisible(true);
|
mUI.mProgress->setVisible(true);
|
||||||
|
mUI.mProgress->setMaximum(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResultsView::CheckingFinished()
|
||||||
|
{
|
||||||
|
mUI.mProgress->setVisible(false);
|
||||||
|
//Should we inform user of non visible/not found errors?
|
||||||
|
if (mShowNoErrorsMessage)
|
||||||
|
{
|
||||||
|
//Tell user that we found no errors
|
||||||
|
if (!mErrorsFound)
|
||||||
|
{
|
||||||
|
QMessageBox msg(QMessageBox::Information,
|
||||||
|
tr("Cppcheck"),
|
||||||
|
tr("No errors found."),
|
||||||
|
QMessageBox::Ok,
|
||||||
|
this);
|
||||||
|
|
||||||
|
msg.exec();
|
||||||
|
} //If we have errors but they aren't visible, tell user about it
|
||||||
|
else if (!mUI.mTree->HasVisibleResults())
|
||||||
|
{
|
||||||
|
QString text = tr("Errors were found, but they are configured to be hidden.\n"\
|
||||||
|
"To toggle what kind of errors are shown, open view menu.");
|
||||||
|
QMessageBox msg(QMessageBox::Information,
|
||||||
|
tr("Cppcheck"),
|
||||||
|
text,
|
||||||
|
QMessageBox::Ok,
|
||||||
|
this);
|
||||||
|
|
||||||
|
msg.exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ResultsView::HasVisibleResults() const
|
bool ResultsView::HasVisibleResults() const
|
||||||
|
|
|
@ -92,9 +92,15 @@ public:
|
||||||
/**
|
/**
|
||||||
* @brief Inform the view that checking has started
|
* @brief Inform the view that checking has started
|
||||||
*
|
*
|
||||||
* At the moment this only displays the progressbar
|
* @param count Count of files to be checked.
|
||||||
*/
|
*/
|
||||||
void CheckingStarted();
|
void CheckingStarted(int count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Inform the view that checking finished.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void CheckingFinished();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Do we have visible results to show?
|
* @brief Do we have visible results to show?
|
||||||
|
@ -138,9 +144,8 @@ public slots:
|
||||||
* @brief Slot for updating the checking progress
|
* @brief Slot for updating the checking progress
|
||||||
*
|
*
|
||||||
* @param value Current progress value
|
* @param value Current progress value
|
||||||
* @param max Maximum progress value
|
|
||||||
*/
|
*/
|
||||||
void Progress(int value, int max);
|
void Progress(int value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Slot for new error to be displayed
|
* @brief Slot for new error to be displayed
|
||||||
|
|
|
@ -138,8 +138,8 @@ void ThreadHandler::Stop()
|
||||||
void ThreadHandler::Initialize(ResultsView *view)
|
void ThreadHandler::Initialize(ResultsView *view)
|
||||||
{
|
{
|
||||||
|
|
||||||
connect(&mResults, SIGNAL(Progress(int, int)),
|
connect(&mResults, SIGNAL(Progress(int)),
|
||||||
view, SLOT(Progress(int, int)));
|
view, SLOT(Progress(int)));
|
||||||
|
|
||||||
connect(&mResults, SIGNAL(Error(const QString &,
|
connect(&mResults, SIGNAL(Error(const QString &,
|
||||||
const QString &,
|
const QString &,
|
||||||
|
|
|
@ -40,7 +40,7 @@ void ThreadResult::FileChecked(const QString &file)
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
Q_UNUSED(file); //For later use maybe?
|
Q_UNUSED(file); //For later use maybe?
|
||||||
mProgress++;
|
mProgress++;
|
||||||
emit Progress(mProgress, mMaxProgress);
|
emit Progress(mProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
|
void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
|
||||||
|
|
|
@ -81,9 +81,8 @@ signals:
|
||||||
/**
|
/**
|
||||||
* @brief Progress signal
|
* @brief Progress signal
|
||||||
* @param value Current progress
|
* @param value Current progress
|
||||||
* @param max Maximum progress
|
|
||||||
*/
|
*/
|
||||||
void Progress(int value, int max);
|
void Progress(int value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Signal of a new error
|
* @brief Signal of a new error
|
||||||
|
|
Loading…
Reference in New Issue