2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2009-05-30 07:48:12 +02:00
|
|
|
* Copyright (C) 2007-2009 Daniel Marjamäki and Cppcheck team.
|
2009-03-01 08:38:21 +01:00
|
|
|
*
|
|
|
|
* 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 "resultstree.h"
|
2009-03-02 20:56:51 +01:00
|
|
|
#include <QDebug>
|
2009-05-23 13:26:04 +02:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QSignalMapper>
|
|
|
|
#include <QProcess>
|
2009-06-03 20:18:22 +02:00
|
|
|
#include <QDir>
|
2009-05-23 13:26:04 +02:00
|
|
|
|
|
|
|
ResultsTree::ResultsTree(QSettings &settings, ApplicationList &list) :
|
|
|
|
mSettings(settings),
|
|
|
|
mApplications(list),
|
2009-06-03 20:18:22 +02:00
|
|
|
mContextItem(0),
|
|
|
|
mCheckPath("")
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
|
|
|
setModel(&mModel);
|
|
|
|
QStringList labels;
|
2009-05-23 13:26:04 +02:00
|
|
|
labels << tr("File") << tr("Severity") << tr("Line") << tr("Message");
|
2009-03-01 08:38:21 +01:00
|
|
|
mModel.setHorizontalHeaderLabels(labels);
|
2009-05-23 17:45:05 +02:00
|
|
|
setExpandsOnDoubleClick(false);
|
2009-06-04 16:46:19 +02:00
|
|
|
setSortingEnabled(true);
|
2009-03-01 08:38:21 +01:00
|
|
|
LoadSettings();
|
2009-05-23 17:45:05 +02:00
|
|
|
connect(this, SIGNAL(doubleClicked(const QModelIndex &)),
|
|
|
|
this, SLOT(QuickStartApplication(const QModelIndex &)));
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultsTree::~ResultsTree()
|
|
|
|
{
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStandardItem *ResultsTree::CreateItem(const QString &name)
|
|
|
|
{
|
|
|
|
QStandardItem *item = new QStandardItem(name);
|
|
|
|
item->setEditable(false);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::AddErrorItem(const QString &file,
|
|
|
|
const QString &severity,
|
2009-03-01 21:44:42 +01:00
|
|
|
const QString &message,
|
|
|
|
const QStringList &files,
|
2009-06-03 20:18:22 +02:00
|
|
|
const QVariantList &lines,
|
|
|
|
const QString &id)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-03-22 13:32:07 +01:00
|
|
|
Q_UNUSED(file);
|
|
|
|
|
|
|
|
if (files.isEmpty())
|
2009-05-23 10:17:27 +02:00
|
|
|
{
|
2009-03-22 13:32:07 +01:00
|
|
|
return;
|
2009-05-23 10:17:27 +02:00
|
|
|
}
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2009-06-03 20:18:22 +02:00
|
|
|
QString realfile = StripPath(files[0], false);
|
2009-03-22 13:32:07 +01:00
|
|
|
|
|
|
|
if (realfile.isEmpty())
|
2009-05-23 10:17:27 +02:00
|
|
|
{
|
2009-03-22 13:32:07 +01:00
|
|
|
realfile = "Undefined file";
|
2009-05-23 10:17:27 +02:00
|
|
|
}
|
|
|
|
|
2009-05-23 10:33:38 +02:00
|
|
|
bool hide = !mShowTypes[SeverityToShowType(severity)];
|
2009-05-23 10:17:27 +02:00
|
|
|
//Create the base item for the error and ensure it has a proper
|
|
|
|
//file item as a parent
|
|
|
|
QStandardItem *item = AddBacktraceFiles(EnsureFileItem(realfile),
|
|
|
|
realfile,
|
|
|
|
lines[0].toInt(),
|
|
|
|
severity,
|
2009-05-23 10:33:38 +02:00
|
|
|
message,
|
2009-05-26 17:21:39 +02:00
|
|
|
hide,
|
|
|
|
SeverityToIcon(severity));
|
2009-05-23 10:17:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
//Add user data to that item
|
|
|
|
QMap<QString, QVariant> data;
|
|
|
|
data["severity"] = SeverityToShowType(severity);
|
|
|
|
data["message"] = message;
|
|
|
|
data["files"] = files;
|
|
|
|
data["lines"] = lines;
|
2009-06-03 20:18:22 +02:00
|
|
|
data["id"] = id;
|
2009-05-23 10:17:27 +02:00
|
|
|
item->setData(QVariant(data));
|
|
|
|
|
|
|
|
//Add backtrace files as children
|
2009-05-23 13:26:04 +02:00
|
|
|
for (int i = 1;i < files.size() && i < lines.size();i++)
|
2009-05-23 10:17:27 +02:00
|
|
|
{
|
2009-05-26 17:21:39 +02:00
|
|
|
AddBacktraceFiles(item,
|
2009-06-03 20:18:22 +02:00
|
|
|
StripPath(files[i], false),
|
2009-05-26 17:23:06 +02:00
|
|
|
lines[i].toInt(),
|
|
|
|
severity,
|
|
|
|
message,
|
|
|
|
hide,
|
2009-06-01 23:06:44 +02:00
|
|
|
":images/go-down.png");
|
2009-05-23 10:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO just hide/show current error and it's file
|
|
|
|
//since this does a lot of unnecessary work
|
2009-05-23 13:26:04 +02:00
|
|
|
if (!hide)
|
|
|
|
{
|
2009-05-23 10:33:38 +02:00
|
|
|
ShowFileItem(realfile);
|
|
|
|
}
|
2009-05-23 10:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent,
|
|
|
|
const QString &file,
|
|
|
|
const int line,
|
|
|
|
const QString &severity,
|
2009-05-23 10:33:38 +02:00
|
|
|
const QString &message,
|
2009-05-26 17:21:39 +02:00
|
|
|
const bool hide,
|
|
|
|
const QString &icon)
|
2009-05-23 10:17:27 +02:00
|
|
|
|
|
|
|
{
|
2009-05-23 13:26:04 +02:00
|
|
|
if (!parent)
|
|
|
|
{
|
2009-05-23 10:33:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-23 10:17:27 +02:00
|
|
|
|
|
|
|
QList<QStandardItem*> list;
|
|
|
|
list << CreateItem(file);
|
|
|
|
list << CreateItem(severity);
|
|
|
|
list << CreateItem(QString("%1").arg(line));
|
|
|
|
list << CreateItem(message);
|
|
|
|
|
2009-05-23 10:33:38 +02:00
|
|
|
QModelIndex index = QModelIndex();
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2009-05-23 10:33:38 +02:00
|
|
|
parent->appendRow(list);
|
2009-05-23 10:17:27 +02:00
|
|
|
|
2009-05-23 13:26:04 +02:00
|
|
|
setRowHidden(parent->rowCount() - 1, parent->index(), hide);
|
2009-05-23 10:17:27 +02:00
|
|
|
|
2009-05-26 17:23:06 +02:00
|
|
|
if (!icon.isEmpty())
|
|
|
|
{
|
2009-05-26 17:21:39 +02:00
|
|
|
list[0]->setIcon(QIcon(icon));
|
|
|
|
}
|
|
|
|
|
2009-05-23 10:17:27 +02:00
|
|
|
//TODO Does this leak memory? Should items from list be deleted?
|
|
|
|
|
|
|
|
return list[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowTypes ResultsTree::VariantToShowType(const QVariant &data)
|
|
|
|
{
|
|
|
|
int value = data.toInt();
|
|
|
|
if (value < SHOW_ALL && value > SHOW_ERRORS)
|
|
|
|
{
|
|
|
|
return SHOW_NONE;
|
|
|
|
}
|
|
|
|
return (ShowTypes)value;
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2009-03-22 18:41:32 +01:00
|
|
|
ShowTypes ResultsTree::SeverityToShowType(const QString & severity)
|
2009-03-22 18:39:44 +01:00
|
|
|
{
|
|
|
|
if (severity == "all")
|
|
|
|
return SHOW_ALL;
|
|
|
|
if (severity == "error")
|
|
|
|
return SHOW_ERRORS;
|
|
|
|
if (severity == "style")
|
|
|
|
return SHOW_STYLE;
|
|
|
|
if (severity == "security")
|
|
|
|
return SHOW_SECURITY;
|
|
|
|
|
|
|
|
return SHOW_NONE;
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QStandardItem *ResultsTree::FindFileItem(const QString &name)
|
|
|
|
{
|
|
|
|
QList<QStandardItem *> list = mModel.findItems(name);
|
|
|
|
if (list.size() > 0)
|
2009-05-23 10:17:27 +02:00
|
|
|
{
|
2009-03-01 08:38:21 +01:00
|
|
|
return list[0];
|
2009-05-23 10:17:27 +02:00
|
|
|
}
|
2009-03-01 08:38:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::Clear()
|
|
|
|
{
|
|
|
|
mModel.removeRows(0, mModel.rowCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::LoadSettings()
|
|
|
|
{
|
|
|
|
for (int i = 0;i < mModel.columnCount();i++)
|
|
|
|
{
|
|
|
|
//mFileTree.columnWidth(i);
|
2009-03-01 21:44:42 +01:00
|
|
|
QString temp = QString(tr("Result column %1 width")).arg(i);
|
2009-03-01 08:38:21 +01:00
|
|
|
setColumnWidth(i, mSettings.value(temp, 800 / mModel.columnCount()).toInt());
|
|
|
|
}
|
2009-06-03 20:18:22 +02:00
|
|
|
|
|
|
|
mSaveFullPath = mSettings.value(tr("Save full path"), false).toBool();
|
|
|
|
mSaveAllErrors = mSettings.value(tr("Save all errors"), false).toBool();
|
|
|
|
mShowFullPath = mSettings.value(tr("Show full path"), false).toBool();
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::SaveSettings()
|
|
|
|
{
|
|
|
|
for (int i = 0;i < mModel.columnCount();i++)
|
|
|
|
{
|
2009-03-01 21:44:42 +01:00
|
|
|
QString temp = QString(tr("Result column %1 width")).arg(i);
|
2009-03-01 08:38:21 +01:00
|
|
|
mSettings.setValue(temp, columnWidth(i));
|
|
|
|
}
|
|
|
|
}
|
2009-03-22 18:39:44 +01:00
|
|
|
|
|
|
|
void ResultsTree::ShowResults(ShowTypes type, bool show)
|
|
|
|
{
|
2009-05-23 10:17:27 +02:00
|
|
|
if (type != SHOW_NONE && mShowTypes[type] != show)
|
2009-03-22 18:39:44 +01:00
|
|
|
{
|
2009-05-23 10:17:27 +02:00
|
|
|
mShowTypes[type] = show;
|
|
|
|
RefreshTree();
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ResultsTree::RefreshTree()
|
|
|
|
{
|
2009-05-23 10:17:27 +02:00
|
|
|
//Get the amount of files in the tree
|
|
|
|
int filecount = mModel.rowCount();
|
|
|
|
|
2009-05-23 13:26:04 +02:00
|
|
|
for (int i = 0;i < filecount;i++)
|
2009-03-22 18:39:44 +01:00
|
|
|
{
|
2009-05-23 10:17:27 +02:00
|
|
|
//Get file i
|
2009-05-23 13:26:04 +02:00
|
|
|
QStandardItem *file = mModel.item(i, 0);
|
2009-05-23 10:17:27 +02:00
|
|
|
if (!file)
|
2009-03-22 18:39:44 +01:00
|
|
|
{
|
2009-05-23 10:17:27 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Get the amount of errors this file contains
|
|
|
|
int errorcount = file->rowCount();
|
|
|
|
|
|
|
|
//By default it shouldn't be visible
|
|
|
|
bool show = false;
|
|
|
|
|
2009-05-23 13:26:04 +02:00
|
|
|
for (int j = 0;j < errorcount;j++)
|
2009-05-23 10:17:27 +02:00
|
|
|
{
|
|
|
|
//Get the error itself
|
2009-05-23 13:26:04 +02:00
|
|
|
QStandardItem *child = file->child(j, 0);
|
2009-05-23 10:17:27 +02:00
|
|
|
if (!child)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Get error's user data
|
|
|
|
QVariant userdata = child->data();
|
|
|
|
//Convert it to QVariantMap
|
|
|
|
QVariantMap data = userdata.toMap();
|
|
|
|
|
|
|
|
//Check if this error should be hidden
|
|
|
|
bool hide = !mShowTypes[VariantToShowType(data["severity"])];
|
|
|
|
|
|
|
|
//Hide/show accordingly
|
2009-05-23 13:26:04 +02:00
|
|
|
setRowHidden(j, file->index(), hide);
|
2009-05-23 10:17:27 +02:00
|
|
|
|
|
|
|
//If it was shown then the file itself has to be shown aswell
|
|
|
|
if (!hide)
|
|
|
|
{
|
|
|
|
show = true;
|
|
|
|
}
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
2009-05-23 10:17:27 +02:00
|
|
|
|
|
|
|
//Show the file if any of it's errors are visible
|
2009-05-23 13:26:04 +02:00
|
|
|
setRowHidden(i, QModelIndex(), !show);
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-23 10:17:27 +02:00
|
|
|
QStandardItem *ResultsTree::EnsureFileItem(const QString &name)
|
2009-03-22 18:39:44 +01:00
|
|
|
{
|
2009-05-23 10:17:27 +02:00
|
|
|
QStandardItem *item = FindFileItem(name);
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2009-05-23 10:17:27 +02:00
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
return item;
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
2009-05-23 10:17:27 +02:00
|
|
|
|
|
|
|
item = CreateItem(name);
|
2009-05-28 10:32:32 +02:00
|
|
|
item->setIcon(QIcon(":images/text-x-generic.png"));
|
2009-05-23 10:17:27 +02:00
|
|
|
|
|
|
|
mModel.appendRow(item);
|
|
|
|
|
|
|
|
return item;
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
|
|
|
|
2009-05-23 10:17:27 +02:00
|
|
|
void ResultsTree::ShowFileItem(const QString &name)
|
|
|
|
{
|
|
|
|
QStandardItem *item = FindFileItem(name);
|
|
|
|
if (item)
|
|
|
|
{
|
2009-05-23 13:26:04 +02:00
|
|
|
setRowHidden(0, mModel.indexFromItem(item), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
|
|
|
|
{
|
|
|
|
QModelIndex index = indexAt(e->pos());
|
|
|
|
if (index.isValid())
|
|
|
|
{
|
|
|
|
mContextItem = mModel.itemFromIndex(index);
|
|
|
|
if (mContextItem && mApplications.GetApplicationCount() > 0 && mContextItem->parent())
|
|
|
|
{
|
|
|
|
|
|
|
|
//Create a new context menu
|
|
|
|
QMenu menu(this);
|
|
|
|
//Store all applications in a list
|
|
|
|
QList<QAction*> actions;
|
|
|
|
|
|
|
|
//Create a signal mapper so we don't have to store data to class
|
|
|
|
//member variables
|
|
|
|
QSignalMapper *signalMapper = new QSignalMapper(this);
|
|
|
|
|
|
|
|
//Go through all applications and add them to the context menu
|
|
|
|
for (int i = 0;i < mApplications.GetApplicationCount();i++)
|
|
|
|
{
|
|
|
|
//Create an action for the application
|
|
|
|
QAction *start = new QAction(mApplications.GetApplicationName(i), &menu);
|
|
|
|
|
|
|
|
//Add it to our list so we can disconnect later on
|
|
|
|
actions << start;
|
|
|
|
|
|
|
|
//Add it to context menu
|
|
|
|
menu.addAction(start);
|
|
|
|
|
|
|
|
//Connect the signal to signal mapper
|
|
|
|
connect(start, SIGNAL(triggered()), signalMapper, SLOT(map()));
|
|
|
|
|
|
|
|
//Add a new mapping
|
|
|
|
signalMapper->setMapping(start, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(signalMapper, SIGNAL(mapped(int)),
|
|
|
|
this, SLOT(Context(int)));
|
|
|
|
|
|
|
|
//Start the menu
|
|
|
|
menu.exec(e->globalPos());
|
|
|
|
|
|
|
|
//Disconnect all signals
|
|
|
|
for (int i = 0;i < actions.size();i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
disconnect(actions[i], SIGNAL(triggered()), signalMapper, SLOT(map()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
disconnect(signalMapper, SIGNAL(mapped(int)),
|
|
|
|
this, SLOT(Context(int)));
|
|
|
|
//And remove the signal mapper
|
|
|
|
delete signalMapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-23 17:45:05 +02:00
|
|
|
void ResultsTree::StartApplication(QStandardItem *target, int application)
|
2009-05-23 13:26:04 +02:00
|
|
|
{
|
2009-05-24 10:53:29 +02:00
|
|
|
if (target && application >= 0 && application < mApplications.GetApplicationCount() && target->parent())
|
2009-05-23 13:26:04 +02:00
|
|
|
{
|
2009-05-23 17:45:05 +02:00
|
|
|
QVariantMap data = target->data().toMap();
|
2009-05-23 13:26:04 +02:00
|
|
|
|
|
|
|
QString program = mApplications.GetApplicationPath(application);
|
|
|
|
|
|
|
|
//TODO Check which line was actually right clicked, now defaults to 0
|
|
|
|
unsigned int index = 0;
|
|
|
|
|
|
|
|
//Replace (file) with filename
|
|
|
|
QStringList files = data["files"].toStringList();
|
|
|
|
if (files.size() > 0)
|
|
|
|
{
|
|
|
|
program.replace("(file)", files[index], Qt::CaseInsensitive);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("Failed to get filename!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariantList lines = data["lines"].toList();
|
|
|
|
if (lines.size() > 0)
|
|
|
|
{
|
|
|
|
program.replace("(line)", QString("%1").arg(lines[index].toInt()), Qt::CaseInsensitive);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("Failed to get filenumber!");
|
|
|
|
}
|
|
|
|
|
|
|
|
program.replace("(message)", data["message"].toString(), Qt::CaseInsensitive);
|
|
|
|
program.replace("(severity)", data["severity"].toString(), Qt::CaseInsensitive);
|
|
|
|
|
2009-05-23 17:45:05 +02:00
|
|
|
QProcess::startDetached(program);
|
2009-05-23 10:17:27 +02:00
|
|
|
}
|
|
|
|
}
|
2009-05-23 17:45:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
void ResultsTree::Context(int application)
|
|
|
|
{
|
|
|
|
StartApplication(mContextItem, application);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::QuickStartApplication(const QModelIndex &index)
|
|
|
|
{
|
|
|
|
StartApplication(mModel.itemFromIndex(index), 0);
|
|
|
|
}
|
2009-05-26 17:21:39 +02:00
|
|
|
|
|
|
|
QString ResultsTree::SeverityToIcon(const QString &severity)
|
|
|
|
{
|
2009-05-26 17:23:06 +02:00
|
|
|
if (severity == "all")
|
2009-06-01 23:06:44 +02:00
|
|
|
return ":images/dialog-warning.png";
|
2009-05-26 17:21:39 +02:00
|
|
|
if (severity == "error")
|
2009-06-01 23:06:44 +02:00
|
|
|
return ":images/dialog-error.png";
|
2009-05-26 17:21:39 +02:00
|
|
|
if (severity == "style")
|
2009-06-01 23:06:44 +02:00
|
|
|
return ":images/dialog-information.png";
|
2009-05-26 17:21:39 +02:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
2009-06-03 20:18:22 +02:00
|
|
|
|
|
|
|
void ResultsTree::SaveResults(QTextStream &out, bool xml)
|
|
|
|
{
|
|
|
|
if (xml)
|
|
|
|
{
|
|
|
|
out << "<?xml version=\"1.0\"?>" << endl << "<results>" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0;i < mModel.rowCount();i++)
|
|
|
|
{
|
|
|
|
QStandardItem *item = mModel.item(i, 0);
|
|
|
|
SaveErrors(out, item, xml);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xml)
|
|
|
|
{
|
|
|
|
out << "</results>" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::SaveErrors(QTextStream &out, QStandardItem *item, bool xml)
|
|
|
|
{
|
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//qDebug() << item->text() << "has" << item->rowCount() << "errors";
|
|
|
|
|
|
|
|
for (int i = 0;i < item->rowCount();i++)
|
|
|
|
{
|
|
|
|
QStandardItem *error = item->child(i, 0);
|
|
|
|
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isRowHidden(i, item->index()) && !mSaveAllErrors)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Get error's user data
|
|
|
|
QVariant userdata = error->data();
|
|
|
|
//Convert it to QVariantMap
|
|
|
|
QVariantMap data = userdata.toMap();
|
|
|
|
|
|
|
|
QString line;
|
|
|
|
QString severity = ShowTypeToString(VariantToShowType(data["severity"]));
|
|
|
|
QString message = data["message"].toString();
|
|
|
|
QString id = data["id"].toString();
|
|
|
|
QStringList files = data["files"].toStringList();
|
|
|
|
QVariantList lines = data["lines"].toList();
|
|
|
|
|
|
|
|
if (files.size() <= 0 || lines.size() <= 0 || lines.size() != files.size())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (xml)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Error example from the core program in xml
|
|
|
|
<error file="gui/test.cpp" line="14" id="mismatchAllocDealloc" severity="error" msg="Mismatching allocation and deallocation: k"/>
|
|
|
|
The callstack seems to be ignored here aswell, instead last item of the stack is used
|
|
|
|
*/
|
|
|
|
line = QString("<error file=\"%1\" line=\"%2\" id=\"%3\" severity=\"%4\" msg=\"%5\"/>").
|
|
|
|
arg(StripPath(files[files.size()-1], true)). //filename
|
|
|
|
arg(lines[lines.size()-1].toInt()). //line
|
|
|
|
arg(id). //ID
|
|
|
|
arg(severity). //severity
|
|
|
|
arg(message); //Message
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Error example from the core program in text
|
|
|
|
[gui/test.cpp:23] -> [gui/test.cpp:14]: (error) Mismatching allocation and deallocation: k
|
|
|
|
*/
|
|
|
|
for (int i = 0;i < lines.size();i++)
|
|
|
|
{
|
|
|
|
line += QString("[%1:%2]").arg(StripPath(files[i], true)).arg(lines[i].toInt());
|
|
|
|
if (i < lines.size() - 1 && lines.size() > 0)
|
|
|
|
{
|
|
|
|
line += " -> ";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == lines.size() - 1)
|
|
|
|
{
|
|
|
|
line += ": ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
line += QString("(%1) %2").arg(severity).arg(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
out << line << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ResultsTree::ShowTypeToString(ShowTypes type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case SHOW_ALL:
|
|
|
|
return "all";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHOW_STYLE:
|
|
|
|
return "style";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHOW_SECURITY:
|
|
|
|
return "security";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHOW_UNUSED:
|
|
|
|
return "unused";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHOW_ERRORS:
|
|
|
|
return "error";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHOW_NONE:
|
|
|
|
return "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::UpdateSettings(bool showFullPath,
|
|
|
|
bool saveFullPath,
|
|
|
|
bool saveAllErrors)
|
|
|
|
{
|
|
|
|
if (mShowFullPath != showFullPath)
|
|
|
|
{
|
|
|
|
mShowFullPath = showFullPath;
|
|
|
|
RefreshFilePaths();
|
|
|
|
}
|
|
|
|
|
|
|
|
mSaveFullPath = saveFullPath;
|
|
|
|
mSaveAllErrors = saveAllErrors;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::SetCheckDirectory(const QString &dir)
|
|
|
|
{
|
|
|
|
mCheckPath = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ResultsTree::StripPath(const QString &path, bool saving)
|
|
|
|
{
|
|
|
|
if ((!saving && mShowFullPath) || (saving && mSaveFullPath))
|
|
|
|
{
|
|
|
|
return QString(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
QDir dir(mCheckPath);
|
|
|
|
return dir.relativeFilePath(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::RefreshFilePaths(QStandardItem *item)
|
|
|
|
{
|
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Mark that this file's path hasn't been updated yet
|
|
|
|
bool updated = false;
|
|
|
|
|
|
|
|
//Loop through all errors within this file
|
|
|
|
for (int i = 0;i < item->rowCount();i++)
|
|
|
|
{
|
|
|
|
//Get error i
|
|
|
|
QStandardItem *error = item->child(i, 0);
|
|
|
|
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Get error's user data
|
|
|
|
QVariant userdata = error->data();
|
|
|
|
//Convert it to QVariantMap
|
|
|
|
QVariantMap data = userdata.toMap();
|
|
|
|
|
|
|
|
//Get list of files
|
|
|
|
QStringList files = data["files"].toStringList();
|
|
|
|
|
|
|
|
//We should always have at least 1 file per error
|
|
|
|
if (files.size() == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Update this error's text
|
|
|
|
error->setText(StripPath(files[0], false));
|
|
|
|
|
|
|
|
//If this error has backtraces make sure the files list has enough filenames
|
|
|
|
if (error->rowCount() <= files.size() - 1)
|
|
|
|
{
|
|
|
|
//Loop through all files within the error
|
|
|
|
for (int j = 0;j < error->rowCount();j++)
|
|
|
|
{
|
|
|
|
//Get file
|
|
|
|
QStandardItem *file = error->child(j, 0);
|
|
|
|
if (!file)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//Update file's path
|
|
|
|
file->setText(StripPath(files[j+1], false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//if the main file hasn't been updated yet, update it now
|
|
|
|
if (!updated)
|
|
|
|
{
|
|
|
|
updated = true;
|
|
|
|
item->setText(error->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::RefreshFilePaths()
|
|
|
|
{
|
|
|
|
qDebug("Refreshing file paths");
|
|
|
|
|
|
|
|
//Go through all file items (these are parent items that contain the errors)
|
|
|
|
for (int i = 0;i < mModel.rowCount();i++)
|
|
|
|
{
|
|
|
|
RefreshFilePaths(mModel.item(i, 0));
|
|
|
|
}
|
|
|
|
}
|