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:
Kimmo Varis 2010-07-04 18:54:41 +03:00
parent acbf5af586
commit 643d400716
6 changed files with 50 additions and 51 deletions

View File

@ -221,7 +221,7 @@ void MainWindow::DoCheckFiles(const QStringList &files)
return;
}
mUI.mResults->CheckingStarted();
mUI.mResults->CheckingStarted(fileNames.count());
mThread->SetFiles(RemoveUnacceptedFiles(fileNames));
QFileInfo inf(fileNames[0]);
@ -386,6 +386,7 @@ QStringList MainWindow::RemoveUnacceptedFiles(const QStringList &list)
void MainWindow::CheckDone()
{
mUI.mResults->CheckingFinished();
EnableCheckButtons(true);
mUI.mActionSettings->setEnabled(true);
if (mUI.mResults->HasResults())

View File

@ -61,48 +61,9 @@ void ResultsView::Clear()
mUI.mProgress->setValue(0);
}
void ResultsView::Progress(int value, int max)
void ResultsView::Progress(int value)
{
mUI.mProgress->setMaximum(max);
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,
@ -194,9 +155,42 @@ void ResultsView::SetCheckDirectory(const QString &dir)
mUI.mTree->SetCheckDirectory(dir);
}
void ResultsView::CheckingStarted()
void ResultsView::CheckingStarted(int count)
{
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

View File

@ -92,9 +92,15 @@ public:
/**
* @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?
@ -138,9 +144,8 @@ public slots:
* @brief Slot for updating the checking progress
*
* @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

View File

@ -138,8 +138,8 @@ void ThreadHandler::Stop()
void ThreadHandler::Initialize(ResultsView *view)
{
connect(&mResults, SIGNAL(Progress(int, int)),
view, SLOT(Progress(int, int)));
connect(&mResults, SIGNAL(Progress(int)),
view, SLOT(Progress(int)));
connect(&mResults, SIGNAL(Error(const QString &,
const QString &,

View File

@ -40,7 +40,7 @@ void ThreadResult::FileChecked(const QString &file)
QMutexLocker locker(&mutex);
Q_UNUSED(file); //For later use maybe?
mProgress++;
emit Progress(mProgress, mMaxProgress);
emit Progress(mProgress);
}
void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)

View File

@ -81,9 +81,8 @@ signals:
/**
* @brief Progress signal
* @param value Current progress
* @param max Maximum progress
*/
void Progress(int value, int max);
void Progress(int value);
/**
* @brief Signal of a new error