GUI: Adding suppression with cppcheckId; include all relevant fields

This commit is contained in:
Daniel Marjamäki 2020-07-16 16:36:55 +02:00
parent 9edbec8594
commit bec78a0960
3 changed files with 21 additions and 15 deletions

View File

@ -719,6 +719,11 @@ void ProjectFile::setSuppressions(const QList<Suppressions::Suppression> &suppre
mSuppressions = suppressions;
}
void ProjectFile::addSuppression(const Suppressions::Suppression &suppression)
{
mSuppressions.append(suppression);
}
void ProjectFile::setAddons(const QStringList &addons)
{
mAddons = addons;
@ -1027,13 +1032,3 @@ QString ProjectFile::getAddonFilePath(QString filesDir, const QString &addon)
return QString();
}
void ProjectFile::suppressCppcheckId(std::size_t cppcheckId)
{
if (cppcheckId > 0) {
Suppressions::Suppression s;
s.cppcheckId = cppcheckId;
mSuppressions.append(s);
write();
}
}

View File

@ -55,9 +55,6 @@ public:
mActiveProject = this;
}
/** Suppress warning with Cppcheck-ID */
void suppressCppcheckId(std::size_t cppcheckId);
/**
* @brief Read the project file.
* @param filename Filename (can be also given to constructor).
@ -312,6 +309,9 @@ public:
*/
void setSuppressions(const QList<Suppressions::Suppression> &suppressions);
/** Add suppression */
void addSuppression(const Suppressions::Suppression &suppression);
/**
* @brief Set list of addons.
* @param addons List of addons.

View File

@ -1059,16 +1059,27 @@ void ResultsTree::suppressCppcheckID()
selectedWarnings.insert(item);
}
bool changed = false;
ProjectFile *projectFile = ProjectFile::getActiveProject();
for (QStandardItem *item: selectedWarnings) {
QStandardItem *fileItem = item->parent();
const QVariantMap data = item->data().toMap();
if (projectFile && data.contains("cppcheckId"))
projectFile->suppressCppcheckId(data["cppcheckId"].toULongLong());
if (projectFile && data.contains("cppcheckId")) {
Suppressions::Suppression suppression;
suppression.cppcheckId = data["cppcheckId"].toULongLong();
suppression.errorId = data["id"].toString().toStdString();
suppression.fileName = data["file"].toString().toStdString();
suppression.lineNumber = data["line"].toInt();
projectFile->addSuppression(suppression);
changed = true;
}
fileItem->removeRow(item->row());
if (fileItem->rowCount() == 0)
mModel.removeRow(fileItem->row());
}
if (changed)
projectFile->write();
}
void ResultsTree::openContainingFolder()