2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2023-01-28 10:16:34 +01:00
|
|
|
* Copyright (C) 2007-2023 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
|
|
|
*/
|
|
|
|
|
2021-04-03 21:30:50 +02:00
|
|
|
#include "resultstree.h"
|
|
|
|
|
2022-02-02 16:17:28 +01:00
|
|
|
#include "application.h"
|
|
|
|
#include "applicationlist.h"
|
|
|
|
#include "common.h"
|
2022-09-16 07:15:49 +02:00
|
|
|
#include "config.h"
|
2022-02-02 16:17:28 +01:00
|
|
|
#include "erroritem.h"
|
2023-10-16 12:57:49 +02:00
|
|
|
#include "errortypes.h"
|
2022-02-02 16:17:28 +01:00
|
|
|
#include "path.h"
|
|
|
|
#include "projectfile.h"
|
|
|
|
#include "report.h"
|
|
|
|
#include "showtypes.h"
|
2022-04-13 12:24:00 +02:00
|
|
|
#include "suppressions.h"
|
2022-02-02 16:17:28 +01:00
|
|
|
#include "threadhandler.h"
|
|
|
|
#include "xmlreportv2.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
2009-06-14 14:09:52 +02:00
|
|
|
#include <QApplication>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QClipboard>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QContextMenuEvent>
|
2009-03-02 20:56:51 +01:00
|
|
|
#include <QDebug>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QDesktopServices>
|
2009-06-03 20:18:22 +02:00
|
|
|
#include <QDir>
|
2009-06-14 14:09:52 +02:00
|
|
|
#include <QFileInfo>
|
2010-07-11 13:22:55 +02:00
|
|
|
#include <QFileDialog>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QIcon>
|
|
|
|
#include <QItemSelectionModel>
|
2021-04-03 21:30:50 +02:00
|
|
|
#include <QKeyEvent>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QList>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QLocale>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QMap>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QModelIndex>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QProcess>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QSet>
|
2021-04-03 21:30:50 +02:00
|
|
|
#include <QSettings>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QSignalMapper>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QStandardItem>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QUrl>
|
|
|
|
#include <QVariant>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QVariantMap>
|
|
|
|
#include <Qt>
|
2017-08-02 20:24:23 +02:00
|
|
|
|
2020-07-16 23:03:54 +02:00
|
|
|
static const char COLUMN[] = "column";
|
|
|
|
static const char CWE[] = "cwe";
|
|
|
|
static const char ERRORID[] = "id";
|
|
|
|
static const char FILENAME[] = "file";
|
|
|
|
static const char FILE0[] = "file0";
|
2020-07-21 11:27:03 +02:00
|
|
|
static const char HASH[] = "hash";
|
2020-07-16 23:03:54 +02:00
|
|
|
static const char HIDE[] = "hide";
|
|
|
|
static const char INCONCLUSIVE[] = "inconclusive";
|
|
|
|
static const char LINE[] = "line";
|
|
|
|
static const char MESSAGE[] = "message";
|
|
|
|
static const char SEVERITY[] = "severity";
|
|
|
|
static const char SINCEDATE[] = "sinceDate";
|
2020-07-18 18:14:55 +02:00
|
|
|
static const char SYMBOLNAMES[] = "symbolNames";
|
2020-07-16 23:03:54 +02:00
|
|
|
static const char SUMMARY[] = "summary";
|
|
|
|
static const char TAGS[] = "tags";
|
|
|
|
|
2017-08-02 20:24:23 +02:00
|
|
|
// These must match column headers given in ResultsTree::translate()
|
2020-07-16 20:19:36 +02:00
|
|
|
static const int COLUMN_SINCE_DATE = 6;
|
|
|
|
static const int COLUMN_TAGS = 7;
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
ResultsTree::ResultsTree(QWidget * parent) :
|
2023-08-08 11:05:02 +02:00
|
|
|
QTreeView(parent)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
|
|
|
setModel(&mModel);
|
2017-07-28 11:54:20 +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
|
|
|
|
2017-07-31 08:18:34 +02:00
|
|
|
connect(this, &ResultsTree::doubleClicked, this, &ResultsTree::quickStartApplication);
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2015-12-03 19:33:36 +01:00
|
|
|
void ResultsTree::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
|
2017-07-28 11:54:20 +02:00
|
|
|
quickStartApplication(this->currentIndex());
|
2015-12-03 19:33:36 +01:00
|
|
|
}
|
|
|
|
QTreeView::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler)
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
|
|
|
mSettings = settings;
|
|
|
|
mApplications = list;
|
2015-12-23 10:28:07 +01:00
|
|
|
mThread = checkThreadHandler;
|
2017-07-28 11:54:20 +02:00
|
|
|
loadSettings();
|
2009-07-02 10:32:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-28 11:54:20 +02: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;
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
QStandardItem *ResultsTree::createCheckboxItem(bool checked)
|
2015-10-15 11:59:17 +02:00
|
|
|
{
|
|
|
|
QStandardItem *item = new QStandardItem;
|
|
|
|
item->setCheckable(true);
|
|
|
|
item->setCheckState(checked ? Qt::Checked : Qt::Unchecked);
|
|
|
|
item->setEnabled(false);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
QStandardItem *ResultsTree::createLineNumberItem(const QString &linenumber)
|
2010-11-19 22:11:40 +01:00
|
|
|
{
|
2011-02-11 20:03:39 +01:00
|
|
|
QStandardItem *item = new QStandardItem();
|
2021-07-22 19:55:23 +02:00
|
|
|
item->setData(QVariant(linenumber.toInt()), Qt::DisplayRole);
|
2011-02-11 20:03:39 +01:00
|
|
|
item->setToolTip(linenumber);
|
2010-11-19 22:11:40 +01:00
|
|
|
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
item->setEditable(false);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
bool ResultsTree::addErrorItem(const ErrorItem &item)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2017-05-21 08:25:55 +02:00
|
|
|
if (item.errorPath.isEmpty()) {
|
2013-02-15 16:49:36 +01:00
|
|
|
return false;
|
2009-05-23 10:17:27 +02:00
|
|
|
}
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2017-08-10 22:46:23 +02:00
|
|
|
const QErrorPathItem &loc = item.errorId.startsWith("clang") ? item.errorPath.front() : item.errorPath.back();
|
|
|
|
QString realfile = stripPath(loc.file, 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
|
|
|
}
|
|
|
|
|
2019-08-22 21:32:18 +02:00
|
|
|
bool hide = false;
|
2009-06-09 09:51:27 +02:00
|
|
|
|
2018-02-15 22:37:10 +01:00
|
|
|
// Ids that are temporarily hidden..
|
|
|
|
if (mHiddenMessageId.contains(item.errorId))
|
|
|
|
hide = true;
|
|
|
|
|
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) &&
|
2017-05-21 08:25:55 +02:00
|
|
|
!item.errorPath.back().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;
|
2017-08-10 22:46:23 +02:00
|
|
|
line.line = loc.line;
|
2011-10-12 21:18:54 +02:00
|
|
|
line.errorId = item.errorId;
|
2020-05-03 17:20:38 +02:00
|
|
|
line.cwe = item.cwe;
|
2020-07-21 11:27:03 +02:00
|
|
|
line.hash = item.hash;
|
2011-04-16 13:04:20 +02:00
|
|
|
line.inconclusive = item.inconclusive;
|
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;
|
2017-08-02 20:24:23 +02:00
|
|
|
line.sinceDate = item.sinceDate;
|
2020-07-16 23:03:54 +02:00
|
|
|
if (const ProjectFile *activeProject = ProjectFile::getActiveProject()) {
|
2020-07-21 11:27:03 +02:00
|
|
|
line.tags = activeProject->getWarningTags(item.hash);
|
2020-07-16 23:03:54 +02:00
|
|
|
}
|
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
|
2017-08-10 22:46:23 +02:00
|
|
|
QStandardItem* fileItem = ensureFileItem(loc.file, item.file0, hide);
|
2017-07-28 11:54:20 +02:00
|
|
|
QStandardItem* stditem = addBacktraceFiles(fileItem,
|
2021-08-07 20:51:18 +02:00
|
|
|
line,
|
|
|
|
hide,
|
|
|
|
severityToIcon(line.severity),
|
|
|
|
false);
|
2010-07-10 19:30:31 +02:00
|
|
|
|
|
|
|
if (!stditem)
|
2013-02-15 16:49:36 +01:00
|
|
|
return false;
|
2009-11-16 17:09:30 +01:00
|
|
|
|
2009-05-23 10:17:27 +02:00
|
|
|
//Add user data to that item
|
|
|
|
QMap<QString, QVariant> data;
|
2020-07-16 23:03:54 +02:00
|
|
|
data[SEVERITY] = ShowTypes::SeverityToShowType(item.severity);
|
|
|
|
data[SUMMARY] = item.summary;
|
|
|
|
data[MESSAGE] = item.message;
|
|
|
|
data[FILENAME] = loc.file;
|
|
|
|
data[LINE] = loc.line;
|
|
|
|
data[COLUMN] = loc.column;
|
|
|
|
data[ERRORID] = item.errorId;
|
|
|
|
data[CWE] = item.cwe;
|
2020-07-21 11:27:03 +02:00
|
|
|
data[HASH] = item.hash;
|
2020-07-16 23:03:54 +02:00
|
|
|
data[INCONCLUSIVE] = item.inconclusive;
|
|
|
|
data[FILE0] = stripPath(item.file0, true);
|
|
|
|
data[SINCEDATE] = item.sinceDate;
|
2020-07-18 18:14:55 +02:00
|
|
|
data[SYMBOLNAMES] = item.symbolNames;
|
2020-07-16 23:03:54 +02:00
|
|
|
data[TAGS] = line.tags;
|
|
|
|
data[HIDE] = hide;
|
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
|
2021-05-05 07:35:13 +02:00
|
|
|
if (item.errorPath.size() > 1) {
|
2017-05-21 08:25:55 +02:00
|
|
|
for (int i = 0; i < item.errorPath.size(); i++) {
|
|
|
|
const QErrorPathItem &e = item.errorPath[i];
|
|
|
|
line.file = e.file;
|
|
|
|
line.line = e.line;
|
|
|
|
line.message = line.summary = e.info;
|
2023-10-18 10:06:17 +02:00
|
|
|
QStandardItem *child_item = addBacktraceFiles(stditem,
|
|
|
|
line,
|
|
|
|
hide,
|
|
|
|
":images/go-down.png",
|
|
|
|
true);
|
2017-06-07 11:55:21 +02:00
|
|
|
if (!child_item)
|
|
|
|
continue;
|
2017-05-21 08:25:55 +02:00
|
|
|
|
2020-04-27 09:08:50 +02:00
|
|
|
// Add user data to that item
|
2017-05-21 08:25:55 +02:00
|
|
|
QMap<QString, QVariant> child_data;
|
2020-07-16 23:03:54 +02:00
|
|
|
child_data[SEVERITY] = ShowTypes::SeverityToShowType(line.severity);
|
|
|
|
child_data[SUMMARY] = line.summary;
|
|
|
|
child_data[MESSAGE] = line.message;
|
|
|
|
child_data[FILENAME] = e.file;
|
|
|
|
child_data[LINE] = e.line;
|
|
|
|
child_data[COLUMN] = e.column;
|
|
|
|
child_data[ERRORID] = line.errorId;
|
|
|
|
child_data[CWE] = line.cwe;
|
2020-07-21 11:27:03 +02:00
|
|
|
child_data[HASH] = line.hash;
|
2020-07-16 23:03:54 +02:00
|
|
|
child_data[INCONCLUSIVE] = line.inconclusive;
|
2020-07-18 18:14:55 +02:00
|
|
|
child_data[SYMBOLNAMES] = item.symbolNames;
|
2017-05-21 08:25:55 +02:00
|
|
|
child_item->setData(QVariant(child_data));
|
|
|
|
}
|
2009-05-23 10:17:27 +02:00
|
|
|
}
|
|
|
|
|
2015-10-15 12:08:51 +02:00
|
|
|
// Partially refresh the tree: Unhide file item if necessary
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!hide) {
|
2019-08-22 21:32:18 +02:00
|
|
|
setRowHidden(fileItem->row(), QModelIndex(), !mShowSeverities.isShown(item.severity));
|
2009-05-23 10:33:38 +02:00
|
|
|
}
|
2013-02-15 16:49:36 +01:00
|
|
|
return true;
|
2009-05-23 10:17:27 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
QStandardItem *ResultsTree::addBacktraceFiles(QStandardItem *parent,
|
2021-08-07 20:51:18 +02:00
|
|
|
const ErrorLine &item,
|
|
|
|
const bool hide,
|
|
|
|
const QString &icon,
|
|
|
|
bool childOfMessage)
|
2009-05-23 10:17:27 +02:00
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!parent) {
|
2017-06-07 11:55:21 +02:00
|
|
|
return nullptr;
|
2009-05-23 10:33:38 +02:00
|
|
|
}
|
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
|
2017-07-28 11:54:20 +02:00
|
|
|
list << createNormalItem(QDir::toNativeSeparators(item.file))
|
|
|
|
<< createNormalItem(childOfMessage ? tr("note") : severityToTranslatedString(item.severity))
|
|
|
|
<< createLineNumberItem(QString::number(item.line))
|
|
|
|
<< createNormalItem(childOfMessage ? QString() : item.errorId)
|
|
|
|
<< (childOfMessage ? createNormalItem(QString()) : createCheckboxItem(item.inconclusive))
|
2017-08-02 20:24:23 +02:00
|
|
|
<< createNormalItem(item.summary)
|
2017-08-18 17:25:08 +02:00
|
|
|
<< createNormalItem(item.sinceDate)
|
|
|
|
<< createNormalItem(item.tags);
|
|
|
|
|
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
|
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()) {
|
2015-10-15 12:08:51 +02:00
|
|
|
// the sixth column is the summary so check it last
|
|
|
|
if (parent->child(i, 5)->text() == list[5]->text()) {
|
2010-11-22 22:32:04 +01:00
|
|
|
// this row matches so don't add it
|
2017-06-07 11:55:21 +02:00
|
|
|
return nullptr;
|
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));
|
|
|
|
}
|
|
|
|
|
fixed memory leak in `cppcheck-gui` (#4248)
* settingsdialog.cpp: fixed memory leak
Direct leak of 200 byte(s) in 1 object(s) allocated from:
#0 0xa15a2d in operator new(unsigned long) (/mnt/s/GitHub/cppcheck-fw/cmake-build-debug-wsl-kali-clang-asan-ubsan/bin/cppcheck-gui+0xa15a2d)
#1 0xe639af in SettingsDialog::SettingsDialog(ApplicationList*, TranslationHandler*, QWidget*) /mnt/s/GitHub/cppcheck-fw/gui/settingsdialog.cpp:75:21
#2 0xc67807 in MainWindow::programSettings() /mnt/s/GitHub/cppcheck-fw/gui/mainwindow.cpp:1064:20
#3 0xd1deb8 in QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (MainWindow::*)()>::call(void (MainWindow::*)(), MainWindow*, void**) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:152:13
#4 0xd1db5c in void QtPrivate::FunctionPointer<void (MainWindow::*)()>::call<QtPrivate::List<>, void>(void (MainWindow::*)(), MainWindow*, void**) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:185:13
#5 0xd1d675 in QtPrivate::QSlotObject<void (MainWindow::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:418:17
#6 0x7f9687f26132 (/usr/lib/x86_64-linux-gnu/libQt5Core.so.5+0x2e6132)
#7 0x7f96889ccdc1 in QAction::triggered(bool) (/usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x15cdc1)
* resultstree.cpp: adjusted TODO about memory leaks
2022-07-09 22:32:48 +02:00
|
|
|
/* TODO: the list items leak memory
|
|
|
|
Indirect leak of 80624 byte(s) in 5039 object(s) allocated from:
|
|
|
|
#0 0xa15a2d in operator new(unsigned long) (/mnt/s/GitHub/cppcheck-fw/cmake-build-debug-wsl-kali-clang-asan-ubsan/bin/cppcheck-gui+0xa15a2d)
|
|
|
|
#1 0xdda276 in ResultsTree::createNormalItem(QString const&) /mnt/s/GitHub/cppcheck-fw/gui/resultstree.cpp:122:27
|
|
|
|
#2 0xde4290 in ResultsTree::addBacktraceFiles(QStandardItem*, ErrorLine const&, bool, QString const&, bool) /mnt/s/GitHub/cppcheck-fw/gui/resultstree.cpp:289:13
|
|
|
|
#3 0xddd754 in ResultsTree::addErrorItem(ErrorItem const&) /mnt/s/GitHub/cppcheck-fw/gui/resultstree.cpp:199:30
|
|
|
|
#4 0xe37046 in ResultsView::error(ErrorItem const&) /mnt/s/GitHub/cppcheck-fw/gui/resultsview.cpp:129:21
|
|
|
|
#5 0xd2448d in QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List<ErrorItem const&>, void, void (ResultsView::*)(ErrorItem const&)>::call(void (ResultsView::*)(ErrorItem const&), ResultsView*, void**) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:152:13
|
|
|
|
#6 0xd2402c in void QtPrivate::FunctionPointer<void (ResultsView::*)(ErrorItem const&)>::call<QtPrivate::List<ErrorItem const&>, void>(void (ResultsView::*)(ErrorItem const&), ResultsView*, void**) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:185:13
|
|
|
|
#7 0xd23b45 in QtPrivate::QSlotObject<void (ResultsView::*)(ErrorItem const&), QtPrivate::List<ErrorItem const&>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:418:17
|
|
|
|
#8 0x7fd2536cc0dd in QObject::event(QEvent*) (/usr/lib/x86_64-linux-gnu/libQt5Core.so.5+0x2dc0dd)
|
|
|
|
#9 0x7fd2541836be in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x1636be)
|
|
|
|
*/
|
2009-05-23 10:17:27 +02:00
|
|
|
|
|
|
|
return list[0];
|
|
|
|
}
|
|
|
|
|
2023-10-12 11:58:39 +02:00
|
|
|
QString ResultsTree::severityToTranslatedString(Severity severity)
|
2011-03-07 22:35:58 +01:00
|
|
|
{
|
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:
|
2017-08-03 12:39:31 +02:00
|
|
|
return QString();
|
2011-03-07 22:35:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +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
|
|
|
}
|
2019-06-30 21:39:22 +02:00
|
|
|
return nullptr;
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::clear()
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
|
|
|
mModel.removeRows(0, mModel.rowCount());
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::clear(const QString &filename)
|
2012-02-14 21:16:11 +01:00
|
|
|
{
|
2017-07-28 11:54:20 +02:00
|
|
|
const QString stripped = stripPath(filename, false);
|
2012-02-14 21:16:11 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < mModel.rowCount(); ++i) {
|
2017-08-02 19:09:03 +02:00
|
|
|
const QStandardItem *fileItem = mModel.item(i, 0);
|
|
|
|
if (!fileItem)
|
2012-02-14 21:16:11 +01:00
|
|
|
continue;
|
|
|
|
|
2017-08-02 19:09:03 +02:00
|
|
|
QVariantMap data = fileItem->data().toMap();
|
2020-07-16 23:03:54 +02:00
|
|
|
if (stripped == data[FILENAME].toString() ||
|
|
|
|
filename == data[FILE0].toString()) {
|
2012-02-14 21:16:11 +01:00
|
|
|
mModel.removeRow(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::clearRecheckFile(const QString &filename)
|
2015-12-29 01:38:36 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; i < mModel.rowCount(); ++i) {
|
2017-08-02 19:09:03 +02:00
|
|
|
const QStandardItem *fileItem = mModel.item(i, 0);
|
|
|
|
if (!fileItem)
|
2015-12-29 01:38:36 +01:00
|
|
|
continue;
|
|
|
|
|
2016-01-15 16:52:22 +01:00
|
|
|
QString actualfile((!mCheckPath.isEmpty() && filename.startsWith(mCheckPath)) ? filename.mid(mCheckPath.length() + 1) : filename);
|
2017-08-02 19:09:03 +02:00
|
|
|
QVariantMap data = fileItem->data().toMap();
|
2020-07-16 23:03:54 +02:00
|
|
|
QString storedfile = data[FILENAME].toString();
|
2016-01-15 16:52:22 +01:00
|
|
|
storedfile = ((!mCheckPath.isEmpty() && storedfile.startsWith(mCheckPath)) ? storedfile.mid(mCheckPath.length() + 1) : storedfile);
|
|
|
|
if (actualfile == storedfile) {
|
2015-12-29 01:38:36 +01:00
|
|
|
mModel.removeRow(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 21:16:11 +01:00
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::loadSettings()
|
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);
|
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
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
showIdColumn(mSettings->value(SETTINGS_SHOW_ERROR_ID, false).toBool());
|
|
|
|
showInconclusiveColumn(mSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool());
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +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
|
|
|
|
2017-07-28 11:54:20 +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);
|
2017-07-28 11:54:20 +02:00
|
|
|
refreshTree();
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-20 12:21:46 +02:00
|
|
|
void ResultsTree::showCppcheckResults(bool show)
|
|
|
|
{
|
|
|
|
mShowCppcheck = show;
|
|
|
|
refreshTree();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::showClangResults(bool show)
|
|
|
|
{
|
|
|
|
mShowClang = show;
|
|
|
|
refreshTree();
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::filterResults(const QString& filter)
|
2011-05-04 07:30:54 +02:00
|
|
|
{
|
|
|
|
mFilter = filter;
|
2017-07-28 11:54:20 +02:00
|
|
|
refreshTree();
|
2011-05-04 07:30:54 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::showHiddenResults()
|
2010-11-21 19:55:34 +01:00
|
|
|
{
|
|
|
|
//Clear the "hide" flag for each item
|
2018-02-15 22:37:10 +01:00
|
|
|
mHiddenMessageId.clear();
|
2022-10-02 07:12:40 +02:00
|
|
|
const int filecount = mModel.rowCount();
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int i = 0; i < filecount; i++) {
|
2017-08-02 19:09:03 +02:00
|
|
|
QStandardItem *fileItem = mModel.item(i, 0);
|
|
|
|
if (!fileItem)
|
2010-11-21 19:55:34 +01:00
|
|
|
continue;
|
|
|
|
|
2017-08-02 19:09:03 +02:00
|
|
|
QVariantMap data = fileItem->data().toMap();
|
2020-07-16 23:03:54 +02:00
|
|
|
data[HIDE] = false;
|
2017-08-02 19:09:03 +02:00
|
|
|
fileItem->setData(QVariant(data));
|
2010-11-21 19:55:34 +01:00
|
|
|
|
2022-10-02 07:12:40 +02:00
|
|
|
const int errorcount = fileItem->rowCount();
|
2011-10-13 20:53:06 +02:00
|
|
|
for (int j = 0; j < errorcount; j++) {
|
2017-08-02 19:09:03 +02:00
|
|
|
QStandardItem *child = fileItem->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();
|
2020-07-16 23:03:54 +02:00
|
|
|
data[HIDE] = false;
|
2010-11-21 19:55:34 +01:00
|
|
|
child->setData(QVariant(data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 11:54:20 +02:00
|
|
|
refreshTree();
|
|
|
|
emit resultsHidden(false);
|
2010-11-21 19:55:34 +01:00
|
|
|
}
|
|
|
|
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::refreshTree()
|
2009-03-22 18:39:44 +01:00
|
|
|
{
|
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
|
2022-10-02 07:12:40 +02:00
|
|
|
const int filecount = mModel.rowCount();
|
2009-05-23 10:17:27 +02:00
|
|
|
|
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
|
2017-08-02 19:09:03 +02:00
|
|
|
QStandardItem *fileItem = mModel.item(i, 0);
|
|
|
|
if (!fileItem) {
|
2009-05-23 10:17:27 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Get the amount of errors this file contains
|
2022-10-02 07:12:40 +02:00
|
|
|
const int errorcount = fileItem->rowCount();
|
2009-05-23 10:17:27 +02:00
|
|
|
|
|
|
|
//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
|
2017-08-02 19:09:03 +02:00
|
|
|
QStandardItem *child = fileItem->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
|
2020-07-16 23:03:54 +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()) {
|
2020-07-16 23:03:54 +02:00
|
|
|
if (!data[SUMMARY].toString().contains(mFilter, Qt::CaseInsensitive) &&
|
|
|
|
!data[MESSAGE].toString().contains(mFilter, Qt::CaseInsensitive) &&
|
|
|
|
!data[FILENAME].toString().contains(mFilter, Qt::CaseInsensitive) &&
|
|
|
|
!data[ERRORID].toString().contains(mFilter, Qt::CaseInsensitive)) {
|
2011-05-04 07:30:54 +02:00
|
|
|
hide = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-20 12:21:46 +02:00
|
|
|
// Tool filter
|
|
|
|
if (!hide) {
|
2020-07-16 23:03:54 +02:00
|
|
|
if (data[ERRORID].toString().startsWith("clang"))
|
2017-08-20 12:21:46 +02:00
|
|
|
hide = !mShowClang;
|
|
|
|
else
|
|
|
|
hide = !mShowCppcheck;
|
|
|
|
}
|
|
|
|
|
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
|
2017-08-02 19:09:03 +02:00
|
|
|
setRowHidden(j, fileItem->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
|
2017-08-02 19:09:03 +02:00
|
|
|
if (fileItem->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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
QStandardItem *ResultsTree::ensureFileItem(const QString &fullpath, const QString &file0, bool hide)
|
2009-03-22 18:39:44 +01:00
|
|
|
{
|
2017-07-28 11:54:20 +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.
|
2017-07-28 11:54:20 +02:00
|
|
|
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
|
2016-09-19 15:40:15 +02:00
|
|
|
name = QDir::toNativeSeparators(name);
|
2017-07-28 11:54:20 +02: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;
|
2020-07-16 23:03:54 +02:00
|
|
|
data[FILENAME] = fullpath;
|
|
|
|
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 13:26:04 +02:00
|
|
|
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;
|
2020-04-27 09:08:50 +02:00
|
|
|
|
2010-11-28 22:26:53 +01:00
|
|
|
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);
|
|
|
|
|
2017-07-28 05:18:43 +02:00
|
|
|
if (mContextItem && mApplications->getApplicationCount() > 0 && mContextItem->parent()) {
|
2016-01-16 15:19:06 +01:00
|
|
|
//Create an action for the application
|
2017-07-28 05:18:43 +02:00
|
|
|
int defaultApplicationIndex = mApplications->getDefaultApplication();
|
2016-01-16 15:19:06 +01:00
|
|
|
if (defaultApplicationIndex < 0)
|
|
|
|
defaultApplicationIndex = 0;
|
2017-07-28 05:18:43 +02:00
|
|
|
const Application& app = mApplications->getApplication(defaultApplicationIndex);
|
2016-01-16 15:19:06 +01:00
|
|
|
QAction *start = new QAction(app.getName(), &menu);
|
|
|
|
if (multipleSelection)
|
|
|
|
start->setDisabled(true);
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2016-01-16 15:19:06 +01:00
|
|
|
//Add it to our list so we can disconnect later on
|
|
|
|
actions << start;
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2016-01-16 15:19:06 +01:00
|
|
|
//Add it to context menu
|
|
|
|
menu.addAction(start);
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2016-01-16 15:19:06 +01:00
|
|
|
//Connect the signal to signal mapper
|
|
|
|
connect(start, SIGNAL(triggered()), signalMapper, SLOT(map()));
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2016-01-16 15:19:06 +01:00
|
|
|
//Add a new mapping
|
|
|
|
signalMapper->setMapping(start, defaultApplicationIndex);
|
2009-05-23 13:26:04 +02:00
|
|
|
|
|
|
|
connect(signalMapper, SIGNAL(mapped(int)),
|
2017-07-28 13:43:49 +02:00
|
|
|
this, SLOT(context(int)));
|
2009-06-14 14:09:52 +02:00
|
|
|
}
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2018-04-13 17:31:51 +02:00
|
|
|
// Add popup menuitems
|
2011-10-13 20:53:06 +02:00
|
|
|
if (mContextItem) {
|
2017-07-28 05:18:43 +02:00
|
|
|
if (mApplications->getApplicationCount() > 0) {
|
2009-06-14 14:09:52 +02:00
|
|
|
menu.addSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Create an action for the application
|
2015-12-23 10:28:07 +01:00
|
|
|
QAction *recheckSelectedFiles = new QAction(tr("Recheck"), &menu);
|
2018-04-13 17:31:51 +02:00
|
|
|
QAction *copy = new QAction(tr("Copy"), &menu);
|
2015-05-25 15:33:46 +02:00
|
|
|
QAction *hide = new QAction(tr("Hide"), &menu);
|
|
|
|
QAction *hideallid = new QAction(tr("Hide all with id"), &menu);
|
|
|
|
QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu);
|
2013-02-10 23:53:01 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (multipleSelection) {
|
2013-02-07 18:00:14 +01:00
|
|
|
hideallid->setDisabled(true);
|
2015-05-25 15:33:46 +02:00
|
|
|
opencontainingfolder->setDisabled(true);
|
2010-11-28 22:26:53 +01:00
|
|
|
}
|
2017-07-28 12:39:28 +02:00
|
|
|
if (mThread->isChecking())
|
2015-12-23 10:28:07 +01:00
|
|
|
recheckSelectedFiles->setDisabled(true);
|
|
|
|
else
|
|
|
|
recheckSelectedFiles->setDisabled(false);
|
2010-11-28 22:26:53 +01:00
|
|
|
|
2015-12-23 10:28:07 +01:00
|
|
|
menu.addAction(recheckSelectedFiles);
|
2017-08-18 17:25:08 +02:00
|
|
|
menu.addSeparator();
|
2018-04-13 17:31:51 +02:00
|
|
|
menu.addAction(copy);
|
2017-08-18 17:25:08 +02:00
|
|
|
menu.addSeparator();
|
2010-11-21 19:55:34 +01:00
|
|
|
menu.addAction(hide);
|
2013-02-07 18:00:14 +01:00
|
|
|
menu.addAction(hideallid);
|
2020-07-21 17:45:56 +02:00
|
|
|
|
2022-04-11 07:30:55 +02:00
|
|
|
QAction *suppress = new QAction(tr("Suppress selected id(s)"), &menu);
|
|
|
|
menu.addAction(suppress);
|
|
|
|
connect(suppress, &QAction::triggered, this, &ResultsTree::suppressSelectedIds);
|
|
|
|
|
2017-08-18 17:25:08 +02:00
|
|
|
menu.addSeparator();
|
2015-05-25 15:33:46 +02:00
|
|
|
menu.addAction(opencontainingfolder);
|
2009-06-14 14:09:52 +02:00
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
connect(recheckSelectedFiles, SIGNAL(triggered()), this, SLOT(recheckSelectedFiles()));
|
2018-04-13 17:31:51 +02:00
|
|
|
connect(copy, SIGNAL(triggered()), this, SLOT(copy()));
|
2017-07-28 13:43:49 +02:00
|
|
|
connect(hide, SIGNAL(triggered()), this, SLOT(hideResult()));
|
|
|
|
connect(hideallid, SIGNAL(triggered()), this, SLOT(hideAllIdResult()));
|
|
|
|
connect(opencontainingfolder, SIGNAL(triggered()), this, SLOT(openContainingFolder()));
|
2017-08-02 22:28:45 +02:00
|
|
|
|
2020-07-16 20:19:36 +02:00
|
|
|
const ProjectFile *currentProject = ProjectFile::getActiveProject();
|
|
|
|
if (currentProject && !currentProject->getTags().isEmpty()) {
|
2017-08-18 17:25:08 +02:00
|
|
|
menu.addSeparator();
|
|
|
|
QMenu *tagMenu = menu.addMenu(tr("Tag"));
|
|
|
|
{
|
2017-08-19 22:55:13 +02:00
|
|
|
QAction *action = new QAction(tr("No tag"), tagMenu);
|
|
|
|
tagMenu->addAction(action);
|
|
|
|
connect(action, &QAction::triggered, [=]() {
|
|
|
|
tagSelectedItems(QString());
|
|
|
|
});
|
2017-08-18 17:25:08 +02:00
|
|
|
}
|
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString& tagstr : currentProject->getTags()) {
|
2017-08-18 17:25:08 +02:00
|
|
|
QAction *action = new QAction(tagstr, tagMenu);
|
|
|
|
tagMenu->addAction(action);
|
2017-08-19 22:55:13 +02:00
|
|
|
connect(action, &QAction::triggered, [=]() {
|
|
|
|
tagSelectedItems(tagstr);
|
|
|
|
});
|
2017-08-18 17:25:08 +02:00
|
|
|
}
|
|
|
|
}
|
2009-06-14 14:09:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Start the menu
|
|
|
|
menu.exec(e->globalPos());
|
2015-12-23 10:28:07 +01:00
|
|
|
index = indexAt(e->pos());
|
|
|
|
if (index.isValid()) {
|
|
|
|
mContextItem = mModel.itemFromIndex(index);
|
2017-07-28 05:18:43 +02:00
|
|
|
if (mContextItem && mApplications->getApplicationCount() > 0 && mContextItem->parent()) {
|
2015-12-23 10:28:07 +01:00
|
|
|
//Disconnect all signals
|
2023-08-05 18:48:43 +02:00
|
|
|
for (const QAction* action : actions) {
|
2020-09-21 19:30:47 +02:00
|
|
|
disconnect(action, SIGNAL(triggered()), signalMapper, SLOT(map()));
|
2015-12-23 10:28:07 +01:00
|
|
|
}
|
2009-05-23 13:26:04 +02:00
|
|
|
|
2015-12-23 10:28:07 +01:00
|
|
|
disconnect(signalMapper, SIGNAL(mapped(int)),
|
2017-07-28 13:43:49 +02:00
|
|
|
this, SLOT(context(int)));
|
2015-12-23 10:28:07 +01:00
|
|
|
//And remove the signal mapper
|
|
|
|
delete signalMapper;
|
2009-05-23 13:26:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-06 09:57:16 +02:00
|
|
|
void ResultsTree::startApplication(const 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
|
2017-07-28 05:18:43 +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)
|
2017-07-28 05:18:43 +02:00
|
|
|
application = mApplications->getDefaultApplication();
|
2011-02-25 11:16:20 +01:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:18:43 +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
|
2020-07-16 23:03:54 +02:00
|
|
|
QString file = data[FILENAME].toString();
|
2011-07-17 13:22:06 +02:00
|
|
|
file = QDir::toNativeSeparators(file);
|
|
|
|
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 {
|
2017-07-28 11:54:20 +02:00
|
|
|
QString dir = askFileDir(file);
|
2010-07-11 15:20:19 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-07-28 05:18:43 +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
|
|
|
|
2020-07-16 23:03:54 +02: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
|
|
|
|
2020-07-16 23:03:54 +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.
|
2015-10-05 21:39:46 +02:00
|
|
|
#ifdef Q_OS_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("\"");
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 21:39:46 +02:00
|
|
|
#endif // Q_OS_WIN
|
2011-04-02 11:27:26 +02:00
|
|
|
|
2011-04-01 23:53:26 +02:00
|
|
|
const QString cmdLine = QString("%1 %2").arg(program).arg(params);
|
|
|
|
|
2022-05-15 12:42:29 +02:00
|
|
|
// this is reported as deprecated in Qt 5.15.2 but no longer in Qt 6
|
2023-08-16 19:35:53 +02:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
|
|
|
SUPPRESS_WARNING_CLANG_PUSH("-Wdeprecated")
|
|
|
|
SUPPRESS_WARNING_GCC_PUSH("-Wdeprecated-declarations")
|
|
|
|
#endif
|
|
|
|
const bool success = QProcess::startDetached(cmdLine);
|
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
|
|
|
SUPPRESS_WARNING_GCC_POP
|
|
|
|
SUPPRESS_WARNING_CLANG_POP
|
|
|
|
#endif
|
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
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
QString ResultsTree::askFileDir(const QString &file)
|
2010-07-11 13:22:55 +02:00
|
|
|
{
|
2018-02-20 22:23:02 +01:00
|
|
|
QString text = tr("Could not find file:") + '\n' + file + '\n';
|
|
|
|
QString title;
|
|
|
|
if (file.indexOf('/')) {
|
|
|
|
QString folderName = file.mid(0, file.indexOf('/'));
|
|
|
|
text += tr("Please select the folder '%1'").arg(folderName);
|
|
|
|
title = tr("Select Directory '%1'").arg(folderName);
|
|
|
|
} else {
|
|
|
|
text += tr("Please select the directory where file is located.");
|
|
|
|
title = tr("Select Directory");
|
|
|
|
}
|
|
|
|
|
2010-07-11 13:22:55 +02:00
|
|
|
QMessageBox msgbox(this);
|
|
|
|
msgbox.setWindowTitle("Cppcheck");
|
|
|
|
msgbox.setText(text);
|
|
|
|
msgbox.setIcon(QMessageBox::Warning);
|
|
|
|
msgbox.exec();
|
2013-02-19 21:39:50 +01:00
|
|
|
|
2018-02-20 22:23:02 +01:00
|
|
|
QString dir = QFileDialog::getExistingDirectory(this, title,
|
2021-08-07 20:51:18 +02:00
|
|
|
getPath(SETTINGS_LAST_SOURCE_PATH),
|
|
|
|
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
2018-02-20 22:23:02 +01:00
|
|
|
|
|
|
|
if (dir.isEmpty())
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
// User selected root path
|
2023-08-22 12:01:30 +02:00
|
|
|
if (QFileInfo::exists(dir + '/' + file))
|
2018-02-20 22:23:02 +01:00
|
|
|
mCheckPath = dir;
|
|
|
|
|
|
|
|
// user selected checked folder
|
|
|
|
else if (file.indexOf('/') > 0) {
|
|
|
|
dir += '/';
|
|
|
|
QString folderName = file.mid(0, file.indexOf('/'));
|
|
|
|
if (dir.indexOf('/' + folderName + '/'))
|
|
|
|
dir = dir.mid(0, dir.lastIndexOf('/' + folderName + '/'));
|
2023-08-22 12:01:30 +02:00
|
|
|
if (QFileInfo::exists(dir + '/' + file))
|
2018-02-20 22:23:02 +01:00
|
|
|
mCheckPath = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise; return
|
|
|
|
else
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
setPath(SETTINGS_LAST_SOURCE_PATH, mCheckPath);
|
|
|
|
return mCheckPath;
|
2010-07-11 13:22:55 +02:00
|
|
|
}
|
|
|
|
|
2018-04-13 17:31:51 +02:00
|
|
|
void ResultsTree::copy()
|
2009-06-14 14:09:52 +02:00
|
|
|
{
|
2018-04-13 17:31:51 +02:00
|
|
|
if (!mSelectionModel)
|
2018-03-06 15:34:14 +01:00
|
|
|
return;
|
2009-12-06 17:46:24 +01:00
|
|
|
|
2018-04-13 17:31:51 +02:00
|
|
|
QString text;
|
2022-03-21 17:14:26 +01:00
|
|
|
for (QModelIndex index : mSelectionModel->selectedRows()) {
|
2018-04-13 17:31:51 +02:00
|
|
|
QStandardItem *item = mModel.itemFromIndex(index);
|
2019-07-15 12:58:25 +02:00
|
|
|
if (!item->parent()) {
|
|
|
|
text += item->text() + '\n';
|
2018-04-13 17:31:51 +02:00
|
|
|
continue;
|
2019-07-15 12:58:25 +02:00
|
|
|
}
|
2018-04-13 17:31:51 +02:00
|
|
|
if (item->parent()->parent())
|
|
|
|
item = item->parent();
|
|
|
|
QVariantMap data = item->data().toMap();
|
|
|
|
if (!data.contains("id"))
|
|
|
|
continue;
|
2020-07-16 23:03:54 +02:00
|
|
|
QString inconclusive = data[INCONCLUSIVE].toBool() ? ",inconclusive" : "";
|
|
|
|
text += '[' + data[FILENAME].toString() + ':' + QString::number(data[LINE].toInt())
|
2018-04-13 19:57:48 +02:00
|
|
|
+ "] ("
|
2023-10-12 11:58:39 +02:00
|
|
|
+ QString::fromStdString(severityToString(ShowTypes::ShowTypeToSeverity((ShowTypes::ShowType)data[SEVERITY].toInt()))) + inconclusive
|
2018-04-13 19:57:48 +02:00
|
|
|
+ ") "
|
2020-07-16 23:03:54 +02:00
|
|
|
+ data[MESSAGE].toString()
|
2018-04-13 19:57:48 +02:00
|
|
|
+ " ["
|
2020-07-16 23:03:54 +02:00
|
|
|
+ data[ERRORID].toString()
|
2018-04-13 19:57:48 +02:00
|
|
|
+ "]\n";
|
2009-12-06 17:46:24 +01:00
|
|
|
}
|
2018-03-06 15:34:14 +01:00
|
|
|
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
2018-04-13 17:31:51 +02:00
|
|
|
clipboard->setText(text);
|
2012-11-03 21:41:42 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::hideResult()
|
2010-11-21 19:55:34 +01:00
|
|
|
{
|
2010-11-28 22:26:53 +01:00
|
|
|
if (!mSelectionModel)
|
|
|
|
return;
|
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (QModelIndex index : mSelectionModel->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();
|
2020-07-16 23:03:54 +02:00
|
|
|
data[HIDE] = true;
|
2010-11-28 22:26:53 +01:00
|
|
|
item->setData(QVariant(data));
|
2010-11-21 19:55:34 +01:00
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
refreshTree();
|
|
|
|
emit resultsHidden(true);
|
2010-11-21 19:55:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::recheckSelectedFiles()
|
2015-12-23 10:28:07 +01:00
|
|
|
{
|
|
|
|
if (!mSelectionModel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QStringList selectedItems;
|
2022-03-21 17:14:26 +01:00
|
|
|
for (QModelIndex index : mSelectionModel->selectedRows()) {
|
2015-12-23 10:28:07 +01:00
|
|
|
QStandardItem *item = mModel.itemFromIndex(index);
|
2015-12-29 01:38:36 +01:00
|
|
|
while (item->parent())
|
|
|
|
item = item->parent();
|
2015-12-23 10:28:07 +01:00
|
|
|
QVariantMap data = item->data().toMap();
|
2020-07-16 23:03:54 +02:00
|
|
|
QString currentFile = data[FILENAME].toString();
|
2016-01-15 16:52:22 +01:00
|
|
|
if (!currentFile.isEmpty()) {
|
|
|
|
QString fileNameWithCheckPath;
|
|
|
|
QFileInfo curfileInfo(currentFile);
|
|
|
|
if (!curfileInfo.exists() && !mCheckPath.isEmpty() && currentFile.indexOf(mCheckPath) != 0)
|
|
|
|
fileNameWithCheckPath = mCheckPath + "/" + currentFile;
|
|
|
|
else
|
|
|
|
fileNameWithCheckPath = currentFile;
|
|
|
|
const QFileInfo fileInfo(fileNameWithCheckPath);
|
|
|
|
if (!fileInfo.exists()) {
|
2017-07-28 11:54:20 +02:00
|
|
|
askFileDir(currentFile);
|
2016-01-15 16:52:22 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Path::isHeader(currentFile.toStdString())) {
|
2020-07-16 23:03:54 +02:00
|
|
|
if (!data[FILE0].toString().isEmpty() && !selectedItems.contains(data[FILE0].toString())) {
|
|
|
|
selectedItems<<((!mCheckPath.isEmpty() && (data[FILE0].toString().indexOf(mCheckPath) != 0)) ? (mCheckPath + "/" + data[FILE0].toString()) : data[FILE0].toString());
|
2016-01-15 16:52:22 +01:00
|
|
|
if (!selectedItems.contains(fileNameWithCheckPath))
|
|
|
|
selectedItems<<fileNameWithCheckPath;
|
|
|
|
}
|
|
|
|
} else if (!selectedItems.contains(fileNameWithCheckPath))
|
|
|
|
selectedItems<<fileNameWithCheckPath;
|
2015-12-29 01:38:36 +01:00
|
|
|
}
|
2015-12-23 10:28:07 +01:00
|
|
|
}
|
2017-07-28 11:54:20 +02:00
|
|
|
emit checkSelected(selectedItems);
|
2015-12-23 10:28:07 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::hideAllIdResult()
|
2013-02-07 18:00:14 +01:00
|
|
|
{
|
2018-02-15 21:29:18 +01:00
|
|
|
if (!mContextItem || !mContextItem->parent())
|
|
|
|
return;
|
2013-02-07 18:00:14 +01:00
|
|
|
|
2018-02-15 21:29:18 +01:00
|
|
|
// 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();
|
2013-02-07 18:00:14 +01:00
|
|
|
|
2020-07-16 23:03:54 +02:00
|
|
|
QString messageId = data[ERRORID].toString();
|
2013-02-10 23:53:01 +01:00
|
|
|
|
2018-02-15 22:37:10 +01:00
|
|
|
mHiddenMessageId.append(messageId);
|
|
|
|
|
2018-02-15 21:29:18 +01:00
|
|
|
// hide all errors with that message Id
|
2022-10-02 07:12:40 +02:00
|
|
|
const int filecount = mModel.rowCount();
|
2018-02-15 21:29:18 +01:00
|
|
|
for (int i = 0; i < filecount; i++) {
|
|
|
|
//Get file i
|
|
|
|
QStandardItem *file = mModel.item(i, 0);
|
|
|
|
if (!file) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-07 18:00:14 +01:00
|
|
|
|
2018-02-15 21:29:18 +01:00
|
|
|
//Get the amount of errors this file contains
|
2022-10-02 07:12:40 +02:00
|
|
|
const int errorcount = file->rowCount();
|
2013-02-10 23:53:01 +01:00
|
|
|
|
2018-02-15 21:29:18 +01:00
|
|
|
for (int j = 0; j < errorcount; j++) {
|
|
|
|
//Get the error itself
|
|
|
|
QStandardItem *child = file->child(j, 0);
|
|
|
|
if (!child) {
|
|
|
|
continue;
|
2013-02-07 18:00:14 +01:00
|
|
|
}
|
|
|
|
|
2018-02-15 21:29:18 +01:00
|
|
|
QVariantMap userdata = child->data().toMap();
|
2020-07-16 23:03:54 +02:00
|
|
|
if (userdata[ERRORID].toString() == messageId) {
|
|
|
|
userdata[HIDE] = true;
|
2018-02-15 21:29:18 +01:00
|
|
|
child->setData(QVariant(userdata));
|
|
|
|
}
|
|
|
|
}
|
2013-02-07 18:00:14 +01:00
|
|
|
}
|
2018-02-15 21:29:18 +01:00
|
|
|
|
|
|
|
refreshTree();
|
|
|
|
emit resultsHidden(true);
|
2013-02-07 18:00:14 +01:00
|
|
|
}
|
|
|
|
|
2017-08-11 07:45:29 +02:00
|
|
|
void ResultsTree::suppressSelectedIds()
|
|
|
|
{
|
|
|
|
if (!mSelectionModel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QSet<QString> selectedIds;
|
2022-03-21 17:14:26 +01:00
|
|
|
for (QModelIndex index : mSelectionModel->selectedRows()) {
|
2017-08-11 07:45:29 +02:00
|
|
|
QStandardItem *item = mModel.itemFromIndex(index);
|
|
|
|
if (!item->parent())
|
|
|
|
continue;
|
|
|
|
if (item->parent()->parent())
|
|
|
|
item = item->parent();
|
|
|
|
QVariantMap data = item->data().toMap();
|
|
|
|
if (!data.contains("id"))
|
|
|
|
continue;
|
2020-07-16 23:03:54 +02:00
|
|
|
selectedIds << data[ERRORID].toString();
|
2017-08-11 07:45:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// delete all errors with selected message Ids
|
|
|
|
for (int i = 0; i < mModel.rowCount(); i++) {
|
|
|
|
QStandardItem * const file = mModel.item(i, 0);
|
2017-08-14 00:23:21 +02:00
|
|
|
for (int j = 0; j < file->rowCount();) {
|
2017-08-11 07:45:29 +02:00
|
|
|
QStandardItem *errorItem = file->child(j, 0);
|
|
|
|
QVariantMap userdata = errorItem->data().toMap();
|
2020-07-16 23:03:54 +02:00
|
|
|
if (selectedIds.contains(userdata[ERRORID].toString())) {
|
2017-08-11 07:45:29 +02:00
|
|
|
file->removeRow(j);
|
|
|
|
} else {
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
2020-07-15 13:03:07 +02:00
|
|
|
if (file->rowCount() == 0)
|
|
|
|
mModel.removeRow(file->row());
|
2017-08-11 07:45:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-01 17:26:16 +01:00
|
|
|
emit suppressIds(selectedIds.values());
|
2017-08-11 07:45:29 +02:00
|
|
|
}
|
|
|
|
|
2020-07-21 11:27:03 +02:00
|
|
|
void ResultsTree::suppressHash()
|
2020-07-15 13:03:07 +02:00
|
|
|
{
|
|
|
|
if (!mSelectionModel)
|
|
|
|
return;
|
2020-07-15 20:55:04 +02:00
|
|
|
|
|
|
|
// Extract selected warnings
|
|
|
|
QSet<QStandardItem *> selectedWarnings;
|
2022-03-21 17:14:26 +01:00
|
|
|
for (QModelIndex index : mSelectionModel->selectedRows()) {
|
2020-07-15 13:03:07 +02:00
|
|
|
QStandardItem *item = mModel.itemFromIndex(index);
|
|
|
|
if (!item->parent())
|
|
|
|
continue;
|
|
|
|
while (item->parent()->parent())
|
|
|
|
item = item->parent();
|
2020-07-15 20:55:04 +02:00
|
|
|
selectedWarnings.insert(item);
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:36:55 +02:00
|
|
|
bool changed = false;
|
2020-07-15 20:55:04 +02:00
|
|
|
ProjectFile *projectFile = ProjectFile::getActiveProject();
|
|
|
|
for (QStandardItem *item: selectedWarnings) {
|
|
|
|
QStandardItem *fileItem = item->parent();
|
2020-07-15 13:03:07 +02:00
|
|
|
const QVariantMap data = item->data().toMap();
|
2020-07-21 11:27:03 +02:00
|
|
|
if (projectFile && data.contains(HASH)) {
|
2020-07-16 16:36:55 +02:00
|
|
|
Suppressions::Suppression suppression;
|
2020-07-21 11:27:03 +02:00
|
|
|
suppression.hash = data[HASH].toULongLong();
|
2020-07-16 23:03:54 +02:00
|
|
|
suppression.errorId = data[ERRORID].toString().toStdString();
|
|
|
|
suppression.fileName = data[FILENAME].toString().toStdString();
|
|
|
|
suppression.lineNumber = data[LINE].toInt();
|
2020-07-16 16:36:55 +02:00
|
|
|
projectFile->addSuppression(suppression);
|
|
|
|
changed = true;
|
|
|
|
}
|
2020-07-15 13:03:07 +02:00
|
|
|
fileItem->removeRow(item->row());
|
|
|
|
if (fileItem->rowCount() == 0)
|
|
|
|
mModel.removeRow(fileItem->row());
|
|
|
|
}
|
2020-07-16 16:36:55 +02:00
|
|
|
|
|
|
|
if (changed)
|
|
|
|
projectFile->write();
|
2020-07-15 13:03:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::openContainingFolder()
|
2015-05-25 15:33:46 +02:00
|
|
|
{
|
2017-07-28 11:54:20 +02:00
|
|
|
QString filePath = getFilePath(mContextItem, true);
|
2015-05-25 21:15:55 +02:00
|
|
|
if (!filePath.isEmpty()) {
|
2015-05-25 15:33:46 +02:00
|
|
|
filePath = QFileInfo(filePath).absolutePath();
|
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-18 17:25:08 +02:00
|
|
|
void ResultsTree::tagSelectedItems(const QString &tag)
|
2017-08-02 22:28:45 +02:00
|
|
|
{
|
|
|
|
if (!mSelectionModel)
|
|
|
|
return;
|
|
|
|
bool isTagged = false;
|
2020-07-16 23:03:54 +02:00
|
|
|
ProjectFile *currentProject = ProjectFile::getActiveProject();
|
2022-03-21 17:14:26 +01:00
|
|
|
for (QModelIndex index : mSelectionModel->selectedRows()) {
|
2017-08-02 22:28:45 +02:00
|
|
|
QStandardItem *item = mModel.itemFromIndex(index);
|
|
|
|
QVariantMap data = item->data().toMap();
|
2017-08-18 17:25:08 +02:00
|
|
|
if (data.contains("tags")) {
|
2020-07-16 23:03:54 +02:00
|
|
|
data[TAGS] = tag;
|
2017-08-02 22:28:45 +02:00
|
|
|
item->setData(QVariant(data));
|
2017-08-18 17:25:08 +02:00
|
|
|
item->parent()->child(index.row(), COLUMN_TAGS)->setText(tag);
|
2020-07-21 11:27:03 +02:00
|
|
|
if (currentProject && data.contains(HASH)) {
|
2020-07-16 23:03:54 +02:00
|
|
|
isTagged = true;
|
2020-07-21 11:27:03 +02:00
|
|
|
currentProject->setWarningTags(data[HASH].toULongLong(), tag);
|
2020-07-16 23:03:54 +02:00
|
|
|
}
|
2017-08-02 22:28:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isTagged)
|
2020-07-16 23:03:54 +02:00
|
|
|
currentProject->write();
|
2017-08-02 22:28:45 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::context(int application)
|
2009-05-23 17:45:05 +02:00
|
|
|
{
|
2017-07-28 11:54:20 +02:00
|
|
|
startApplication(mContextItem, application);
|
2009-05-23 17:45:05 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::quickStartApplication(const QModelIndex &index)
|
2009-05-23 17:45:05 +02:00
|
|
|
{
|
2017-07-28 11:54:20 +02:00
|
|
|
startApplication(mModel.itemFromIndex(index));
|
2009-05-23 17:45:05 +02:00
|
|
|
}
|
2009-05-26 17:21:39 +02:00
|
|
|
|
2023-10-06 09:57:16 +02:00
|
|
|
QString ResultsTree::getFilePath(const QStandardItem *target, bool fullPath)
|
2009-06-14 14:09:52 +02:00
|
|
|
{
|
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();
|
|
|
|
|
|
|
|
//Replace (file) with filename
|
2020-07-16 23:03:54 +02:00
|
|
|
QString file = data[FILENAME].toString();
|
2023-10-18 10:06:17 +02:00
|
|
|
QString 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
|
|
|
}
|
|
|
|
|
2015-05-25 15:33:46 +02:00
|
|
|
return pathStr;
|
2009-06-14 14:09:52 +02:00
|
|
|
}
|
2015-05-25 15:33:46 +02:00
|
|
|
|
|
|
|
return QString();
|
2009-06-14 14:09:52 +02:00
|
|
|
}
|
|
|
|
|
2023-10-12 11:58:39 +02:00
|
|
|
QString ResultsTree::severityToIcon(Severity severity)
|
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:
|
2017-08-03 12:39:31 +02:00
|
|
|
return QString();
|
2011-03-07 22:11:59 +01:00
|
|
|
}
|
2009-05-26 17:21:39 +02:00
|
|
|
}
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::saveResults(Report *report) const
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2017-07-28 11:12:05 +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++) {
|
2017-08-02 12:45:57 +02:00
|
|
|
if (mSaveAllErrors || !isRowHidden(i, QModelIndex()))
|
|
|
|
saveErrors(report, mModel.item(i, 0));
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 11:12:05 +02:00
|
|
|
report->writeFooter();
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
2020-07-14 18:19:03 +02:00
|
|
|
void ResultsTree::saveErrors(Report *report, const QStandardItem *fileItem) const
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2017-08-02 19:09:03 +02:00
|
|
|
if (!fileItem) {
|
2009-06-03 20:18:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-02 19:09:03 +02:00
|
|
|
for (int i = 0; i < fileItem->rowCount(); i++) {
|
|
|
|
const QStandardItem *error = fileItem->child(i, 0);
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!error) {
|
2009-06-03 20:18:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-08-02 19:09:03 +02:00
|
|
|
if (isRowHidden(i, fileItem->index()) && !mSaveAllErrors) {
|
2009-06-03 20:18:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-07-10 17:20:45 +02:00
|
|
|
ErrorItem item;
|
2017-08-02 12:45:57 +02:00
|
|
|
readErrorItem(error, &item);
|
2009-11-19 23:43:46 +01:00
|
|
|
|
2017-08-02 12:45:57 +02:00
|
|
|
report->writeError(item);
|
|
|
|
}
|
|
|
|
}
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2017-08-02 20:24:23 +02:00
|
|
|
static int indexOf(const QList<ErrorItem> &list, const ErrorItem &item)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
2018-10-20 16:30:40 +02:00
|
|
|
if (ErrorItem::sameCID(item, list[i])) {
|
2017-08-02 20:24:23 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsTree::updateFromOldReport(const QString &filename)
|
|
|
|
{
|
|
|
|
QList<ErrorItem> oldErrors;
|
|
|
|
XmlReportV2 oldReport(filename);
|
|
|
|
if (oldReport.open()) {
|
|
|
|
oldErrors = oldReport.read();
|
|
|
|
oldReport.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read current results..
|
|
|
|
for (int i = 0; i < mModel.rowCount(); i++) {
|
|
|
|
QStandardItem *fileItem = mModel.item(i,0);
|
|
|
|
for (int j = 0; j < fileItem->rowCount(); j++) {
|
|
|
|
QStandardItem *error = fileItem->child(j,0);
|
|
|
|
ErrorItem errorItem;
|
|
|
|
readErrorItem(error, &errorItem);
|
2022-10-02 07:12:40 +02:00
|
|
|
const int oldErrorIndex = indexOf(oldErrors, errorItem);
|
2017-08-02 20:24:23 +02:00
|
|
|
QVariantMap data = error->data().toMap();
|
|
|
|
|
|
|
|
// New error .. set the "sinceDate" property
|
2017-08-03 23:27:18 +02:00
|
|
|
if (oldErrorIndex >= 0 && !oldErrors[oldErrorIndex].sinceDate.isEmpty()) {
|
2020-07-16 23:03:54 +02:00
|
|
|
data[SINCEDATE] = oldErrors[oldErrorIndex].sinceDate;
|
2017-08-03 23:27:18 +02:00
|
|
|
error->setData(data);
|
|
|
|
fileItem->child(j, COLUMN_SINCE_DATE)->setText(oldErrors[oldErrorIndex].sinceDate);
|
2020-07-16 23:03:54 +02:00
|
|
|
} else if (oldErrorIndex < 0 || data[SINCEDATE].toString().isEmpty()) {
|
2022-03-22 21:44:41 +01:00
|
|
|
const QString sinceDate = QLocale::system().dateFormat(QLocale::ShortFormat);
|
2020-07-16 23:03:54 +02:00
|
|
|
data[SINCEDATE] = sinceDate;
|
2017-08-02 20:24:23 +02:00
|
|
|
error->setData(data);
|
|
|
|
fileItem->child(j, COLUMN_SINCE_DATE)->setText(sinceDate);
|
|
|
|
if (oldErrorIndex < 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-08-18 17:25:08 +02:00
|
|
|
if (!errorItem.tags.isEmpty())
|
2017-08-02 20:24:23 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
const ErrorItem &oldErrorItem = oldErrors[oldErrorIndex];
|
2020-07-16 23:03:54 +02:00
|
|
|
data[TAGS] = oldErrorItem.tags;
|
2017-08-02 20:24:23 +02:00
|
|
|
error->setData(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:34:06 +02:00
|
|
|
void ResultsTree::readErrorItem(const QStandardItem *error, ErrorItem *item) const
|
|
|
|
{
|
2017-08-02 20:24:23 +02:00
|
|
|
// Get error's user data
|
|
|
|
QVariantMap data = error->data().toMap();
|
2017-08-02 12:45:57 +02:00
|
|
|
|
2020-07-16 23:03:54 +02:00
|
|
|
item->severity = ShowTypes::ShowTypeToSeverity(ShowTypes::VariantToShowType(data[SEVERITY]));
|
|
|
|
item->summary = data[SUMMARY].toString();
|
|
|
|
item->message = data[MESSAGE].toString();
|
|
|
|
item->errorId = data[ERRORID].toString();
|
|
|
|
item->cwe = data[CWE].toInt();
|
2020-07-21 11:27:03 +02:00
|
|
|
item->hash = data[HASH].toULongLong();
|
2020-07-16 23:03:54 +02:00
|
|
|
item->inconclusive = data[INCONCLUSIVE].toBool();
|
|
|
|
item->file0 = data[FILE0].toString();
|
|
|
|
item->sinceDate = data[SINCEDATE].toString();
|
|
|
|
item->tags = data[TAGS].toString();
|
2017-08-02 12:45:57 +02:00
|
|
|
|
|
|
|
if (error->rowCount() == 0) {
|
|
|
|
QErrorPathItem e;
|
2020-07-16 23:03:54 +02:00
|
|
|
e.file = stripPath(data[FILENAME].toString(), true);
|
|
|
|
e.line = data[LINE].toInt();
|
|
|
|
e.info = data[MESSAGE].toString();
|
2017-08-02 12:45:57 +02:00
|
|
|
item->errorPath << e;
|
|
|
|
}
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2017-08-02 12:45:57 +02:00
|
|
|
for (int j = 0; j < error->rowCount(); j++) {
|
|
|
|
const 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();
|
|
|
|
|
|
|
|
QErrorPathItem e;
|
2020-07-16 23:03:54 +02:00
|
|
|
e.file = stripPath(child_data[FILENAME].toString(), true);
|
2021-07-22 19:55:23 +02:00
|
|
|
e.line = child_data[LINE].toInt();
|
2020-07-16 23:03:54 +02:00
|
|
|
e.info = child_data[MESSAGE].toString();
|
2017-08-02 12:45:57 +02:00
|
|
|
item->errorPath << e;
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::updateSettings(bool showFullPath,
|
2009-06-03 20:18:22 +02:00
|
|
|
bool saveFullPath,
|
2012-10-27 11:16:52 +02:00
|
|
|
bool saveAllErrors,
|
2015-10-15 11:59:17 +02:00
|
|
|
bool showErrorId,
|
|
|
|
bool showInconclusive)
|
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;
|
2017-07-28 11:54:20 +02:00
|
|
|
refreshFilePaths();
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mSaveFullPath = saveFullPath;
|
|
|
|
mSaveAllErrors = saveAllErrors;
|
2012-10-27 11:16:52 +02:00
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
showIdColumn(showErrorId);
|
|
|
|
showInconclusiveColumn(showInconclusive);
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::setCheckDirectory(const QString &dir)
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
|
|
|
mCheckPath = dir;
|
|
|
|
}
|
|
|
|
|
2016-01-15 16:52:22 +01:00
|
|
|
|
2020-03-07 11:33:08 +01:00
|
|
|
QString ResultsTree::getCheckDirectory()
|
2016-01-15 16:52:22 +01:00
|
|
|
{
|
|
|
|
return mCheckPath;
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +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);
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::refreshFilePaths(QStandardItem *item)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//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
|
2020-07-16 23:03:54 +02:00
|
|
|
QString file = data[FILENAME].toString();
|
2009-06-03 20:18:22 +02:00
|
|
|
|
|
|
|
//Update this error's text
|
2017-07-28 11:54:20 +02: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;
|
|
|
|
}
|
2013-06-26 09:47:02 +02:00
|
|
|
//Get child's user data
|
2009-11-19 23:43:46 +01:00
|
|
|
QVariant child_userdata = child->data();
|
|
|
|
//Convert it to QVariantMap
|
|
|
|
QVariantMap child_data = child_userdata.toMap();
|
|
|
|
|
|
|
|
//Get list of files
|
2020-07-16 23:03:54 +02:00
|
|
|
QString child_files = child_data[FILENAME].toString();
|
2009-06-03 20:18:22 +02:00
|
|
|
//Update file's path
|
2017-07-28 11:54:20 +02: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());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::refreshFilePaths()
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
|
|
|
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++) {
|
2017-07-28 11:54:20 +02:00
|
|
|
refreshFilePaths(mModel.item(i, 0));
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
}
|
2009-06-09 09:51:27 +02:00
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
bool ResultsTree::hasVisibleResults() const
|
2009-06-09 09:51:27 +02:00
|
|
|
{
|
|
|
|
return mVisibleErrors;
|
|
|
|
}
|
2009-06-20 22:42:12 +02:00
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
bool ResultsTree::hasResults() const
|
2009-06-20 22:42:12 +02:00
|
|
|
{
|
|
|
|
return mModel.rowCount() > 0;
|
|
|
|
}
|
2009-07-02 10:32:29 +02:00
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::translate()
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
|
|
|
QStringList labels;
|
2017-08-02 20:24:23 +02:00
|
|
|
labels << tr("File") << tr("Severity") << tr("Line") << tr("Id") << tr("Inconclusive") << tr("Summary") << tr("Since date") << tr("Tag");
|
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
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::showIdColumn(bool show)
|
2012-10-27 11:16:52 +02:00
|
|
|
{
|
|
|
|
mShowErrorId = show;
|
|
|
|
if (show)
|
|
|
|
showColumn(3);
|
|
|
|
else
|
|
|
|
hideColumn(3);
|
|
|
|
}
|
|
|
|
|
2017-07-28 11:54:20 +02:00
|
|
|
void ResultsTree::showInconclusiveColumn(bool show)
|
2015-10-15 11:59:17 +02:00
|
|
|
{
|
|
|
|
if (show)
|
|
|
|
showColumn(4);
|
|
|
|
else
|
|
|
|
hideColumn(4);
|
|
|
|
}
|
|
|
|
|
2010-11-23 21:37:31 +01:00
|
|
|
void ResultsTree::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
{
|
|
|
|
QTreeView::currentChanged(current, previous);
|
2019-06-05 10:13:37 +02:00
|
|
|
emit treeSelectionChanged(current);
|
2010-11-23 21:37:31 +01:00
|
|
|
}
|