Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions gui/erroritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,22 @@ QString ErrorItem::tool() const

QString ErrorItem::toString() const
{
QString str = errorPath.back().file + " - " + errorId + " - ";
const int i = getMainLocIndex();
QString ret = errorPath[i].file + ":" + QString::number(errorPath[i].line) + ":" + QString::number(errorPath[i].column) + ":";
ret += GuiSeverity::toString(severity);
if (inconclusive)
str += "inconclusive ";
str += GuiSeverity::toString(severity) +"\n";
str += summary + "\n";
str += message + "\n";
for (const QErrorPathItem& i : errorPath) {
str += " " + i.file + ": " + QString::number(i.line) + "\n";
ret += ",inconclusive";
ret += ": " + summary + " [" + errorId + "]";
if (errorPath.size() >= 2) {
for (const auto& e: errorPath)
ret += "\n" + e.file + ":" + QString::number(e.line) + ":" + QString::number(e.column) + ":note: " + e.info;
}
return str;
return ret;
}

bool ErrorItem::sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2)
bool ErrorItem::same(const ErrorItem &errorItem1, const ErrorItem &errorItem2)
{
if (errorItem1.hash || errorItem2.hash)
if (errorItem1.hash && errorItem2.hash)
return errorItem1.hash == errorItem2.hash;

// fallback
Expand All @@ -95,3 +96,19 @@ bool ErrorItem::sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2
errorItem1.inconclusive == errorItem2.inconclusive &&
errorItem1.severity == errorItem2.severity;
}

bool ErrorItem::filterMatch(const QString& filter) const
{
if (filter.isEmpty())
return true;
if (summary.contains(filter, Qt::CaseInsensitive) ||
message.contains(filter, Qt::CaseInsensitive) ||
errorId.contains(filter, Qt::CaseInsensitive) ||
classification.contains(filter, Qt::CaseInsensitive))
return true;
return std::any_of(errorPath.cbegin(), errorPath.cend(),
[filter](const auto& e) {
return e.file.contains(filter, Qt::CaseInsensitive) ||
e.info.contains(filter, Qt::CaseInsensitive);
});
}
42 changes: 16 additions & 26 deletions gui/erroritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ class ErrorItem {
QString toString() const;
QString tool() const;

int getMainLocIndex() const {
return isClangResult() ? 0 : errorPath.size() - 1;
}

QString getFile() const {
return errorPath.isEmpty() ? QString() : errorPath[getMainLocIndex()].file;
}

bool isClangResult() const {
return errorId.startsWith("clang");
}

bool filterMatch(const QString& filter) const;

QString file0;
QString errorId;
Severity severity;
Expand All @@ -100,33 +114,9 @@ class ErrorItem {
QString tags;

/**
* Compare "CID"
* Compare Hash and fields
*/
static bool sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2);
static bool same(const ErrorItem &errorItem1, const ErrorItem &errorItem2);
};

// NOLINTNEXTLINE(performance-no-int-to-ptr)
Q_DECLARE_METATYPE(ErrorItem)

/**
* @brief A class containing error data for one shown error line.
*/
class ErrorLine {
public:
QString file;
int line;
QString file0;
QString errorId;
int cwe;
unsigned long long hash;
bool inconclusive;
Severity severity;
QString summary;
QString message;
QString sinceDate;
QString tags;
QString remark;
};

/// @}
#endif // ERRORITEM_H
23 changes: 23 additions & 0 deletions gui/resultitem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2025 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "resultitem.h"

ResultItem::ResultItem(QSharedPointer<ErrorItem> errorItem, Type type, int errorPathIndex)
: errorItem(std::move(errorItem)), mType(type), mErrorPathIndex(errorPathIndex)
{}
49 changes: 49 additions & 0 deletions gui/resultitem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* -*- C++ -*-
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2025 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef RESULTITEM_H
#define RESULTITEM_H

#include "erroritem.h"
#include <QStandardItem>
#include <QSharedPointer>

class ResultItem : public QStandardItem
{
public:
enum class Type: std::uint8_t {file, message, note};

ResultItem(QSharedPointer<ErrorItem> errorItem, Type type, int errorPathIndex);
QSharedPointer<ErrorItem> errorItem;
bool hidden{};

QErrorPathItem getErrorPathItem() const {
if (!errorItem || mErrorPathIndex < 0 || mErrorPathIndex >= errorItem->errorPath.size())
return {};
return errorItem->errorPath[mErrorPathIndex];
}

Type getType() const {
return mType;
}
private:
const Type mType;
const int mErrorPathIndex;
};

#endif // RESULTITEM_H
Loading
Loading