diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index dfebccf74..46e491428 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -371,11 +371,16 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS foreach (const ErrorItem &e, errorItems) { if (e.errorPath.isEmpty()) continue; + if (mSuppressions.contains(e.errorId)) + continue; std::list callstack; foreach (const QErrorPathItem &path, e.errorPath) { callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(path.file.toStdString(), path.info.toStdString(), path.line)); } - ErrorLogger::ErrorMessage errmsg(callstack, file0.toStdString(), errorItem.severity, errorItem.message.toStdString(), errorItem.errorId.toStdString(), false); + const std::string f0 = file0.toStdString(); + const std::string msg = e.message.toStdString(); + const std::string id = e.errorId.toStdString(); + ErrorLogger::ErrorMessage errmsg(callstack, f0, errorItem.severity, msg, id, false); mResult.reportErr(errmsg); } } diff --git a/gui/checkthread.h b/gui/checkthread.h index 5cfa68019..5cc17becf 100644 --- a/gui/checkthread.h +++ b/gui/checkthread.h @@ -68,6 +68,10 @@ public: mClangPath = p; } + void setSuppressions(const QStringList s) { + mSuppressions = s; + } + /** * @brief method that is run in a thread * @@ -127,6 +131,7 @@ private: QString mVsIncludePaths; QString mDataDir; QString mClangPath; + QStringList mSuppressions; }; /// @} #endif // CHECKTHREAD_H diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 9710914e7..e8e835747 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -127,6 +127,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : connect(mUI.mResults, &ResultsView::resultsHidden, mUI.mActionShowHidden, &QAction::setEnabled); connect(mUI.mResults, &ResultsView::checkSelected, this, &MainWindow::performSelectedFilesCheck); connect(mUI.mResults, &ResultsView::tagged, this, &MainWindow::tagged); + connect(mUI.mResults, &ResultsView::suppressIds, this, &MainWindow::suppressIds); connect(mUI.mMenuView, &QMenu::aboutToShow, this, &MainWindow::aboutToShowViewMenu); // File menu @@ -452,6 +453,7 @@ void MainWindow::doAnalyzeProject(ImportProject p) clangPath = "C:/Program Files/LLVM/bin"; } mThread->setClangPath(clangPath); + mThread->setSuppressions(mProjectFile->getSuppressions()); #endif } mThread->setProject(p); @@ -1690,3 +1692,16 @@ void MainWindow::tagged() if (!lastResults.isEmpty()) mUI.mResults->save(lastResults, Report::XMLV2); } + +void MainWindow::suppressIds(QStringList ids) +{ + if (mProjectFile) { + QStringList suppressions = mProjectFile->getSuppressions(); + foreach (QString s, ids) { + if (!suppressions.contains(s)) + suppressions << s; + } + mProjectFile->setSuppressions(suppressions); + mProjectFile->write(); + } +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 82749a1a9..26373e9f4 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -224,6 +224,9 @@ protected slots: /** Some results were tagged */ void tagged(); + /** Suppress error ids */ + void suppressIds(QStringList ids); + private: /** Get filename for last results */ diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 46f27f208..d08cdbdcb 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -602,6 +602,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) QAction *copymessageid = new QAction(tr("Copy message id"), &menu); QAction *hide = new QAction(tr("Hide"), &menu); QAction *hideallid = new QAction(tr("Hide all with id"), &menu); + QAction *suppress = new QAction(tr("Suppress selected id(s)"), &menu); QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu); if (multipleSelection) { @@ -624,6 +625,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) menu.addAction(copymessageid); menu.addAction(hide); menu.addAction(hideallid); + menu.addAction(suppress); menu.addAction(opencontainingfolder); connect(recheckSelectedFiles, SIGNAL(triggered()), this, SLOT(recheckSelectedFiles())); @@ -633,6 +635,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) connect(copymessageid, SIGNAL(triggered()), this, SLOT(copyMessageId())); connect(hide, SIGNAL(triggered()), this, SLOT(hideResult())); connect(hideallid, SIGNAL(triggered()), this, SLOT(hideAllIdResult())); + connect(suppress, SIGNAL(triggered()), this, SLOT(suppressSelectedIds())); connect(opencontainingfolder, SIGNAL(triggered()), this, SLOT(openContainingFolder())); menu.addSeparator(); @@ -936,6 +939,43 @@ void ResultsTree::hideAllIdResult() } } +void ResultsTree::suppressSelectedIds() +{ + if (!mSelectionModel) + return; + + QModelIndexList selectedRows = mSelectionModel->selectedRows(); + QSet selectedIds; + foreach (QModelIndex index, selectedRows) { + QStandardItem *item = mModel.itemFromIndex(index); + if (!item->parent()) + continue; + if (item->parent()->parent()) + item = item->parent(); + QVariantMap data = item->data().toMap(); + if (!data.contains("id")) + continue; + selectedIds << data["id"].toString(); + } + + // delete all errors with selected message Ids + for (int i = 0; i < mModel.rowCount(); i++) { + QStandardItem * const file = mModel.item(i, 0); + for (int j = 0; j < file->rowCount(); ) { + QStandardItem *errorItem = file->child(j, 0); + QVariantMap userdata = errorItem->data().toMap(); + if (selectedIds.contains(userdata["id"].toString())) { + file->removeRow(j); + } else { + j++; + } + } + } + + + emit suppressIds(selectedIds.toList()); +} + void ResultsTree::openContainingFolder() { QString filePath = getFilePath(mContextItem, true); diff --git a/gui/resultstree.h b/gui/resultstree.h index 8c9c6b0bb..f1bf646d7 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -210,6 +210,9 @@ signals: */ void tagged(); + /** Suppress Ids */ + void suppressIds(QStringList ids); + protected slots: /** * @brief Slot to quickstart an error with default application @@ -267,6 +270,9 @@ protected slots: */ void hideAllIdResult(); + /** Slot for context menu item to suppress all messages with the current message id */ + void suppressSelectedIds(); + /** * @brief Slot for context menu item to open the folder containing the current file. */ diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 31e7a8ede..960a0325f 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -52,6 +52,7 @@ ResultsView::ResultsView(QWidget * parent) : connect(mUI.mTree, &ResultsTree::checkSelected, this, &ResultsView::checkSelected); connect(mUI.mTree, &ResultsTree::selectionChanged, this, &ResultsView::updateDetails); connect(mUI.mTree, &ResultsTree::tagged, this, &ResultsView::tagged); + connect(mUI.mTree, &ResultsTree::suppressIds, this, &ResultsView::suppressIds); } void ResultsView::initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler) diff --git a/gui/resultsview.h b/gui/resultsview.h index 51065580d..39902622a 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -218,6 +218,9 @@ signals: */ void tagged(); + /** Suppress Ids */ + void suppressIds(QStringList ids); + public slots: /** diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index de1500bb7..500f1cac0 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -47,6 +47,7 @@ void ThreadHandler::clearFiles() mResults.clearFiles(); mAnalyseWholeProgram = false; mAddons.clear(); + mSuppressions.clear(); } void ThreadHandler::setFiles(const QStringList &files) @@ -93,6 +94,7 @@ void ThreadHandler::check(const Settings &settings) for (int i = 0; i < mRunningThreadCount; i++) { mThreads[i]->setAddons(mAddons); + mThreads[i]->setSuppressions(mSuppressions); mThreads[i]->setVsIncludePaths(mVsIncludePaths); mThreads[i]->setClangPath(mClangPath); mThreads[i]->setDataDir(mDataDir); diff --git a/gui/threadhandler.h b/gui/threadhandler.h index 72e724663..363e2e52a 100644 --- a/gui/threadhandler.h +++ b/gui/threadhandler.h @@ -75,6 +75,10 @@ public: mAddons = addons; } + void setSuppressions(const QStringList &s) { + mSuppressions = s; + } + void setVsIncludePaths(const QString &s) { mVsIncludePaths = s; } @@ -250,6 +254,7 @@ protected: bool mAnalyseWholeProgram; QStringList mAddons; + QStringList mSuppressions; QString mVsIncludePaths; QString mClangPath;