diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 53f4a5f9ab9..78d56929b48 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -239,6 +239,11 @@ bool ResultsTree::addErrorItem(const ErrorItem& errorItem) if (errorItem.errorPath.isEmpty()) return false; + const QString s = errorItem.toString(); + if (mErrorList.contains(s)) + return false; + mErrorList.append(s); + QSharedPointer errorItemPtr{new ErrorItem(errorItem)}; if (mReportType != ReportType::normal) { @@ -393,6 +398,8 @@ ResultItem *ResultsTree::findFileItem(const QString &name) const void ResultsTree::clear() { + mErrorList.clear(); + mModel->removeRows(0, mModel->rowCount()); if (const ProjectFile *activeProject = ProjectFile::getActiveProject()) { @@ -419,6 +426,7 @@ void ResultsTree::clear(const QString &filename) if (stripped == fileItem->text() || filename == fileItem->errorItem->file0) { mModel->removeRow(i); + mErrorList.removeAll(fileItem->errorItem->toString()); break; } } @@ -436,6 +444,7 @@ void ResultsTree::clearRecheckFile(const QString &filename) storedfile = ((!mCheckPath.isEmpty() && storedfile.startsWith(mCheckPath)) ? storedfile.mid(mCheckPath.length() + 1) : storedfile); if (actualfile == storedfile) { mModel->removeRow(i); + mErrorList.removeAll(fileItem->errorItem->toString()); break; } } diff --git a/gui/resultstree.h b/gui/resultstree.h index 9537d6d929a..87907bc5d95 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -568,6 +568,9 @@ protected slots: QStringList mHiddenMessageId; + // List of existing errors so we can avoid duplicates + QStringList mErrorList; + QItemSelectionModel* mSelectionModel{}; ThreadHandler *mThread{}; diff --git a/gui/test/resultstree/testresultstree.cpp b/gui/test/resultstree/testresultstree.cpp index be09034609f..8208ca0343e 100644 --- a/gui/test/resultstree/testresultstree.cpp +++ b/gui/test/resultstree/testresultstree.cpp @@ -134,6 +134,19 @@ void TestResultsTree::test1() const QCOMPARE(tree.isRowHidden(0,QModelIndex()), false); // Show item } +void TestResultsTree::duplicateResults() const +{ + // #14359 - filter out duplicate warnings + ResultsTree tree(nullptr); + + ErrorItem errorItem; + errorItem.summary = errorItem.message = "test"; + errorItem.severity = Severity::error; + errorItem.errorPath << QErrorPathItem(); + QVERIFY(tree.addErrorItem(errorItem)); + QVERIFY(!tree.addErrorItem(errorItem)); +} + static QErrorPathItem createErrorPathItem(QString file, int line, int column, QString info) { QErrorPathItem ret; ret.file = std::move(file); diff --git a/gui/test/resultstree/testresultstree.h b/gui/test/resultstree/testresultstree.h index 1e743581bac..108ed098eb5 100644 --- a/gui/test/resultstree/testresultstree.h +++ b/gui/test/resultstree/testresultstree.h @@ -23,6 +23,7 @@ class TestResultsTree : public QObject { private slots: void test1() const; + void duplicateResults() const; void multiLineResult() const; void resultsInSameFile() const; void testReportType() const;