GUI: More refactoring to use ErrorItem and ErrorLine.
This commit is contained in:
parent
0e9d0e9bde
commit
2f0202d105
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ERRORITEM_H
|
||||
#define ERRORITEM_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
/// @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
|
|
@ -50,6 +50,7 @@ HEADERS += mainwindow.h \
|
|||
applicationdialog.h \
|
||||
aboutdialog.h \
|
||||
common.h \
|
||||
erroritem.h \
|
||||
fileviewdialog.h \
|
||||
projectfile.h \
|
||||
report.h \
|
||||
|
|
14
gui/report.h
14
gui/report.h
|
@ -23,23 +23,11 @@
|
|||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QFile>
|
||||
#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.
|
||||
*/
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <QMessageBox>
|
||||
#include <QFileInfo>
|
||||
#include <QClipboard>
|
||||
#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,
|
||||
QStandardItem *stditem = AddBacktraceFiles(EnsureFileItem(line.file, hide),
|
||||
line,
|
||||
hide,
|
||||
SeverityToIcon(severity));
|
||||
SeverityToIcon(line.severity));
|
||||
|
||||
if (!item)
|
||||
if (!stditem)
|
||||
return;
|
||||
|
||||
//Add user data to that item
|
||||
QMap<QString, QVariant> 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<QString, QVariant> 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<QStandardItem*> 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++)
|
||||
|
|
|
@ -25,11 +25,13 @@
|
|||
#include <QStandardItem>
|
||||
#include <QSettings>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QTextStream>
|
||||
#include "common.h"
|
||||
#include "applicationlist.h"
|
||||
#include <QTextStream>
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue