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; mSuppressions = suppressions;
} }
void ProjectFile::addSuppression(const Suppressions::Suppression &suppression)
{
mSuppressions.append(suppression);
}
void ProjectFile::setAddons(const QStringList &addons) void ProjectFile::setAddons(const QStringList &addons)
{ {
mAddons = addons; mAddons = addons;
@ -1027,13 +1032,3 @@ QString ProjectFile::getAddonFilePath(QString filesDir, const QString &addon)
return QString(); 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; mActiveProject = this;
} }
/** Suppress warning with Cppcheck-ID */
void suppressCppcheckId(std::size_t cppcheckId);
/** /**
* @brief Read the project file. * @brief Read the project file.
* @param filename Filename (can be also given to constructor). * @param filename Filename (can be also given to constructor).
@ -312,6 +309,9 @@ public:
*/ */
void setSuppressions(const QList<Suppressions::Suppression> &suppressions); void setSuppressions(const QList<Suppressions::Suppression> &suppressions);
/** Add suppression */
void addSuppression(const Suppressions::Suppression &suppression);
/** /**
* @brief Set list of addons. * @brief Set list of addons.
* @param addons List of addons. * @param addons List of addons.

View File

@ -1059,16 +1059,27 @@ void ResultsTree::suppressCppcheckID()
selectedWarnings.insert(item); selectedWarnings.insert(item);
} }
bool changed = false;
ProjectFile *projectFile = ProjectFile::getActiveProject(); ProjectFile *projectFile = ProjectFile::getActiveProject();
for (QStandardItem *item: selectedWarnings) { for (QStandardItem *item: selectedWarnings) {
QStandardItem *fileItem = item->parent(); QStandardItem *fileItem = item->parent();
const QVariantMap data = item->data().toMap(); const QVariantMap data = item->data().toMap();
if (projectFile && data.contains("cppcheckId")) if (projectFile && data.contains("cppcheckId")) {
projectFile->suppressCppcheckId(data["cppcheckId"].toULongLong()); 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()); fileItem->removeRow(item->row());
if (fileItem->rowCount() == 0) if (fileItem->rowCount() == 0)
mModel.removeRow(fileItem->row()); mModel.removeRow(fileItem->row());
} }
if (changed)
projectFile->write();
} }
void ResultsTree::openContainingFolder() void ResultsTree::openContainingFolder()