Fixed #7231 (GUI: 'Selected File Recheck' being performed multiple times if file selection includes existing error messages.)

This commit is contained in:
Akhilesh Nema 2015-12-29 01:38:36 +01:00 committed by Daniel Marjamäki
parent b38559774d
commit 997d7dc695
5 changed files with 51 additions and 21 deletions

View File

@ -813,10 +813,16 @@ void MainWindow::ReCheckSelected(QStringList files, bool all)
// Clear details, statistics and progress // Clear details, statistics and progress
mUI.mResults->Clear(false); mUI.mResults->Clear(false);
for (int i = 0; i < files.size(); ++i) for (int i = 0; i < files.size(); ++i)
mUI.mResults->Clear(files[i]); mUI.mResults->ClearRecheckFile(files[i]);
FileList pathList;
pathList.AddPathList(files);
if (mProject)
pathList.AddExcludeList(mProject->GetProjectFile()->GetExcludedPaths());
QStringList fileNames = pathList.GetFileList();
CheckLockDownUI(); // lock UI while checking CheckLockDownUI(); // lock UI while checking
mUI.mResults->CheckingStarted(files.size()); mUI.mResults->CheckingStarted(fileNames.size());
mThread->SetCheckFiles(files); mThread->SetCheckFiles(fileNames);
// Saving last check start time, otherwise unchecked modified files will not be // Saving last check start time, otherwise unchecked modified files will not be
// considered in "Modified Files Check" performed after "Selected Files Check" // considered in "Modified Files Check" performed after "Selected Files Check"

View File

@ -46,6 +46,7 @@
#include "application.h" #include "application.h"
#include "showtypes.h" #include "showtypes.h"
#include "threadhandler.h" #include "threadhandler.h"
#include "path.h"
ResultsTree::ResultsTree(QWidget * parent) : ResultsTree::ResultsTree(QWidget * parent) :
QTreeView(parent), QTreeView(parent),
@ -339,6 +340,21 @@ void ResultsTree::Clear(const QString &filename)
} }
} }
void ResultsTree::ClearRecheckFile(const QString &filename)
{
for (int i = 0; i < mModel.rowCount(); ++i) {
const QStandardItem *item = mModel.item(i, 0);
if (!item)
continue;
QVariantMap data = item->data().toMap();
if (filename == data["file"].toString()) {
mModel.removeRow(i);
break;
}
}
}
void ResultsTree::LoadSettings() void ResultsTree::LoadSettings()
{ {
@ -813,8 +829,16 @@ void ResultsTree::RecheckSelectedFiles()
QStringList selectedItems; QStringList selectedItems;
foreach (QModelIndex index, selectedRows) { foreach (QModelIndex index, selectedRows) {
QStandardItem *item = mModel.itemFromIndex(index); QStandardItem *item = mModel.itemFromIndex(index);
while (item->parent())
item = item->parent();
QVariantMap data = item->data().toMap(); QVariantMap data = item->data().toMap();
selectedItems<<data["file"].toString(); QString currentFile = data["file"].toString();
if (Path::isHeader(currentFile.toStdString())) {
if (!selectedItems.contains(data["file0"].toString()))
selectedItems<<data["file0"].toString();
}
if (!selectedItems.contains(currentFile))
selectedItems<<currentFile;
} }
emit CheckSelected(selectedItems); emit CheckSelected(selectedItems);
} }

View File

@ -70,6 +70,11 @@ public:
*/ */
void Clear(const QString &filename); void Clear(const QString &filename);
/**
* @brief Clear errors of a file selected for recheck
*/
void ClearRecheckFile(const QString &filename);
/** /**
* @brief Function to show/hide certain type of errors * @brief Function to show/hide certain type of errors
* Refreshes the tree. * Refreshes the tree.

View File

@ -42,7 +42,6 @@
ResultsView::ResultsView(QWidget * parent) : ResultsView::ResultsView(QWidget * parent) :
QWidget(parent), QWidget(parent),
mErrorsFound(false),
mShowNoErrorsMessage(true), mShowNoErrorsMessage(true),
mStatistics(new CheckStatistics(this)) mStatistics(new CheckStatistics(this))
{ {
@ -74,7 +73,6 @@ void ResultsView::Clear(bool results)
{ {
if (results) { if (results) {
mUI.mTree->Clear(); mUI.mTree->Clear();
mErrorsFound = false;
} }
mUI.mDetails->setText(""); mUI.mDetails->setText("");
@ -90,13 +88,11 @@ void ResultsView::Clear(bool results)
void ResultsView::Clear(const QString &filename) void ResultsView::Clear(const QString &filename)
{ {
mUI.mTree->Clear(filename); mUI.mTree->Clear(filename);
}
/** void ResultsView::ClearRecheckFile(const QString &filename)
* @todo Optimize this.. It is inefficient to check this every time. {
*/ mUI.mTree->ClearRecheckFile(filename);
// If the results list got empty..
if (!mUI.mTree->HasResults())
mErrorsFound = false;
} }
void ResultsView::Progress(int value, const QString& description) void ResultsView::Progress(int value, const QString& description)
@ -107,7 +103,6 @@ void ResultsView::Progress(int value, const QString& description)
void ResultsView::Error(const ErrorItem &item) void ResultsView::Error(const ErrorItem &item)
{ {
mErrorsFound = true;
if (mUI.mTree->AddErrorItem(item)) { if (mUI.mTree->AddErrorItem(item)) {
emit GotResults(); emit GotResults();
mStatistics->AddItem(ShowTypes::SeverityToShowType(item.severity)); mStatistics->AddItem(ShowTypes::SeverityToShowType(item.severity));
@ -141,7 +136,7 @@ void ResultsView::FilterResults(const QString& filter)
void ResultsView::Save(const QString &filename, Report::Type type) const void ResultsView::Save(const QString &filename, Report::Type type) const
{ {
if (!mErrorsFound) { if (!HasResults()) {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText(tr("No errors found, nothing to save.")); msgBox.setText(tr("No errors found, nothing to save."));
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
@ -205,7 +200,7 @@ void ResultsView::PrintPreview()
void ResultsView::Print(QPrinter* printer) void ResultsView::Print(QPrinter* printer)
{ {
if (!mErrorsFound) { if (!HasResults()) {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText(tr("No errors found, nothing to print.")); msgBox.setText(tr("No errors found, nothing to print."));
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
@ -251,7 +246,7 @@ void ResultsView::CheckingFinished()
//Should we inform user of non visible/not found errors? //Should we inform user of non visible/not found errors?
if (mShowNoErrorsMessage) { if (mShowNoErrorsMessage) {
//Tell user that we found no errors //Tell user that we found no errors
if (!mErrorsFound) { if (!HasResults()) {
QMessageBox msg(QMessageBox::Information, QMessageBox msg(QMessageBox::Information,
tr("Cppcheck"), tr("Cppcheck"),
tr("No errors found."), tr("No errors found."),

View File

@ -68,6 +68,11 @@ public:
*/ */
void Clear(const QString &filename); void Clear(const QString &filename);
/**
* @brief Remove a recheck file from the results.
*/
void ClearRecheckFile(const QString &filename);
/** /**
* @brief Save results to a file * @brief Save results to a file
* *
@ -249,11 +254,6 @@ public slots:
void PrintPreview(); void PrintPreview();
protected: protected:
/**
* @brief Have any errors been found
*/
bool mErrorsFound;
/** /**
* @brief Should we show a "No errors found dialog" every time no errors were found? * @brief Should we show a "No errors found dialog" every time no errors were found?
*/ */