Skip to content

Commit 997d7dc

Browse files
nemaakhileshdanmar
authored andcommitted
Fixed cppcheck-opensource#7231 (GUI: 'Selected File Recheck' being performed multiple times if file selection includes existing error messages.)
1 parent b385597 commit 997d7dc

5 files changed

Lines changed: 51 additions & 21 deletions

File tree

‎gui/mainwindow.cpp‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,16 @@ void MainWindow::ReCheckSelected(QStringList files, bool all)
813813
// Clear details, statistics and progress
814814
mUI.mResults->Clear(false);
815815
for (int i = 0; i < files.size(); ++i)
816-
mUI.mResults->Clear(files[i]);
816+
mUI.mResults->ClearRecheckFile(files[i]);
817+
818+
FileList pathList;
819+
pathList.AddPathList(files);
820+
if (mProject)
821+
pathList.AddExcludeList(mProject->GetProjectFile()->GetExcludedPaths());
822+
QStringList fileNames = pathList.GetFileList();
817823
CheckLockDownUI(); // lock UI while checking
818-
mUI.mResults->CheckingStarted(files.size());
819-
mThread->SetCheckFiles(files);
824+
mUI.mResults->CheckingStarted(fileNames.size());
825+
mThread->SetCheckFiles(fileNames);
820826

821827
// Saving last check start time, otherwise unchecked modified files will not be
822828
// considered in "Modified Files Check" performed after "Selected Files Check"

‎gui/resultstree.cpp‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "application.h"
4747
#include "showtypes.h"
4848
#include "threadhandler.h"
49+
#include "path.h"
4950

5051
ResultsTree::ResultsTree(QWidget * parent) :
5152
QTreeView(parent),
@@ -339,6 +340,21 @@ void ResultsTree::Clear(const QString &filename)
339340
}
340341
}
341342

343+
void ResultsTree::ClearRecheckFile(const QString &filename)
344+
{
345+
for (int i = 0; i < mModel.rowCount(); ++i) {
346+
const QStandardItem *item = mModel.item(i, 0);
347+
if (!item)
348+
continue;
349+
350+
QVariantMap data = item->data().toMap();
351+
if (filename == data["file"].toString()) {
352+
mModel.removeRow(i);
353+
break;
354+
}
355+
}
356+
}
357+
342358

343359
void ResultsTree::LoadSettings()
344360
{
@@ -813,8 +829,16 @@ void ResultsTree::RecheckSelectedFiles()
813829
QStringList selectedItems;
814830
foreach (QModelIndex index, selectedRows) {
815831
QStandardItem *item = mModel.itemFromIndex(index);
832+
while (item->parent())
833+
item = item->parent();
816834
QVariantMap data = item->data().toMap();
817-
selectedItems<<data["file"].toString();
835+
QString currentFile = data["file"].toString();
836+
if (Path::isHeader(currentFile.toStdString())) {
837+
if (!selectedItems.contains(data["file0"].toString()))
838+
selectedItems<<data["file0"].toString();
839+
}
840+
if (!selectedItems.contains(currentFile))
841+
selectedItems<<currentFile;
818842
}
819843
emit CheckSelected(selectedItems);
820844
}

‎gui/resultstree.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ class ResultsTree : public QTreeView {
7070
*/
7171
void Clear(const QString &filename);
7272

73+
/**
74+
* @brief Clear errors of a file selected for recheck
75+
*/
76+
void ClearRecheckFile(const QString &filename);
77+
7378
/**
7479
* @brief Function to show/hide certain type of errors
7580
* Refreshes the tree.

‎gui/resultsview.cpp‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
ResultsView::ResultsView(QWidget * parent) :
4444
QWidget(parent),
45-
mErrorsFound(false),
4645
mShowNoErrorsMessage(true),
4746
mStatistics(new CheckStatistics(this))
4847
{
@@ -74,7 +73,6 @@ void ResultsView::Clear(bool results)
7473
{
7574
if (results) {
7675
mUI.mTree->Clear();
77-
mErrorsFound = false;
7876
}
7977

8078
mUI.mDetails->setText("");
@@ -90,13 +88,11 @@ void ResultsView::Clear(bool results)
9088
void ResultsView::Clear(const QString &filename)
9189
{
9290
mUI.mTree->Clear(filename);
91+
}
9392

94-
/**
95-
* @todo Optimize this.. It is inefficient to check this every time.
96-
*/
97-
// If the results list got empty..
98-
if (!mUI.mTree->HasResults())
99-
mErrorsFound = false;
93+
void ResultsView::ClearRecheckFile(const QString &filename)
94+
{
95+
mUI.mTree->ClearRecheckFile(filename);
10096
}
10197

10298
void ResultsView::Progress(int value, const QString& description)
@@ -107,7 +103,6 @@ void ResultsView::Progress(int value, const QString& description)
107103

108104
void ResultsView::Error(const ErrorItem &item)
109105
{
110-
mErrorsFound = true;
111106
if (mUI.mTree->AddErrorItem(item)) {
112107
emit GotResults();
113108
mStatistics->AddItem(ShowTypes::SeverityToShowType(item.severity));
@@ -141,7 +136,7 @@ void ResultsView::FilterResults(const QString& filter)
141136

142137
void ResultsView::Save(const QString &filename, Report::Type type) const
143138
{
144-
if (!mErrorsFound) {
139+
if (!HasResults()) {
145140
QMessageBox msgBox;
146141
msgBox.setText(tr("No errors found, nothing to save."));
147142
msgBox.setIcon(QMessageBox::Critical);
@@ -205,7 +200,7 @@ void ResultsView::PrintPreview()
205200

206201
void ResultsView::Print(QPrinter* printer)
207202
{
208-
if (!mErrorsFound) {
203+
if (!HasResults()) {
209204
QMessageBox msgBox;
210205
msgBox.setText(tr("No errors found, nothing to print."));
211206
msgBox.setIcon(QMessageBox::Critical);
@@ -251,7 +246,7 @@ void ResultsView::CheckingFinished()
251246
//Should we inform user of non visible/not found errors?
252247
if (mShowNoErrorsMessage) {
253248
//Tell user that we found no errors
254-
if (!mErrorsFound) {
249+
if (!HasResults()) {
255250
QMessageBox msg(QMessageBox::Information,
256251
tr("Cppcheck"),
257252
tr("No errors found."),

‎gui/resultsview.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class ResultsView : public QWidget {
6868
*/
6969
void Clear(const QString &filename);
7070

71+
/**
72+
* @brief Remove a recheck file from the results.
73+
*/
74+
void ClearRecheckFile(const QString &filename);
75+
7176
/**
7277
* @brief Save results to a file
7378
*
@@ -249,11 +254,6 @@ public slots:
249254
void PrintPreview();
250255

251256
protected:
252-
/**
253-
* @brief Have any errors been found
254-
*/
255-
bool mErrorsFound;
256-
257257
/**
258258
* @brief Should we show a "No errors found dialog" every time no errors were found?
259259
*/

0 commit comments

Comments
 (0)