diff --git a/gui/erroritem.h b/gui/erroritem.h new file mode 100644 index 000000000..a5eb88abb --- /dev/null +++ b/gui/erroritem.h @@ -0,0 +1,56 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamäki and 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 . + */ + +#ifndef ERRORITEM_H +#define ERRORITEM_H + +#include +#include + +/// @addtogroup GUI +/// @{ + +/** +* @brief A class containing error data for one error. +*/ +class ErrorItem +{ +public: + QString file; + QStringList files; + QStringList lines; + QString id; + QString severity; + QString msg; +}; + +/** +* @brief A class containing error data for one shown error line. +*/ +class ErrorLine +{ +public: + QString file; + QString line; + QString id; + QString severity; + QString msg; +}; + +/// @} +#endif // ERRORITEM_H diff --git a/gui/gui.pro b/gui/gui.pro index 0ef54b270..d0c23068c 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -50,6 +50,7 @@ HEADERS += mainwindow.h \ applicationdialog.h \ aboutdialog.h \ common.h \ + erroritem.h \ fileviewdialog.h \ projectfile.h \ report.h \ diff --git a/gui/report.h b/gui/report.h index 386911dd0..83a22e148 100644 --- a/gui/report.h +++ b/gui/report.h @@ -23,23 +23,11 @@ #include #include #include +#include "erroritem.h" /// @addtogroup GUI /// @{ -/** -* @brief A class containing error data. -*/ -class ErrorItem -{ -public: - QStringList files; - QStringList lines; - QString id; - QString severity; - QString msg; -}; - /** * @brief A base class for reports. */ diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index a01785b59..096c6e94c 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -25,6 +25,7 @@ #include #include #include +#include "erroritem.h" #include "resultstree.h" #include "xmlreport.h" @@ -67,28 +68,21 @@ QStandardItem *ResultsTree::CreateItem(const QString &name) return item; } -void ResultsTree::AddErrorItem(const QString &file, - const QString &severity, - const QString &message, - const QStringList &files, - const QVariantList &lines, - const QString &id) +void ResultsTree::AddErrorItem(const ErrorItem &item) { - Q_UNUSED(file); - - if (files.isEmpty()) + if (item.files.isEmpty()) { return; } - QString realfile = StripPath(files[0], false); + QString realfile = StripPath(item.files[0], false); if (realfile.isEmpty()) { realfile = tr("Undefined file"); } - bool hide = !mShowTypes[SeverityToShowType(severity)]; + bool hide = !mShowTypes[SeverityToShowType(item.severity)]; //if there is at least one error that is not hidden, we have a visible error if (!hide) @@ -96,48 +90,49 @@ void ResultsTree::AddErrorItem(const QString &file, mVisibleErrors = true; } + ErrorLine line; + line.file = realfile; + line.id = item.id; + line.line = item.lines[0]; + line.msg = item.msg; + line.severity = item.severity; //Create the base item for the error and ensure it has a proper //file item as a parent - QStandardItem *item = AddBacktraceFiles(EnsureFileItem(files[0], hide), - realfile, - lines[0].toInt(), - severity, - message, - hide, - SeverityToIcon(severity)); + QStandardItem *stditem = AddBacktraceFiles(EnsureFileItem(line.file, hide), + line, + hide, + SeverityToIcon(line.severity)); - if (!item) + if (!stditem) return; //Add user data to that item QMap data; - data["severity"] = SeverityToShowType(severity); - data["message"] = message; - data["file"] = files[0]; - data["line"] = lines[0]; - data["id"] = id; - item->setData(QVariant(data)); + data["severity"] = SeverityToShowType(line.severity); + data["message"] = line.msg; + data["file"] = line.file; + data["line"] = line.line; + data["id"] = line.id; + stditem->setData(QVariant(data)); //Add backtrace files as children - for (int i = 1; i < files.size() && i < lines.size(); i++) + for (int i = 1; i < item.files.size() && i < item.lines.size(); i++) { + line.file = item.files[i]; + line.line = item.lines[i]; QStandardItem *child_item; - - child_item = AddBacktraceFiles(item, - StripPath(files[i], false), - lines[i].toInt(), - severity, - message, + child_item = AddBacktraceFiles(stditem, + line, hide, ":images/go-down.png"); //Add user data to that item QMap child_data; - child_data["severity"] = SeverityToShowType(severity); - child_data["message"] = message; - child_data["file"] = files[i]; - child_data["line"] = lines[i]; - child_data["id"] = id; + child_data["severity"] = SeverityToShowType(line.severity); + child_data["message"] = line.msg; + child_data["file"] = line.file; + child_data["line"] = line.line; + child_data["id"] = line.id; child_item->setData(QVariant(child_data)); } @@ -150,10 +145,7 @@ void ResultsTree::AddErrorItem(const QString &file, } QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent, - const QString &file, - const int line, - const QString &severity, - const QString &message, + const ErrorLine &item, const bool hide, const QString &icon) @@ -164,12 +156,12 @@ QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent, } QList list; - list << CreateItem(file); - list << CreateItem(tr(severity.toLatin1())); - list << CreateItem(QString("%1").arg(line)); + list << CreateItem(item.file); + list << CreateItem(tr(item.severity.toLatin1())); + list << CreateItem(QString("%1").arg(item.line)); //TODO message has parameter names so we'll need changes to the core //cppcheck so we can get proper translations - list << CreateItem(tr(message.toLatin1())); + list << CreateItem(tr(item.msg.toLatin1())); // Check for duplicate rows and don't add them if found for (int i = 0; i < parent->rowCount(); i++) diff --git a/gui/resultstree.h b/gui/resultstree.h index a234d7af0..6f2ae6620 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -25,11 +25,13 @@ #include #include #include +#include #include "common.h" #include "applicationlist.h" -#include class Report; +class ErrorItem; +class ErrorLine; /// @addtogroup GUI /// @{ @@ -50,19 +52,9 @@ public: /** * @brief Add a new item to the tree * - * @param file filename - * @param severity error severity - * @param message error message - * @param files list of files affected by the error - * @param lines list of file line numers affected by the error - * @param id error id + * @param item Error item data */ - void AddErrorItem(const QString &file, - const QString &severity, - const QString &message, - const QStringList &files, - const QVariantList &lines, - const QString &id); + void AddErrorItem(const ErrorItem &item); /** * @brief Clear all errors from the tree @@ -224,19 +216,13 @@ protected: * @brief Add a new error item beneath a file or a backtrace item beneath an error * * @param parent Parent for the item. Either a file item or an error item - * @param file Filename of the error - * @param line Line numer - * @param severity Error severity - * @param message Error message + * @param item Error line data * @param hide Should this be hidden (true) or shown (false) * @param icon Should a default backtrace item icon be added * @return newly created QStandardItem * */ QStandardItem *AddBacktraceFiles(QStandardItem *parent, - const QString &file, - const int line, - const QString &severity, - const QString &message, + const ErrorLine &item, const bool hide, const QString &icon); diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 9c3b14a77..e13f8b6ba 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -74,7 +74,20 @@ void ResultsView::Error(const QString &file, const QString &id) { mErrorsFound = true; - mUI.mTree->AddErrorItem(file, severity, message, files, lines, id); + ErrorItem item; + item.file = file; + item.files = files; + item.id = id; + item.msg = message; + item.severity = severity; + + QVariant line; + foreach(line, lines) + { + item.lines.append(line.toString()); + } + + mUI.mTree->AddErrorItem(item); emit GotResults(); }