2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2013-01-01 17:29:08 +01:00
|
|
|
* Copyright (C) 2007-2013 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
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-03-01 08:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2009-06-14 14:09:52 +02:00
|
|
|
#include <QApplication>
|
2010-10-31 12:16:55 +01:00
|
|
|
#include <QWidget>
|
|
|
|
#include <QStandardItem>
|
2009-03-02 20:56:51 +01:00
|
|
|
#include <QDebug>
|
2010-10-31 12:16:55 +01:00
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QList>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QVariant>
|
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-06-09 08:30:28 +02:00
|
|
|
#include <QMessageBox>
|
2010-10-31 12:16:55 +01:00
|
|
|
#include <QAction>
|
2009-06-14 14:09:52 +02:00
|
|
|
#include <QFileInfo>
|
2010-07-11 13:22:55 +02:00
|
|
|
#include <QFileDialog>
|
2009-06-14 14:09:52 +02:00
|
|
|
#include <QClipboard>
|
2010-10-31 12:16:55 +01:00
|
|
|
#include <QContextMenuEvent>
|
2010-11-23 21:37:31 +01:00
|
|
|
#include <QModelIndex>
|
2012-10-07 12:25:34 +02:00
|
|
|
#include "common.h"
|
2010-07-10 19:30:31 +02:00
|
|
|
#include "erroritem.h"
|
2010-10-31 12:16:55 +01:00
|
|
|
#include "applicationlist.h"
|
2009-06-24 09:54:56 +02:00
|
|
|
#include "resultstree.h"
|
2010-10-31 12:16:55 +01:00
|
|
|
#include "report.h"
|
2011-04-02 15:11:01 +02:00
|
|
|
#include "application.h"
|
2011-10-11 21:14:15 +02:00
|
|
|
#include "showtypes.h"
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
ResultsTree::ResultsTree(QWidget * parent) :
|
2010-04-15 20:08:51 +02:00
|
|
|
QTreeView(parent),
|
|
|
|
mContextItem(0),
|
2012-10-27 11:16:52 +02:00
|
|
|
mShowErrorId(false),
|
2012-10-27 12:10:32 +02:00
|
|
|
mVisibleErrors(false),
|
2010-11-28 22:26:53 +01:00
|
|
|
mSelectionModel(0)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
|
|
|
setModel(&mModel);
|
2012-10-27 11:16:52 +02:00
|
|
|
Translate(); // Adds columns to grid
|
2009-05-23 17:45:05 +02:00
|
|
|
setExpandsOnDoubleClick(false);
|
2009-06-04 16:46:19 +02:00
|
|
|
setSortingEnabled(true);
|
2009-07-02 10:32:29 +02:00
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
void ResultsTree::Initialize(QSettings *settings, ApplicationList *list)
|
|
|
|
{
|
|
|
|
mSettings = settings;
|
|
|
|
mApplications = list;
|
|
|
|
LoadSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-19 21:54:40 +01:00
|
|
|
QStandardItem *ResultsTree::CreateNormalItem(const QString &name)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
|
|
|
QStandardItem *item = new QStandardItem(name);
|
2010-11-19 21:54:40 +01:00
|
|
|
item->setData(name, Qt::ToolTipRole);
|
2009-03-01 08:38:21 +01:00
|
|
|
item->setEditable(false);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2010-11-19 22:11:40 +01:00
|
|
|
QStandardItem *ResultsTree::CreateLineNumberItem(const QString &linenumber)
|
|
|
|
{
|
2011-02-11 20:03:39 +01:00
|
|
|
QStandardItem *item = new QStandardItem();
|
|
|
|
item->setData(QVariant(linenumber.toULongLong()), Qt::DisplayRole);
|
|
|
|
item->setToolTip(linenumber);
|
2010-11-19 22:11:40 +01:00
|
|
|
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
item->setEditable(false);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2010-07-10 19:30:31 +02:00
|
|
|
void ResultsTree::AddErrorItem(const ErrorItem &item)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if (item.files.isEmpty()) {
|
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
|
|
|
|
2010-07-10 19:30:31 +02:00
|
|
|
QString realfile = StripPath(item.files[0], false);
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (realfile.isEmpty()) {
|
2009-07-02 12:48:32 +02:00
|
|
|
realfile = tr("Undefined file");
|
2009-05-23 10:17:27 +02:00
|
|
|
}
|
|
|
|
|
2011-10-11 21:14:15 +02:00
|
|
|
bool hide = !mShowSeverities.isShown(item.severity);
|
|
|
|
//bool hide = !mShowTypes[SeverityToShowType(item.severity)];
|
2009-06-09 09:51:27 +02:00
|
|
|
|
2011-05-04 07:30:54 +02:00
|
|
|
//If specified, filter on summary, message, filename, and id
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!hide && !mFilter.isEmpty()) {
|
2011-05-04 07:30:54 +02:00
|
|
|
if (!item.summary.contains(mFilter, Qt::CaseInsensitive) &&
|
|
|
|
!item.message.contains(mFilter, Qt::CaseInsensitive) &&
|
|
|
|
!item.file.contains(mFilter, Qt::CaseInsensitive) &&
|
2011-10-13 20:53:06 +02:00
|
|
|
!item.errorId.contains(mFilter, Qt::CaseInsensitive)) {
|
2011-05-04 07:30:54 +02:00
|
|
|
hide = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-19 23:43:46 +01:00
|
|
|
//if there is at least one error that is not hidden, we have a visible error
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!hide) {
|
2009-06-09 09:51:27 +02:00
|
|
|
mVisibleErrors = true;
|
|
|
|
}
|
|
|
|
|
2010-07-10 19:30:31 +02:00
|
|
|
ErrorLine line;
|
|
|
|
line.file = realfile;
|
2011-10-12 21:18:54 +02:00
|
|
|
line.errorId = item.errorId;
|
2011-04-16 13:04:20 +02:00
|
|
|
line.inconclusive = item.inconclusive;
|
2010-07-12 00:51:36 +02:00
|
|
|
line.line = item.lines[0];
|
2010-11-11 22:15:06 +01:00
|
|
|
line.summary = item.summary;
|
2010-11-11 21:51:00 +01:00
|
|
|
line.message = item.message;
|
2011-03-07 20:20:09 +01:00
|
|
|
line.severity = item.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
|
2012-02-14 21:16:11 +01:00
|
|
|
QStandardItem *stditem = AddBacktraceFiles(EnsureFileItem(line.file, item.file0, hide),
|
2010-07-10 19:30:31 +02:00
|
|
|
line,
|
|
|
|
hide,
|
2011-03-07 22:11:59 +01:00
|
|
|
SeverityToIcon(line.severity));
|
2010-07-10 19:30:31 +02:00
|
|
|
|
|
|
|
if (!stditem)
|
2009-11-16 17:09:30 +01:00
|
|
|
return;
|
|
|
|
|
2009-05-23 10:17:27 +02:00
|
|
|
//Add user data to that item
|
|
|
|
QMap<QString, QVariant> data;
|
2010-11-21 19:55:34 +01:00
|
|
|
data["hide"] = false;
|
2011-10-11 21:14:15 +02:00
|
|
|
data["severity"] = ShowTypes::SeverityToShowType(item.severity);
|
2010-11-11 22:15:06 +01:00
|
|
|
data["summary"] = item.summary;
|
2010-11-11 21:51:00 +01:00
|
|
|
data["message"] = item.message;
|
2010-07-11 00:07:40 +02:00
|
|
|
data["file"] = item.files[0];
|
2010-07-12 00:51:36 +02:00
|
|
|
data["line"] = item.lines[0];
|
2011-10-12 21:18:54 +02:00
|
|
|
data["id"] = item.errorId;
|
2011-04-16 13:04:20 +02:00
|
|
|
data["inconclusive"] = item.inconclusive;
|
2012-02-14 21:16:11 +01:00
|
|
|
data["file0"] = item.file0;
|
2010-07-10 19:30:31 +02:00
|
|
|
stditem->setData(QVariant(data));
|
2009-05-23 10:17:27 +02:00
|
|
|
|
|
|
|
//Add backtrace files as children
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 1; i < item.files.size(); i++) {
|
2010-07-11 00:07:40 +02:00
|
|
|
line.file = StripPath(item.files[i], false);
|
2010-07-10 19:30:31 +02:00
|
|
|
line.line = item.lines[i];
|
2009-11-19 23:43:46 +01:00
|
|
|
QStandardItem *child_item;
|
2010-07-10 19:30:31 +02:00
|
|
|
child_item = AddBacktraceFiles(stditem,
|
|
|
|
line,
|
2009-11-19 23:43:46 +01:00
|
|
|
hide,
|
|
|
|
":images/go-down.png");
|
|
|
|
|
|
|
|
//Add user data to that item
|
|
|
|
QMap<QString, QVariant> child_data;
|
2011-10-11 21:14:15 +02:00
|
|
|
child_data["severity"] = ShowTypes::SeverityToShowType(line.severity);
|
2010-11-11 22:15:06 +01:00
|
|
|
child_data["summary"] = line.summary;
|
2010-11-11 21:51:00 +01:00
|
|
|
child_data["message"] = line.message;
|
2010-07-11 00:07:40 +02:00
|
|
|
child_data["file"] = item.files[i];
|
2010-07-10 19:30:31 +02:00
|
|
|
child_data["line"] = line.line;
|
2011-10-12 21:18:54 +02:00
|
|
|
child_data["id"] = line.errorId;
|
2011-04-16 13:04:20 +02:00
|
|
|
child_data["inconclusive"] = line.inconclusive;
|
2009-11-19 23:43:46 +01:00
|
|
|
child_item->setData(QVariant(child_data));
|
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
|
2011-10-13 20:53:06 +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,
|
2010-07-10 19:30:31 +02:00
|
|
|
const ErrorLine &item,
|
2009-05-26 17:21:39 +02:00
|
|
|
const bool hide,
|
|
|
|
const QString &icon)
|
2009-05-23 10:17:27 +02:00
|
|
|
|
|
|
|
{
|
2011-10-13 20:53:06 +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;
|
2010-07-17 19:20:49 +02:00
|
|
|
// Ensure shown path is with native separators
|
|
|
|
const QString file = QDir::toNativeSeparators(item.file);
|
2010-11-19 21:54:40 +01:00
|
|
|
list << CreateNormalItem(file);
|
2012-10-21 11:37:23 +02:00
|
|
|
const QString severity = SeverityToTranslatedString(item.severity);
|
|
|
|
list << CreateNormalItem(severity);
|
2010-11-19 22:11:40 +01:00
|
|
|
list << CreateLineNumberItem(QString("%1").arg(item.line));
|
2012-10-27 11:16:52 +02:00
|
|
|
list << CreateNormalItem(item.errorId);
|
2009-07-02 12:48:32 +02:00
|
|
|
//TODO message has parameter names so we'll need changes to the core
|
|
|
|
//cppcheck so we can get proper translations
|
2011-04-16 13:04:20 +02:00
|
|
|
QString summary;
|
2011-10-13 20:53:06 +02:00
|
|
|
if (item.inconclusive) {
|
2011-04-16 13:04:20 +02:00
|
|
|
summary = tr("[Inconclusive]");
|
|
|
|
summary += " ";
|
|
|
|
}
|
|
|
|
summary += item.summary.toLatin1();
|
|
|
|
list << CreateNormalItem(summary);
|
2009-05-23 10:17:27 +02:00
|
|
|
|
2009-11-16 17:09:30 +01:00
|
|
|
// Check for duplicate rows and don't add them if found
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 0; i < parent->rowCount(); i++) {
|
2012-12-07 12:54:28 +01:00
|
|
|
// The first column is the file name and is always the same
|
2009-11-16 17:09:30 +01:00
|
|
|
|
|
|
|
// the third column is the line number so check it first
|
2011-10-13 20:53:06 +02:00
|
|
|
if (parent->child(i, 2)->text() == list[2]->text()) {
|
2009-11-16 17:09:30 +01:00
|
|
|
// the second column is the severity so check it next
|
2011-10-13 20:53:06 +02:00
|
|
|
if (parent->child(i, 1)->text() == list[1]->text()) {
|
2010-11-11 22:15:06 +01:00
|
|
|
// the fourth column is the summary so check it last
|
2012-12-07 13:35:14 +01:00
|
|
|
if (parent->child(i, 4)->text() == list[4]->text()) {
|
2010-11-22 22:32:04 +01:00
|
|
|
// this row matches so don't add it
|
|
|
|
return 0;
|
2009-11-16 17:09:30 +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
|
|
|
|
2011-10-13 20:53: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];
|
|
|
|
}
|
|
|
|
|
2011-03-07 22:35:58 +01:00
|
|
|
QString ResultsTree::SeverityToTranslatedString(Severity::SeverityType severity)
|
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (severity) {
|
2011-03-07 22:35:58 +01:00
|
|
|
case Severity::style:
|
|
|
|
return tr("style");
|
|
|
|
|
|
|
|
case Severity::error:
|
|
|
|
return tr("error");
|
|
|
|
|
|
|
|
case Severity::warning:
|
|
|
|
return tr("warning");
|
|
|
|
|
|
|
|
case Severity::performance:
|
|
|
|
return tr("performance");
|
|
|
|
|
|
|
|
case Severity::portability:
|
|
|
|
return tr("portability");
|
|
|
|
|
|
|
|
case Severity::information:
|
|
|
|
return tr("information");
|
|
|
|
|
|
|
|
case Severity::debug:
|
|
|
|
return tr("debug");
|
|
|
|
|
|
|
|
case Severity::none:
|
2012-10-21 11:37:23 +02:00
|
|
|
default:
|
2011-03-07 22:35:58 +01:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-27 12:10:32 +02:00
|
|
|
QStandardItem *ResultsTree::FindFileItem(const QString &name) const
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2012-12-07 12:54:28 +01:00
|
|
|
// The first column contains the file name. In Windows we can get filenames
|
|
|
|
// "header.h" and "Header.h" and must compare them as identical.
|
|
|
|
|
|
|
|
for (int i = 0; i < mModel.rowCount(); i++) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (QString::compare(mModel.item(i, 0)->text(), name, Qt::CaseInsensitive) == 0)
|
|
|
|
#else
|
|
|
|
if (mModel.item(i, 0)->text() == name)
|
|
|
|
#endif
|
|
|
|
return mModel.item(i, 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());
|
|
|
|
}
|
|
|
|
|
2012-02-14 21:16:11 +01:00
|
|
|
void ResultsTree::Clear(const QString &filename)
|
|
|
|
{
|
|
|
|
const QString stripped = StripPath(filename, false);
|
|
|
|
|
|
|
|
for (int i = 0; i < mModel.rowCount(); ++i) {
|
|
|
|
const QStandardItem *item = mModel.item(i, 0);
|
|
|
|
if (!item)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QVariantMap data = item->data().toMap();
|
|
|
|
if (stripped == data["file"].toString() ||
|
|
|
|
filename == data["file0"].toString()) {
|
|
|
|
mModel.removeRow(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
void ResultsTree::LoadSettings()
|
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 0; i < mModel.columnCount(); i++) {
|
2009-07-02 10:32:29 +02:00
|
|
|
QString temp = QString(SETTINGS_RESULT_COLUMN_WIDTH).arg(i);
|
2012-10-27 11:16:52 +02:00
|
|
|
setColumnWidth(i, qMax(20, mSettings->value(temp, 800 / mModel.columnCount()).toInt()));
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mSaveFullPath = mSettings->value(SETTINGS_SAVE_FULL_PATH, false).toBool();
|
|
|
|
mSaveAllErrors = mSettings->value(SETTINGS_SAVE_ALL_ERRORS, false).toBool();
|
|
|
|
mShowFullPath = mSettings->value(SETTINGS_SHOW_FULL_PATH, false).toBool();
|
2012-10-27 11:16:52 +02:00
|
|
|
|
|
|
|
ShowIdColumn(mSettings->value(SETTINGS_SHOW_ERROR_ID, false).toBool());
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2012-10-27 12:10:32 +02:00
|
|
|
void ResultsTree::SaveSettings() const
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 0; i < mModel.columnCount(); i++) {
|
2009-07-02 10:32:29 +02:00
|
|
|
QString temp = QString(SETTINGS_RESULT_COLUMN_WIDTH).arg(i);
|
|
|
|
mSettings->setValue(temp, columnWidth(i));
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
}
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2011-10-11 21:14:15 +02:00
|
|
|
void ResultsTree::ShowResults(ShowTypes::ShowType type, bool show)
|
2009-03-22 18:39:44 +01:00
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if (type != ShowTypes::ShowNone && mShowSeverities.isShown(type) != show) {
|
2011-10-11 21:14:15 +02:00
|
|
|
mShowSeverities.show(type, show);
|
2009-05-23 10:17:27 +02:00
|
|
|
RefreshTree();
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-04 07:30:54 +02:00
|
|
|
void ResultsTree::FilterResults(const QString& filter)
|
|
|
|
{
|
|
|
|
mFilter = filter;
|
|
|
|
RefreshTree();
|
|
|
|
}
|
|
|
|
|
2010-11-21 19:55:34 +01:00
|
|
|
void ResultsTree::ShowHiddenResults()
|
|
|
|
{
|
|
|
|
//Clear the "hide" flag for each item
|
|
|
|
int filecount = mModel.rowCount();
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 0; i < filecount; i++) {
|
2010-11-21 19:55:34 +01:00
|
|
|
QStandardItem *file = mModel.item(i, 0);
|
|
|
|
if (!file)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QVariantMap data = file->data().toMap();
|
|
|
|
data["hide"] = false;
|
|
|
|
file->setData(QVariant(data));
|
|
|
|
|
|
|
|
int errorcount = file->rowCount();
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int j = 0; j < errorcount; j++) {
|
2010-11-21 19:55:34 +01:00
|
|
|
QStandardItem *child = file->child(j, 0);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (child) {
|
2010-11-21 19:55:34 +01:00
|
|
|
data = child->data().toMap();
|
|
|
|
data["hide"] = false;
|
|
|
|
child->setData(QVariant(data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RefreshTree();
|
2010-11-24 09:48:07 +01:00
|
|
|
emit ResultsHidden(false);
|
2010-11-21 19:55:34 +01:00
|
|
|
}
|
|
|
|
|
2009-03-22 18:39:44 +01:00
|
|
|
|
|
|
|
void ResultsTree::RefreshTree()
|
|
|
|
{
|
2009-06-09 09:51:27 +02:00
|
|
|
mVisibleErrors = false;
|
2009-05-23 10:17:27 +02:00
|
|
|
//Get the amount of files in the tree
|
|
|
|
int filecount = mModel.rowCount();
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 0; i < filecount; i++) {
|
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);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!file) {
|
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;
|
|
|
|
|
2011-10-13 20:53:06 +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);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!child) {
|
2009-05-23 10:17:27 +02:00
|
|
|
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
|
2011-10-11 21:14:15 +02:00
|
|
|
bool hide = (data["hide"].toBool() || !mShowSeverities.isShown(ShowTypes::VariantToShowType(data["severity"])));
|
2009-05-23 10:17:27 +02:00
|
|
|
|
2011-05-04 07:30:54 +02:00
|
|
|
//If specified, filter on summary, message, filename, and id
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!hide && !mFilter.isEmpty()) {
|
2011-05-04 07:30:54 +02:00
|
|
|
if (!data["summary"].toString().contains(mFilter, Qt::CaseInsensitive) &&
|
|
|
|
!data["message"].toString().contains(mFilter, Qt::CaseInsensitive) &&
|
|
|
|
!data["file"].toString().contains(mFilter, Qt::CaseInsensitive) &&
|
2011-10-13 20:53:06 +02:00
|
|
|
!data["id"].toString().contains(mFilter, Qt::CaseInsensitive)) {
|
2011-05-04 07:30:54 +02:00
|
|
|
hide = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!hide) {
|
2009-06-09 09:51:27 +02:00
|
|
|
mVisibleErrors = true;
|
|
|
|
}
|
|
|
|
|
2009-05-23 10:17:27 +02:00
|
|
|
//Hide/show accordingly
|
2009-05-23 13:26:04 +02:00
|
|
|
setRowHidden(j, file->index(), hide);
|
2009-05-23 10:17:27 +02:00
|
|
|
|
2009-11-19 23:43:46 +01:00
|
|
|
//If it was shown then the file itself has to be shown as well
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!hide) {
|
2009-05-23 10:17:27 +02:00
|
|
|
show = true;
|
|
|
|
}
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
2009-05-23 10:17:27 +02:00
|
|
|
|
2010-11-21 19:55:34 +01:00
|
|
|
//Hide the file if its "hide" attribute is set
|
2011-10-13 20:53:06 +02:00
|
|
|
if (file->data().toMap()["hide"].toBool()) {
|
2010-11-21 19:55:34 +01:00
|
|
|
show = false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 21:16:11 +01:00
|
|
|
QStandardItem *ResultsTree::EnsureFileItem(const QString &fullpath, const QString &file0, bool hide)
|
2009-03-22 18:39:44 +01:00
|
|
|
{
|
2009-06-14 14:09:52 +02:00
|
|
|
QString name = StripPath(fullpath, false);
|
2010-07-18 12:17:21 +02:00
|
|
|
// Since item has path with native separators we must use path with
|
|
|
|
// native separators to find it.
|
|
|
|
QStandardItem *item = FindFileItem(QDir::toNativeSeparators(name));
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (item) {
|
2009-05-23 10:17:27 +02:00
|
|
|
return item;
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
2009-05-23 10:17:27 +02:00
|
|
|
|
2010-07-17 19:20:49 +02:00
|
|
|
// Ensure shown path is with native separators
|
|
|
|
name = QDir::toNativeSeparators(name);
|
2010-11-19 21:54:40 +01:00
|
|
|
item = CreateNormalItem(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
|
|
|
|
2009-06-14 14:09:52 +02:00
|
|
|
//Add user data to that item
|
|
|
|
QMap<QString, QVariant> data;
|
2009-11-19 23:43:46 +01:00
|
|
|
data["file"] = fullpath;
|
2012-02-14 21:16:11 +01:00
|
|
|
data["file0"] = file0;
|
2009-06-14 14:09:52 +02:00
|
|
|
item->setData(QVariant(data));
|
2009-05-23 10:17:27 +02:00
|
|
|
mModel.appendRow(item);
|
|
|
|
|
2009-06-09 08:30:28 +02:00
|
|
|
setRowHidden(mModel.rowCount() - 1, QModelIndex(), hide);
|
|
|
|
|
2009-05-23 10:17:27 +02:00
|
|
|
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);
|
2011-10-13 20:53:06 +02:00
|
|
|
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());
|
2011-10-13 20:53:06 +02:00
|
|
|
if (index.isValid()) {
|
2010-11-28 22:26:53 +01:00
|
|
|
bool multipleSelection = false;
|
|
|
|
mSelectionModel = selectionModel();
|
|
|
|
if (mSelectionModel->selectedRows().count() > 1)
|
|
|
|
multipleSelection = true;
|
|
|
|
|
2009-05-23 13:26:04 +02:00
|
|
|
mContextItem = mModel.itemFromIndex(index);
|
|
|
|
|
2009-06-14 14:09:52 +02:00
|
|
|
//Create a new context menu
|
|
|
|
QMenu menu(this);
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2009-06-14 14:09:52 +02:00
|
|
|
//Store all applications in a list
|
|
|
|
QList<QAction*> actions;
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2009-06-14 14:09:52 +02:00
|
|
|
//Create a signal mapper so we don't have to store data to class
|
|
|
|
//member variables
|
|
|
|
QSignalMapper *signalMapper = new QSignalMapper(this);
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (mContextItem && mApplications->GetApplicationCount() > 0 && mContextItem->parent()) {
|
2009-05-23 13:26:04 +02:00
|
|
|
//Go through all applications and add them to the context menu
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 0; i < mApplications->GetApplicationCount(); i++) {
|
2009-05-23 13:26:04 +02:00
|
|
|
//Create an action for the application
|
2012-10-27 11:35:00 +02:00
|
|
|
const Application& app = mApplications->GetApplication(i);
|
2011-04-02 15:11:01 +02:00
|
|
|
QAction *start = new QAction(app.getName(), &menu);
|
2010-11-28 22:26:53 +01:00
|
|
|
if (multipleSelection)
|
|
|
|
start->setDisabled(true);
|
2009-05-23 13:26:04 +02:00
|
|
|
|
|
|
|
//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)));
|
2009-06-14 14:09:52 +02:00
|
|
|
}
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2009-06-14 14:09:52 +02:00
|
|
|
// Add menuitems to copy full path/filename to clipboard
|
2011-10-13 20:53:06 +02:00
|
|
|
if (mContextItem) {
|
|
|
|
if (mApplications->GetApplicationCount() > 0) {
|
2009-06-14 14:09:52 +02:00
|
|
|
menu.addSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Create an action for the application
|
2012-11-03 21:41:42 +01:00
|
|
|
QAction *copyfilename = new QAction(tr("Copy filename"), &menu);
|
|
|
|
QAction *copypath = new QAction(tr("Copy full path"), &menu);
|
|
|
|
QAction *copymessage = new QAction(tr("Copy message"), &menu);
|
|
|
|
QAction *copymessageid = new QAction(tr("Copy message id"), &menu);
|
|
|
|
QAction *hide = new QAction(tr("Hide"), &menu);
|
2013-02-07 18:00:14 +01:00
|
|
|
QAction *hideallid = new QAction(tr("Hide all with id"), &menu);
|
2013-02-10 23:53:01 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (multipleSelection) {
|
2010-11-28 22:26:53 +01:00
|
|
|
copyfilename->setDisabled(true);
|
|
|
|
copypath->setDisabled(true);
|
|
|
|
copymessage->setDisabled(true);
|
2012-11-03 21:41:42 +01:00
|
|
|
copymessageid->setDisabled(true);
|
2013-02-07 18:00:14 +01:00
|
|
|
hideallid->setDisabled(true);
|
2010-11-28 22:26:53 +01:00
|
|
|
}
|
|
|
|
|
2009-06-14 14:09:52 +02:00
|
|
|
menu.addAction(copyfilename);
|
|
|
|
menu.addAction(copypath);
|
2009-12-06 17:46:24 +01:00
|
|
|
menu.addAction(copymessage);
|
2012-11-03 21:41:42 +01:00
|
|
|
menu.addAction(copymessageid);
|
2010-11-21 19:55:34 +01:00
|
|
|
menu.addAction(hide);
|
2013-02-07 18:00:14 +01:00
|
|
|
menu.addAction(hideallid);
|
2009-06-14 14:09:52 +02:00
|
|
|
|
|
|
|
connect(copyfilename, SIGNAL(triggered()), this, SLOT(CopyFilename()));
|
|
|
|
connect(copypath, SIGNAL(triggered()), this, SLOT(CopyFullPath()));
|
2009-12-06 17:46:24 +01:00
|
|
|
connect(copymessage, SIGNAL(triggered()), this, SLOT(CopyMessage()));
|
2012-11-03 21:41:42 +01:00
|
|
|
connect(copymessageid, SIGNAL(triggered()), this, SLOT(CopyMessageId()));
|
2010-11-21 19:55:34 +01:00
|
|
|
connect(hide, SIGNAL(triggered()), this, SLOT(HideResult()));
|
2013-02-07 18:00:14 +01:00
|
|
|
connect(hideallid, SIGNAL(triggered()), this, SLOT(HideAllIdResult()));
|
2009-06-14 14:09:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Start the menu
|
|
|
|
menu.exec(e->globalPos());
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (mContextItem && mApplications->GetApplicationCount() > 0 && mContextItem->parent()) {
|
2009-05-23 13:26:04 +02:00
|
|
|
//Disconnect all signals
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 0; i < actions.size(); i++) {
|
2009-05-23 13:26:04 +02:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-07-11 13:22:55 +02:00
|
|
|
//If there are no applications specified, tell the user about it
|
2011-10-13 20:53:06 +02:00
|
|
|
if (mApplications->GetApplicationCount() == 0) {
|
2011-07-17 14:11:24 +02:00
|
|
|
QMessageBox msg(QMessageBox::Critical,
|
2009-06-09 09:51:27 +02:00
|
|
|
tr("Cppcheck"),
|
2011-07-17 14:11:24 +02:00
|
|
|
tr("No editor application configured.\n\n"
|
|
|
|
"Configure the editor application for Cppcheck in preferences/Applications."),
|
2009-06-09 21:42:13 +02:00
|
|
|
QMessageBox::Ok,
|
|
|
|
this);
|
2009-06-09 09:51:27 +02:00
|
|
|
msg.exec();
|
2009-06-09 08:30:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-25 11:16:20 +01:00
|
|
|
if (application == -1)
|
|
|
|
application = mApplications->GetDefaultApplication();
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (application == -1) {
|
2011-07-17 14:11:24 +02:00
|
|
|
QMessageBox msg(QMessageBox::Critical,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
tr("No default editor application selected.\n\n"
|
|
|
|
"Please select the default editor application in preferences/Applications."),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
this);
|
|
|
|
msg.exec();
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (target && application >= 0 && application < mApplications->GetApplicationCount() && target->parent()) {
|
2009-11-16 17:02:28 +01:00
|
|
|
// Make sure we are working with the first column
|
2010-04-02 07:30:58 +02:00
|
|
|
if (target->column() != 0)
|
2009-11-16 17:02:28 +01:00
|
|
|
target = target->parent()->child(target->row(), 0);
|
|
|
|
|
2009-05-23 17:45:05 +02:00
|
|
|
QVariantMap data = target->data().toMap();
|
2009-05-23 13:26:04 +02:00
|
|
|
|
|
|
|
//Replace (file) with filename
|
2009-11-19 23:43:46 +01:00
|
|
|
QString file = data["file"].toString();
|
2011-07-17 13:22:06 +02:00
|
|
|
file = QDir::toNativeSeparators(file);
|
2012-03-04 15:53:11 +01:00
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
file.replace(QString("\\"), QString("\\\\"));
|
|
|
|
#endif
|
2011-07-17 13:22:06 +02:00
|
|
|
qDebug() << "Opening file: " << file;
|
2010-07-11 13:22:55 +02:00
|
|
|
|
|
|
|
QFileInfo info(file);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!info.exists()) {
|
|
|
|
if (info.isAbsolute()) {
|
2010-07-11 13:22:55 +02:00
|
|
|
QMessageBox msgbox(this);
|
|
|
|
msgbox.setWindowTitle("Cppcheck");
|
|
|
|
msgbox.setText(tr("Could not find the file!"));
|
|
|
|
msgbox.setIcon(QMessageBox::Critical);
|
|
|
|
msgbox.exec();
|
2011-10-13 20:53:06 +02:00
|
|
|
} else {
|
2010-07-11 15:20:19 +02:00
|
|
|
QDir checkdir(mCheckPath);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (checkdir.isAbsolute() && checkdir.exists()) {
|
2010-07-11 15:20:19 +02:00
|
|
|
file = mCheckPath + "/" + file;
|
2011-10-13 20:53:06 +02:00
|
|
|
} else {
|
2010-07-11 15:20:19 +02:00
|
|
|
QString dir = AskFileDir(file);
|
|
|
|
dir += '/';
|
|
|
|
file = dir + file;
|
|
|
|
}
|
2010-07-11 13:22:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (file.indexOf(" ") > -1) {
|
2009-11-19 23:43:46 +01:00
|
|
|
file.insert(0, "\"");
|
|
|
|
file.append("\"");
|
2009-05-23 13:26:04 +02:00
|
|
|
}
|
|
|
|
|
2012-10-27 11:35:00 +02:00
|
|
|
const Application& app = mApplications->GetApplication(application);
|
2011-04-02 15:11:01 +02:00
|
|
|
QString params = app.getParameters();
|
2011-04-01 23:53:26 +02:00
|
|
|
params.replace("(file)", file, Qt::CaseInsensitive);
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2009-11-19 23:43:46 +01:00
|
|
|
QVariant line = data["line"];
|
2011-04-01 23:53:26 +02:00
|
|
|
params.replace("(line)", QString("%1").arg(line.toInt()), Qt::CaseInsensitive);
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2011-04-01 23:53:26 +02:00
|
|
|
params.replace("(message)", data["message"].toString(), Qt::CaseInsensitive);
|
|
|
|
params.replace("(severity)", data["severity"].toString(), Qt::CaseInsensitive);
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2011-04-02 15:11:01 +02:00
|
|
|
QString program = app.getPath();
|
2011-04-02 11:27:26 +02:00
|
|
|
|
|
|
|
// In Windows we must surround paths including spaces with quotation marks.
|
|
|
|
#ifdef Q_WS_WIN
|
2011-10-13 20:53:06 +02:00
|
|
|
if (program.indexOf(" ") > -1) {
|
|
|
|
if (!program.startsWith('"') && !program.endsWith('"')) {
|
2011-04-02 11:27:26 +02:00
|
|
|
program.insert(0, "\"");
|
|
|
|
program.append("\"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // Q_WS_WIN
|
|
|
|
|
2011-04-01 23:53:26 +02:00
|
|
|
const QString cmdLine = QString("%1 %2").arg(program).arg(params);
|
|
|
|
|
|
|
|
bool success = QProcess::startDetached(cmdLine);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!success) {
|
2011-04-01 23:53:26 +02:00
|
|
|
QString text = tr("Could not start %1\n\nPlease check the application path and parameters are correct.").arg(program);
|
2009-06-08 15:47:53 +02:00
|
|
|
|
|
|
|
QMessageBox msgbox(this);
|
|
|
|
msgbox.setWindowTitle("Cppcheck");
|
|
|
|
msgbox.setText(text);
|
|
|
|
msgbox.setIcon(QMessageBox::Critical);
|
2009-06-09 09:51:27 +02:00
|
|
|
|
2009-06-08 15:47:53 +02:00
|
|
|
msgbox.exec();
|
|
|
|
}
|
2009-05-23 10:17:27 +02:00
|
|
|
}
|
|
|
|
}
|
2009-05-23 17:45:05 +02:00
|
|
|
|
2010-07-11 13:22:55 +02:00
|
|
|
QString ResultsTree::AskFileDir(const QString &file)
|
|
|
|
{
|
|
|
|
QString text = tr("Could not find file:\n%1\nPlease select the directory where file is located.").arg(file);
|
|
|
|
QMessageBox msgbox(this);
|
|
|
|
msgbox.setWindowTitle("Cppcheck");
|
|
|
|
msgbox.setText(text);
|
|
|
|
msgbox.setIcon(QMessageBox::Warning);
|
|
|
|
msgbox.exec();
|
2013-02-09 19:36:48 +01:00
|
|
|
|
2010-07-11 13:22:55 +02:00
|
|
|
QString dir = QFileDialog::getExistingDirectory(this, tr("Select Directory"),
|
2013-02-10 08:15:32 +01:00
|
|
|
"",
|
2010-07-11 13:22:55 +02:00
|
|
|
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
2010-07-11 15:20:19 +02:00
|
|
|
mCheckPath = dir;
|
2010-07-11 13:22:55 +02:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2009-06-14 14:09:52 +02:00
|
|
|
void ResultsTree::CopyFilename()
|
|
|
|
{
|
|
|
|
CopyPath(mContextItem, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::CopyFullPath()
|
|
|
|
{
|
|
|
|
CopyPath(mContextItem, true);
|
|
|
|
}
|
2009-05-23 17:45:05 +02:00
|
|
|
|
2009-12-06 17:46:24 +01:00
|
|
|
void ResultsTree::CopyMessage()
|
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if (mContextItem) {
|
2009-12-06 17:46:24 +01:00
|
|
|
// Make sure we are working with the first column
|
2010-04-02 07:30:58 +02:00
|
|
|
if (mContextItem->column() != 0)
|
2009-12-06 17:46:24 +01:00
|
|
|
mContextItem = mContextItem->parent()->child(mContextItem->row(), 0);
|
|
|
|
|
|
|
|
QVariantMap data = mContextItem->data().toMap();
|
|
|
|
|
2011-04-16 13:04:20 +02:00
|
|
|
QString message;
|
2011-10-13 20:53:06 +02:00
|
|
|
if (data["inconclusive"].toBool()) {
|
2011-04-16 13:04:20 +02:00
|
|
|
message = tr("[Inconclusive]");
|
|
|
|
message += " ";
|
|
|
|
}
|
|
|
|
message += data["message"].toString();
|
2009-12-06 17:46:24 +01:00
|
|
|
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
clipboard->setText(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-03 21:41:42 +01:00
|
|
|
void ResultsTree::CopyMessageId()
|
|
|
|
{
|
|
|
|
if (mContextItem) {
|
|
|
|
// Make sure we are working with the first column
|
|
|
|
if (mContextItem->column() != 0)
|
|
|
|
mContextItem = mContextItem->parent()->child(mContextItem->row(), 0);
|
|
|
|
QVariantMap data = mContextItem->data().toMap();
|
|
|
|
|
|
|
|
QString messageId = data["id"].toString();
|
|
|
|
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
clipboard->setText(messageId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-21 19:55:34 +01:00
|
|
|
void ResultsTree::HideResult()
|
|
|
|
{
|
2010-11-28 22:26:53 +01:00
|
|
|
if (!mSelectionModel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QModelIndexList selectedRows = mSelectionModel->selectedRows();
|
|
|
|
QModelIndex index;
|
2011-10-13 20:53:06 +02:00
|
|
|
foreach(index, selectedRows) {
|
2010-11-28 22:26:53 +01:00
|
|
|
QStandardItem *item = mModel.itemFromIndex(index);
|
2010-11-21 19:55:34 +01:00
|
|
|
//Set the "hide" flag for this item
|
2010-11-28 22:26:53 +01:00
|
|
|
QVariantMap data = item->data().toMap();
|
2010-11-21 19:55:34 +01:00
|
|
|
data["hide"] = true;
|
2010-11-28 22:26:53 +01:00
|
|
|
item->setData(QVariant(data));
|
2010-11-21 19:55:34 +01:00
|
|
|
|
|
|
|
RefreshTree();
|
2010-11-24 09:48:07 +01:00
|
|
|
emit ResultsHidden(true);
|
2010-11-21 19:55:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 18:00:14 +01:00
|
|
|
void ResultsTree::HideAllIdResult()
|
|
|
|
{
|
|
|
|
if (mContextItem) {
|
|
|
|
// Make sure we are working with the first column
|
|
|
|
if (mContextItem->column() != 0)
|
|
|
|
mContextItem = mContextItem->parent()->child(mContextItem->row(), 0);
|
|
|
|
QVariantMap data = mContextItem->data().toMap();
|
|
|
|
|
|
|
|
QString messageId = data["id"].toString();
|
|
|
|
|
|
|
|
// hide all errors with that message Id
|
|
|
|
int filecount = mModel.rowCount();
|
|
|
|
for (int i = 0; i < filecount; i++) {
|
|
|
|
//Get file i
|
|
|
|
QStandardItem *file = mModel.item(i, 0);
|
|
|
|
if (!file) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-10 23:53:01 +01:00
|
|
|
|
2013-02-07 18:00:14 +01:00
|
|
|
//Get the amount of errors this file contains
|
|
|
|
int errorcount = file->rowCount();
|
|
|
|
|
|
|
|
for (int j = 0; j < errorcount; j++) {
|
|
|
|
//Get the error itself
|
|
|
|
QStandardItem *child = file->child(j, 0);
|
|
|
|
if (!child) {
|
2013-02-10 23:53:01 +01:00
|
|
|
continue;
|
2013-02-07 18:00:14 +01:00
|
|
|
}
|
2013-02-10 23:53:01 +01:00
|
|
|
|
2013-02-07 18:00:14 +01:00
|
|
|
QVariantMap userdata = child->data().toMap();
|
|
|
|
if (userdata["id"].toString() == messageId) {
|
|
|
|
userdata["hide"] = true;
|
|
|
|
child->setData(QVariant(userdata));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RefreshTree();
|
|
|
|
emit ResultsHidden(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-23 17:45:05 +02:00
|
|
|
void ResultsTree::Context(int application)
|
|
|
|
{
|
|
|
|
StartApplication(mContextItem, application);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::QuickStartApplication(const QModelIndex &index)
|
|
|
|
{
|
2011-02-25 11:16:20 +01:00
|
|
|
StartApplication(mModel.itemFromIndex(index));
|
2009-05-23 17:45:05 +02:00
|
|
|
}
|
2009-05-26 17:21:39 +02:00
|
|
|
|
2009-06-14 14:09:52 +02:00
|
|
|
void ResultsTree::CopyPath(QStandardItem *target, bool fullPath)
|
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if (target) {
|
2009-11-19 23:43:46 +01:00
|
|
|
// Make sure we are working with the first column
|
2010-04-02 07:30:58 +02:00
|
|
|
if (target->column() != 0)
|
2009-11-19 23:43:46 +01:00
|
|
|
target = target->parent()->child(target->row(), 0);
|
|
|
|
|
2009-06-14 14:09:52 +02:00
|
|
|
QVariantMap data = target->data().toMap();
|
|
|
|
QString pathStr;
|
|
|
|
|
|
|
|
//Replace (file) with filename
|
2009-11-19 23:43:46 +01:00
|
|
|
QString file = data["file"].toString();
|
2011-01-06 17:32:04 +01:00
|
|
|
pathStr = QDir::toNativeSeparators(file);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!fullPath) {
|
2009-11-19 23:43:46 +01:00
|
|
|
QFileInfo fi(pathStr);
|
|
|
|
pathStr = fi.fileName();
|
2009-06-14 14:09:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
clipboard->setText(pathStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 22:11:59 +01:00
|
|
|
QString ResultsTree::SeverityToIcon(Severity::SeverityType severity) const
|
2009-05-26 17:21:39 +02:00
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (severity) {
|
2011-03-07 22:11:59 +01:00
|
|
|
case Severity::error:
|
2009-06-01 23:06:44 +02:00
|
|
|
return ":images/dialog-error.png";
|
2011-03-07 22:11:59 +01:00
|
|
|
case Severity::style:
|
2010-12-26 13:01:15 +01:00
|
|
|
return ":images/applications-development.png";
|
2011-03-07 22:11:59 +01:00
|
|
|
case Severity::warning:
|
2010-10-18 20:35:35 +02:00
|
|
|
return ":images/dialog-warning.png";
|
2011-03-07 22:11:59 +01:00
|
|
|
case Severity::portability:
|
2010-12-27 10:06:31 +01:00
|
|
|
return ":images/applications-system.png";
|
2011-03-07 22:11:59 +01:00
|
|
|
case Severity::performance:
|
2010-10-18 20:35:35 +02:00
|
|
|
return ":images/utilities-system-monitor.png";
|
2011-03-07 22:11:59 +01:00
|
|
|
case Severity::information:
|
2010-12-26 13:36:24 +01:00
|
|
|
return ":images/dialog-information.png";
|
2011-03-07 22:11:59 +01:00
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
2009-05-26 17:21:39 +02:00
|
|
|
}
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2012-10-27 12:10:32 +02:00
|
|
|
void ResultsTree::SaveResults(Report *report) const
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2009-06-24 09:54:56 +02:00
|
|
|
report->WriteHeader();
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 0; i < mModel.rowCount(); i++) {
|
2009-06-03 20:18:22 +02:00
|
|
|
QStandardItem *item = mModel.item(i, 0);
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!isRowHidden(i, item->index()))
|
2009-07-04 21:29:48 +02:00
|
|
|
SaveErrors(report, item);
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
2009-06-24 09:54:56 +02:00
|
|
|
report->WriteFooter();
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
2012-10-27 12:10:32 +02:00
|
|
|
void ResultsTree::SaveErrors(Report *report, QStandardItem *item) const
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!item) {
|
2009-06-03 20:18:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 0; i < item->rowCount(); i++) {
|
2009-06-03 20:18:22 +02:00
|
|
|
QStandardItem *error = item->child(i, 0);
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!error) {
|
2009-06-03 20:18:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (isRowHidden(i, item->index()) && !mSaveAllErrors) {
|
2009-06-03 20:18:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Get error's user data
|
|
|
|
QVariant userdata = error->data();
|
|
|
|
//Convert it to QVariantMap
|
|
|
|
QVariantMap data = userdata.toMap();
|
|
|
|
|
2010-07-10 17:20:45 +02:00
|
|
|
ErrorItem item;
|
2011-10-11 21:14:15 +02:00
|
|
|
item.severity = ShowTypes::ShowTypeToSeverity(ShowTypes::VariantToShowType(data["severity"]));
|
2010-11-11 22:15:06 +01:00
|
|
|
item.summary = data["summary"].toString();
|
2010-11-11 21:51:00 +01:00
|
|
|
item.message = data["message"].toString();
|
2011-10-12 21:18:54 +02:00
|
|
|
item.errorId = data["id"].toString();
|
2011-04-16 13:04:20 +02:00
|
|
|
item.inconclusive = data["inconclusive"].toBool();
|
2012-02-14 21:16:11 +01:00
|
|
|
item.file0 = data["file0"].toString();
|
2009-11-19 23:43:46 +01:00
|
|
|
QString file = StripPath(data["file"].toString(), true);
|
2010-07-10 19:54:33 +02:00
|
|
|
unsigned int line = data["line"].toUInt();
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2010-07-10 17:20:45 +02:00
|
|
|
item.files << file;
|
|
|
|
item.lines << line;
|
2009-11-19 23:43:46 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int j = 0; j < error->rowCount(); j++) {
|
2009-11-19 23:43:46 +01:00
|
|
|
QStandardItem *child_error = error->child(j, 0);
|
|
|
|
//Get error's user data
|
|
|
|
QVariant child_userdata = child_error->data();
|
|
|
|
//Convert it to QVariantMap
|
|
|
|
QVariantMap child_data = child_userdata.toMap();
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2009-11-19 23:43:46 +01:00
|
|
|
file = StripPath(child_data["file"].toString(), true);
|
2010-07-10 19:54:33 +02:00
|
|
|
line = child_data["line"].toUInt();
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2010-07-10 17:20:45 +02:00
|
|
|
item.files << file;
|
|
|
|
item.lines << line;
|
2009-11-19 23:43:46 +01:00
|
|
|
}
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2010-07-10 17:20:45 +02:00
|
|
|
report->WriteError(item);
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::UpdateSettings(bool showFullPath,
|
|
|
|
bool saveFullPath,
|
2012-10-27 11:16:52 +02:00
|
|
|
bool saveAllErrors,
|
|
|
|
bool showErrorId)
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if (mShowFullPath != showFullPath) {
|
2009-06-03 20:18:22 +02:00
|
|
|
mShowFullPath = showFullPath;
|
|
|
|
RefreshFilePaths();
|
|
|
|
}
|
|
|
|
|
|
|
|
mSaveFullPath = saveFullPath;
|
|
|
|
mSaveAllErrors = saveAllErrors;
|
2012-10-27 11:16:52 +02:00
|
|
|
|
|
|
|
ShowIdColumn(showErrorId);
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::SetCheckDirectory(const QString &dir)
|
|
|
|
{
|
|
|
|
mCheckPath = dir;
|
|
|
|
}
|
|
|
|
|
2012-10-27 12:10:32 +02:00
|
|
|
QString ResultsTree::StripPath(const QString &path, bool saving) const
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if ((!saving && mShowFullPath) || (saving && mSaveFullPath)) {
|
2009-06-03 20:18:22 +02:00
|
|
|
return QString(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
QDir dir(mCheckPath);
|
|
|
|
return dir.relativeFilePath(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::RefreshFilePaths(QStandardItem *item)
|
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!item) {
|
2009-06-03 20:18:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Mark that this file's path hasn't been updated yet
|
|
|
|
bool updated = false;
|
|
|
|
|
|
|
|
//Loop through all errors within this file
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 0; i < item->rowCount(); i++) {
|
2009-06-03 20:18:22 +02:00
|
|
|
//Get error i
|
|
|
|
QStandardItem *error = item->child(i, 0);
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!error) {
|
2009-06-03 20:18:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Get error's user data
|
|
|
|
QVariant userdata = error->data();
|
|
|
|
//Convert it to QVariantMap
|
|
|
|
QVariantMap data = userdata.toMap();
|
|
|
|
|
|
|
|
//Get list of files
|
2009-11-19 23:43:46 +01:00
|
|
|
QString file = data["file"].toString();
|
2009-06-03 20:18:22 +02:00
|
|
|
|
|
|
|
//Update this error's text
|
2009-11-19 23:43:46 +01:00
|
|
|
error->setText(StripPath(file, false));
|
2009-06-03 20:18:22 +02:00
|
|
|
|
|
|
|
//If this error has backtraces make sure the files list has enough filenames
|
2011-10-13 20:53:06 +02:00
|
|
|
if (error->hasChildren()) {
|
2009-06-03 20:18:22 +02:00
|
|
|
//Loop through all files within the error
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int j = 0; j < error->rowCount(); j++) {
|
2009-06-03 20:18:22 +02:00
|
|
|
//Get file
|
2009-11-19 23:43:46 +01:00
|
|
|
QStandardItem *child = error->child(j, 0);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!child) {
|
2009-06-03 20:18:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
2009-11-19 23:43:46 +01:00
|
|
|
//Get childs's user data
|
|
|
|
QVariant child_userdata = child->data();
|
|
|
|
//Convert it to QVariantMap
|
|
|
|
QVariantMap child_data = child_userdata.toMap();
|
|
|
|
|
|
|
|
//Get list of files
|
|
|
|
QString child_files = child_data["file"].toString();
|
2009-06-03 20:18:22 +02:00
|
|
|
//Update file's path
|
2009-11-19 23:43:46 +01:00
|
|
|
child->setText(StripPath(child_files, false));
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//if the main file hasn't been updated yet, update it now
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!updated) {
|
2009-06-03 20:18:22 +02:00
|
|
|
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)
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 0; i < mModel.rowCount(); i++) {
|
2009-06-03 20:18:22 +02:00
|
|
|
RefreshFilePaths(mModel.item(i, 0));
|
|
|
|
}
|
|
|
|
}
|
2009-06-09 09:51:27 +02:00
|
|
|
|
2009-06-20 22:05:17 +02:00
|
|
|
bool ResultsTree::HasVisibleResults() const
|
2009-06-09 09:51:27 +02:00
|
|
|
{
|
|
|
|
return mVisibleErrors;
|
|
|
|
}
|
2009-06-20 22:42:12 +02:00
|
|
|
|
|
|
|
bool ResultsTree::HasResults() const
|
|
|
|
{
|
|
|
|
return mModel.rowCount() > 0;
|
|
|
|
}
|
2009-07-02 10:32:29 +02:00
|
|
|
|
2009-07-02 10:46:26 +02:00
|
|
|
void ResultsTree::Translate()
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
|
|
|
QStringList labels;
|
2012-10-27 11:16:52 +02:00
|
|
|
labels << tr("File") << tr("Severity") << tr("Line") << tr("Id") << tr("Summary");
|
2009-07-02 10:32:29 +02:00
|
|
|
mModel.setHorizontalHeaderLabels(labels);
|
2009-07-02 12:48:32 +02:00
|
|
|
//TODO go through all the errors in the tree and translate severity and message
|
2009-07-02 10:32:29 +02:00
|
|
|
}
|
|
|
|
|
2012-10-27 11:16:52 +02:00
|
|
|
void ResultsTree::ShowIdColumn(bool show)
|
|
|
|
{
|
|
|
|
mShowErrorId = show;
|
|
|
|
if (show)
|
|
|
|
showColumn(3);
|
|
|
|
else
|
|
|
|
hideColumn(3);
|
|
|
|
}
|
|
|
|
|
2010-11-23 21:37:31 +01:00
|
|
|
void ResultsTree::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
{
|
|
|
|
QTreeView::currentChanged(current, previous);
|
|
|
|
emit SelectionChanged(current);
|
|
|
|
}
|