From 997d7dc6955ce83a9bbf9def86e28331bac676fe Mon Sep 17 00:00:00 2001 From: Akhilesh Nema Date: Tue, 29 Dec 2015 01:38:36 +0100 Subject: [PATCH] Fixed #7231 (GUI: 'Selected File Recheck' being performed multiple times if file selection includes existing error messages.) --- gui/mainwindow.cpp | 12 +++++++++--- gui/resultstree.cpp | 26 +++++++++++++++++++++++++- gui/resultstree.h | 5 +++++ gui/resultsview.cpp | 19 +++++++------------ gui/resultsview.h | 10 +++++----- 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 3b67efabb..8b8a16d47 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -813,10 +813,16 @@ void MainWindow::ReCheckSelected(QStringList files, bool all) // Clear details, statistics and progress mUI.mResults->Clear(false); 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 - mUI.mResults->CheckingStarted(files.size()); - mThread->SetCheckFiles(files); + mUI.mResults->CheckingStarted(fileNames.size()); + mThread->SetCheckFiles(fileNames); // Saving last check start time, otherwise unchecked modified files will not be // considered in "Modified Files Check" performed after "Selected Files Check" diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 632cb7795..1fa5a2088 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -46,6 +46,7 @@ #include "application.h" #include "showtypes.h" #include "threadhandler.h" +#include "path.h" ResultsTree::ResultsTree(QWidget * 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() { @@ -813,8 +829,16 @@ void ResultsTree::RecheckSelectedFiles() QStringList selectedItems; foreach (QModelIndex index, selectedRows) { QStandardItem *item = mModel.itemFromIndex(index); + while (item->parent()) + item = item->parent(); QVariantMap data = item->data().toMap(); - selectedItems<Clear(); - mErrorsFound = false; } mUI.mDetails->setText(""); @@ -90,13 +88,11 @@ void ResultsView::Clear(bool results) void ResultsView::Clear(const QString &filename) { mUI.mTree->Clear(filename); +} - /** - * @todo Optimize this.. It is inefficient to check this every time. - */ - // If the results list got empty.. - if (!mUI.mTree->HasResults()) - mErrorsFound = false; +void ResultsView::ClearRecheckFile(const QString &filename) +{ + mUI.mTree->ClearRecheckFile(filename); } 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) { - mErrorsFound = true; if (mUI.mTree->AddErrorItem(item)) { emit GotResults(); 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 { - if (!mErrorsFound) { + if (!HasResults()) { QMessageBox msgBox; msgBox.setText(tr("No errors found, nothing to save.")); msgBox.setIcon(QMessageBox::Critical); @@ -205,7 +200,7 @@ void ResultsView::PrintPreview() void ResultsView::Print(QPrinter* printer) { - if (!mErrorsFound) { + if (!HasResults()) { QMessageBox msgBox; msgBox.setText(tr("No errors found, nothing to print.")); msgBox.setIcon(QMessageBox::Critical); @@ -251,7 +246,7 @@ void ResultsView::CheckingFinished() //Should we inform user of non visible/not found errors? if (mShowNoErrorsMessage) { //Tell user that we found no errors - if (!mErrorsFound) { + if (!HasResults()) { QMessageBox msg(QMessageBox::Information, tr("Cppcheck"), tr("No errors found."), diff --git a/gui/resultsview.h b/gui/resultsview.h index f715f3568..085fd5d09 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -68,6 +68,11 @@ public: */ void Clear(const QString &filename); + /** + * @brief Remove a recheck file from the results. + */ + void ClearRecheckFile(const QString &filename); + /** * @brief Save results to a file * @@ -249,11 +254,6 @@ public slots: void PrintPreview(); protected: - /** - * @brief Have any errors been found - */ - bool mErrorsFound; - /** * @brief Should we show a "No errors found dialog" every time no errors were found? */