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 \
|
applicationdialog.h \
|
||||||
aboutdialog.h \
|
aboutdialog.h \
|
||||||
common.h \
|
common.h \
|
||||||
|
erroritem.h \
|
||||||
fileviewdialog.h \
|
fileviewdialog.h \
|
||||||
projectfile.h \
|
projectfile.h \
|
||||||
report.h \
|
report.h \
|
||||||
|
|
14
gui/report.h
14
gui/report.h
|
@ -23,23 +23,11 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include "erroritem.h"
|
||||||
|
|
||||||
/// @addtogroup GUI
|
/// @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.
|
* @brief A base class for reports.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include "erroritem.h"
|
||||||
#include "resultstree.h"
|
#include "resultstree.h"
|
||||||
#include "xmlreport.h"
|
#include "xmlreport.h"
|
||||||
|
|
||||||
|
@ -67,28 +68,21 @@ QStandardItem *ResultsTree::CreateItem(const QString &name)
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResultsTree::AddErrorItem(const QString &file,
|
void ResultsTree::AddErrorItem(const ErrorItem &item)
|
||||||
const QString &severity,
|
|
||||||
const QString &message,
|
|
||||||
const QStringList &files,
|
|
||||||
const QVariantList &lines,
|
|
||||||
const QString &id)
|
|
||||||
{
|
{
|
||||||
Q_UNUSED(file);
|
if (item.files.isEmpty())
|
||||||
|
|
||||||
if (files.isEmpty())
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString realfile = StripPath(files[0], false);
|
QString realfile = StripPath(item.files[0], false);
|
||||||
|
|
||||||
if (realfile.isEmpty())
|
if (realfile.isEmpty())
|
||||||
{
|
{
|
||||||
realfile = tr("Undefined file");
|
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 there is at least one error that is not hidden, we have a visible error
|
||||||
if (!hide)
|
if (!hide)
|
||||||
|
@ -96,48 +90,49 @@ void ResultsTree::AddErrorItem(const QString &file,
|
||||||
mVisibleErrors = true;
|
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
|
//Create the base item for the error and ensure it has a proper
|
||||||
//file item as a parent
|
//file item as a parent
|
||||||
QStandardItem *item = AddBacktraceFiles(EnsureFileItem(files[0], hide),
|
QStandardItem *stditem = AddBacktraceFiles(EnsureFileItem(line.file, hide),
|
||||||
realfile,
|
line,
|
||||||
lines[0].toInt(),
|
|
||||||
severity,
|
|
||||||
message,
|
|
||||||
hide,
|
hide,
|
||||||
SeverityToIcon(severity));
|
SeverityToIcon(line.severity));
|
||||||
|
|
||||||
if (!item)
|
if (!stditem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Add user data to that item
|
//Add user data to that item
|
||||||
QMap<QString, QVariant> data;
|
QMap<QString, QVariant> data;
|
||||||
data["severity"] = SeverityToShowType(severity);
|
data["severity"] = SeverityToShowType(line.severity);
|
||||||
data["message"] = message;
|
data["message"] = line.msg;
|
||||||
data["file"] = files[0];
|
data["file"] = line.file;
|
||||||
data["line"] = lines[0];
|
data["line"] = line.line;
|
||||||
data["id"] = id;
|
data["id"] = line.id;
|
||||||
item->setData(QVariant(data));
|
stditem->setData(QVariant(data));
|
||||||
|
|
||||||
//Add backtrace files as children
|
//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;
|
QStandardItem *child_item;
|
||||||
|
child_item = AddBacktraceFiles(stditem,
|
||||||
child_item = AddBacktraceFiles(item,
|
line,
|
||||||
StripPath(files[i], false),
|
|
||||||
lines[i].toInt(),
|
|
||||||
severity,
|
|
||||||
message,
|
|
||||||
hide,
|
hide,
|
||||||
":images/go-down.png");
|
":images/go-down.png");
|
||||||
|
|
||||||
//Add user data to that item
|
//Add user data to that item
|
||||||
QMap<QString, QVariant> child_data;
|
QMap<QString, QVariant> child_data;
|
||||||
child_data["severity"] = SeverityToShowType(severity);
|
child_data["severity"] = SeverityToShowType(line.severity);
|
||||||
child_data["message"] = message;
|
child_data["message"] = line.msg;
|
||||||
child_data["file"] = files[i];
|
child_data["file"] = line.file;
|
||||||
child_data["line"] = lines[i];
|
child_data["line"] = line.line;
|
||||||
child_data["id"] = id;
|
child_data["id"] = line.id;
|
||||||
child_item->setData(QVariant(child_data));
|
child_item->setData(QVariant(child_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,10 +145,7 @@ void ResultsTree::AddErrorItem(const QString &file,
|
||||||
}
|
}
|
||||||
|
|
||||||
QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent,
|
QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent,
|
||||||
const QString &file,
|
const ErrorLine &item,
|
||||||
const int line,
|
|
||||||
const QString &severity,
|
|
||||||
const QString &message,
|
|
||||||
const bool hide,
|
const bool hide,
|
||||||
const QString &icon)
|
const QString &icon)
|
||||||
|
|
||||||
|
@ -164,12 +156,12 @@ QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent,
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QStandardItem*> list;
|
QList<QStandardItem*> list;
|
||||||
list << CreateItem(file);
|
list << CreateItem(item.file);
|
||||||
list << CreateItem(tr(severity.toLatin1()));
|
list << CreateItem(tr(item.severity.toLatin1()));
|
||||||
list << CreateItem(QString("%1").arg(line));
|
list << CreateItem(QString("%1").arg(item.line));
|
||||||
//TODO message has parameter names so we'll need changes to the core
|
//TODO message has parameter names so we'll need changes to the core
|
||||||
//cppcheck so we can get proper translations
|
//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
|
// Check for duplicate rows and don't add them if found
|
||||||
for (int i = 0; i < parent->rowCount(); i++)
|
for (int i = 0; i < parent->rowCount(); i++)
|
||||||
|
|
|
@ -25,11 +25,13 @@
|
||||||
#include <QStandardItem>
|
#include <QStandardItem>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
|
#include <QTextStream>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "applicationlist.h"
|
#include "applicationlist.h"
|
||||||
#include <QTextStream>
|
|
||||||
|
|
||||||
class Report;
|
class Report;
|
||||||
|
class ErrorItem;
|
||||||
|
class ErrorLine;
|
||||||
|
|
||||||
/// @addtogroup GUI
|
/// @addtogroup GUI
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -50,19 +52,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* @brief Add a new item to the tree
|
* @brief Add a new item to the tree
|
||||||
*
|
*
|
||||||
* @param file filename
|
* @param item Error item data
|
||||||
* @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
|
|
||||||
*/
|
*/
|
||||||
void AddErrorItem(const QString &file,
|
void AddErrorItem(const ErrorItem &item);
|
||||||
const QString &severity,
|
|
||||||
const QString &message,
|
|
||||||
const QStringList &files,
|
|
||||||
const QVariantList &lines,
|
|
||||||
const QString &id);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Clear all errors from the tree
|
* @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
|
* @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 parent Parent for the item. Either a file item or an error item
|
||||||
* @param file Filename of the error
|
* @param item Error line data
|
||||||
* @param line Line numer
|
|
||||||
* @param severity Error severity
|
|
||||||
* @param message Error message
|
|
||||||
* @param hide Should this be hidden (true) or shown (false)
|
* @param hide Should this be hidden (true) or shown (false)
|
||||||
* @param icon Should a default backtrace item icon be added
|
* @param icon Should a default backtrace item icon be added
|
||||||
* @return newly created QStandardItem *
|
* @return newly created QStandardItem *
|
||||||
*/
|
*/
|
||||||
QStandardItem *AddBacktraceFiles(QStandardItem *parent,
|
QStandardItem *AddBacktraceFiles(QStandardItem *parent,
|
||||||
const QString &file,
|
const ErrorLine &item,
|
||||||
const int line,
|
|
||||||
const QString &severity,
|
|
||||||
const QString &message,
|
|
||||||
const bool hide,
|
const bool hide,
|
||||||
const QString &icon);
|
const QString &icon);
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,20 @@ void ResultsView::Error(const QString &file,
|
||||||
const QString &id)
|
const QString &id)
|
||||||
{
|
{
|
||||||
mErrorsFound = true;
|
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();
|
emit GotResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue