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 "resultsview.h"
|
|
|
|
|
2022-02-02 16:17:28 +01:00
|
|
|
#include "checkstatistics.h"
|
2023-08-31 18:28:47 +02:00
|
|
|
#include "checkersreport.h"
|
2022-04-13 12:24:00 +02:00
|
|
|
#include "codeeditor.h"
|
2022-02-02 16:17:28 +01:00
|
|
|
#include "codeeditorstyle.h"
|
2011-07-28 08:30:45 +02:00
|
|
|
#include "common.h"
|
2022-02-02 16:17:28 +01:00
|
|
|
#include "csvreport.h"
|
2010-07-14 13:24:46 +02:00
|
|
|
#include "erroritem.h"
|
2023-10-09 10:07:20 +02:00
|
|
|
#include "errorlogger.h"
|
|
|
|
#include "errortypes.h"
|
2022-02-02 16:17:28 +01:00
|
|
|
#include "path.h"
|
|
|
|
#include "printablereport.h"
|
2022-04-13 12:24:00 +02:00
|
|
|
#include "resultstree.h"
|
2023-10-09 10:07:20 +02:00
|
|
|
#include "settings.h"
|
2009-06-24 09:54:56 +02:00
|
|
|
#include "txtreport.h"
|
|
|
|
#include "xmlreport.h"
|
2011-02-03 20:40:35 +01:00
|
|
|
#include "xmlreportv2.h"
|
2022-02-02 16:17:28 +01:00
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
#include "ui_resultsview.h"
|
|
|
|
|
2023-10-09 10:07:20 +02:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QByteArray>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QClipboard>
|
|
|
|
#include <QDate>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QDateTime>
|
|
|
|
#include <QDialog>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QDir>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QIODevice>
|
2023-10-09 10:07:20 +02:00
|
|
|
#include <QLabel>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QList>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QListWidgetItem>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QPoint>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QPrintDialog>
|
|
|
|
#include <QPrintPreviewDialog>
|
|
|
|
#include <QPrinter>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QProgressBar>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QSettings>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QSplitter>
|
|
|
|
#include <QStandardItem>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QStandardItemModel>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QTextDocument>
|
|
|
|
#include <QTextEdit>
|
|
|
|
#include <QTextStream>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QVariant>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QVariantMap>
|
|
|
|
#include <Qt>
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
ResultsView::ResultsView(QWidget * parent) :
|
2010-04-15 20:08:51 +02:00
|
|
|
QWidget(parent),
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI(new Ui::ResultsView),
|
2010-11-29 23:01:45 +01:00
|
|
|
mStatistics(new CheckStatistics(this))
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->setupUi(this);
|
2010-11-24 09:48:07 +01:00
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
connect(mUI->mTree, &ResultsTree::resultsHidden, this, &ResultsView::resultsHidden);
|
|
|
|
connect(mUI->mTree, &ResultsTree::checkSelected, this, &ResultsView::checkSelected);
|
|
|
|
connect(mUI->mTree, &ResultsTree::treeSelectionChanged, this, &ResultsView::updateDetails);
|
|
|
|
connect(mUI->mTree, &ResultsTree::suppressIds, this, &ResultsView::suppressIds);
|
|
|
|
connect(this, &ResultsView::showResults, mUI->mTree, &ResultsTree::showResults);
|
|
|
|
connect(this, &ResultsView::showCppcheckResults, mUI->mTree, &ResultsTree::showCppcheckResults);
|
|
|
|
connect(this, &ResultsView::showClangResults, mUI->mTree, &ResultsTree::showClangResults);
|
|
|
|
connect(this, &ResultsView::collapseAllResults, mUI->mTree, &ResultsTree::collapseAll);
|
|
|
|
connect(this, &ResultsView::expandAllResults, mUI->mTree, &ResultsTree::expandAll);
|
|
|
|
connect(this, &ResultsView::showHiddenResults, mUI->mTree, &ResultsTree::showHiddenResults);
|
2020-08-22 11:37:44 +02:00
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListLog->setContextMenuPolicy(Qt::CustomContextMenu);
|
2009-07-02 10:32:29 +02:00
|
|
|
}
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler)
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mProgress->setMinimum(0);
|
|
|
|
mUI->mProgress->setVisible(false);
|
2023-08-25 13:38:27 +02:00
|
|
|
mUI->mLabelCriticalErrors->setVisible(false);
|
2010-11-23 20:57:16 +01:00
|
|
|
|
2019-06-25 15:29:15 +02:00
|
|
|
CodeEditorStyle theStyle(CodeEditorStyle::loadSettings(settings));
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mCode->setStyle(theStyle);
|
2019-06-23 19:04:53 +02:00
|
|
|
|
2010-11-23 20:57:16 +01:00
|
|
|
QByteArray state = settings->value(SETTINGS_MAINWND_SPLITTER_STATE).toByteArray();
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mVerticalSplitter->restoreState(state);
|
2009-07-02 10:32:29 +02:00
|
|
|
mShowNoErrorsMessage = settings->value(SETTINGS_SHOW_NO_ERRORS, true).toBool();
|
2009-06-09 09:51:27 +02:00
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->initialize(settings, list, checkThreadHandler);
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultsView::~ResultsView()
|
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
delete mUI;
|
2023-08-31 18:28:47 +02:00
|
|
|
delete mCheckSettings;
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::clear(bool results)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2012-09-05 21:01:50 +02:00
|
|
|
if (results) {
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->clear();
|
2012-09-05 21:01:50 +02:00
|
|
|
}
|
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mDetails->setText(QString());
|
2012-09-05 21:01:50 +02:00
|
|
|
|
2017-07-28 05:23:25 +02:00
|
|
|
mStatistics->clear();
|
2023-08-31 18:28:47 +02:00
|
|
|
delete mCheckSettings;
|
|
|
|
mCheckSettings = nullptr;
|
2009-06-09 09:51:27 +02:00
|
|
|
|
|
|
|
//Clear the progressbar
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mProgress->setMaximum(PROGRESS_MAX);
|
|
|
|
mUI->mProgress->setValue(0);
|
|
|
|
mUI->mProgress->setFormat("%p%");
|
2023-08-25 13:38:27 +02:00
|
|
|
|
|
|
|
mUI->mLabelCriticalErrors->setVisible(false);
|
|
|
|
|
|
|
|
mSuccess = false;
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::clear(const QString &filename)
|
2012-02-14 21:16:11 +01:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->clear(filename);
|
2015-12-29 01:38:36 +01:00
|
|
|
}
|
2012-02-14 21:16:11 +01:00
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::clearRecheckFile(const QString &filename)
|
2015-12-29 01:38:36 +01:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->clearRecheckFile(filename);
|
2012-02-14 21:16:11 +01:00
|
|
|
}
|
|
|
|
|
2023-02-24 21:22:08 +01:00
|
|
|
const ShowTypes & ResultsView::getShowTypes() const
|
2022-03-19 19:54:20 +01:00
|
|
|
{
|
2023-02-24 21:22:08 +01:00
|
|
|
return mUI->mTree->mShowSeverities;
|
2022-03-19 19:54:20 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::progress(int value, const QString& description)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mProgress->setValue(value);
|
|
|
|
mUI->mProgress->setFormat(QString("%p% (%1)").arg(description));
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::error(const ErrorItem &item)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2023-12-18 18:26:23 +01:00
|
|
|
if (item.severity == Severity::internal && (item.errorId == "logChecker" || item.errorId.endsWith("-logChecker"))) {
|
2023-08-31 18:28:47 +02:00
|
|
|
mStatistics->addChecker(item.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-25 13:38:27 +02:00
|
|
|
handleCriticalError(item);
|
|
|
|
|
2023-12-18 18:26:23 +01:00
|
|
|
if (item.severity == Severity::internal)
|
|
|
|
return;
|
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
if (mUI->mTree->addErrorItem(item)) {
|
2017-07-28 12:10:10 +02:00
|
|
|
emit gotResults();
|
2017-08-09 20:53:17 +02:00
|
|
|
mStatistics->addItem(item.tool(), ShowTypes::SeverityToShowType(item.severity));
|
2013-02-15 16:49:36 +01:00
|
|
|
}
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::filterResults(const QString& filter)
|
2011-05-04 07:30:54 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->filterResults(filter);
|
2011-05-04 07:30:54 +02:00
|
|
|
}
|
|
|
|
|
2017-07-30 00:13:00 +02:00
|
|
|
void ResultsView::saveStatistics(const QString &filename) const
|
|
|
|
{
|
|
|
|
QFile f(filename);
|
|
|
|
if (!f.open(QIODevice::Text | QIODevice::Append))
|
|
|
|
return;
|
|
|
|
QTextStream ts(&f);
|
2017-08-09 20:53:17 +02:00
|
|
|
ts << '[' << QDate::currentDate().toString("dd.MM.yyyy") << "]\n";
|
2017-08-11 08:08:30 +02:00
|
|
|
ts << QDateTime::currentMSecsSinceEpoch() << '\n';
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString& tool : mStatistics->getTools()) {
|
2017-08-09 20:53:17 +02:00
|
|
|
ts << tool << "-error:" << mStatistics->getCount(tool, ShowTypes::ShowErrors) << '\n';
|
|
|
|
ts << tool << "-warning:" << mStatistics->getCount(tool, ShowTypes::ShowWarnings) << '\n';
|
|
|
|
ts << tool << "-style:" << mStatistics->getCount(tool, ShowTypes::ShowStyle) << '\n';
|
|
|
|
ts << tool << "-performance:" << mStatistics->getCount(tool, ShowTypes::ShowPerformance) << '\n';
|
|
|
|
ts << tool << "-portability:" << mStatistics->getCount(tool, ShowTypes::ShowPortability) << '\n';
|
|
|
|
}
|
2017-07-30 00:13:00 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 20:24:23 +02:00
|
|
|
void ResultsView::updateFromOldReport(const QString &filename) const
|
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->updateFromOldReport(filename);
|
2017-08-02 20:24:23 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::save(const QString &filename, Report::Type type) const
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2019-06-30 21:39:22 +02:00
|
|
|
Report *report = nullptr;
|
2009-07-06 11:30:49 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2009-07-06 11:30:49 +02:00
|
|
|
case Report::CSV:
|
2012-10-27 12:22:56 +02:00
|
|
|
report = new CsvReport(filename);
|
2009-07-06 11:30:49 +02:00
|
|
|
break;
|
|
|
|
case Report::TXT:
|
2012-10-27 12:22:56 +02:00
|
|
|
report = new TxtReport(filename);
|
2009-07-06 11:30:49 +02:00
|
|
|
break;
|
2011-02-03 20:40:35 +01:00
|
|
|
case Report::XMLV2:
|
2012-10-27 12:22:56 +02:00
|
|
|
report = new XmlReportV2(filename);
|
2011-02-03 20:40:35 +01:00
|
|
|
break;
|
2009-07-06 11:30:49 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (report) {
|
2017-07-28 11:12:05 +02:00
|
|
|
if (report->create())
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->saveResults(report);
|
2011-10-13 20:53:06 +02:00
|
|
|
else {
|
2009-06-24 09:54:56 +02:00
|
|
|
QMessageBox msgBox;
|
2009-08-01 08:42:52 +02:00
|
|
|
msgBox.setText(tr("Failed to save the report."));
|
2009-07-06 11:37:54 +02:00
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
2009-06-24 09:54:56 +02:00
|
|
|
msgBox.exec();
|
|
|
|
}
|
2009-07-31 21:19:21 +02:00
|
|
|
delete report;
|
2019-06-30 21:39:22 +02:00
|
|
|
report = nullptr;
|
2011-10-13 20:53:06 +02:00
|
|
|
} else {
|
2009-07-06 11:30:49 +02:00
|
|
|
QMessageBox msgBox;
|
2009-08-01 08:42:52 +02:00
|
|
|
msgBox.setText(tr("Failed to save the report."));
|
2009-07-06 11:37:54 +02:00
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
2009-07-06 11:30:49 +02:00
|
|
|
msgBox.exec();
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::print()
|
2015-04-17 16:33:52 +02:00
|
|
|
{
|
|
|
|
QPrinter printer;
|
|
|
|
QPrintDialog dialog(&printer, this);
|
|
|
|
dialog.setWindowTitle(tr("Print Report"));
|
|
|
|
if (dialog.exec() != QDialog::Accepted)
|
|
|
|
return;
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
print(&printer);
|
2015-04-17 16:33:52 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::printPreview()
|
2015-04-17 16:33:52 +02:00
|
|
|
{
|
|
|
|
QPrinter printer;
|
|
|
|
QPrintPreviewDialog dialog(&printer, this);
|
2017-07-28 13:43:49 +02:00
|
|
|
connect(&dialog, SIGNAL(paintRequested(QPrinter*)), SLOT(print(QPrinter*)));
|
2015-04-17 16:33:52 +02:00
|
|
|
dialog.exec();
|
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::print(QPrinter* printer)
|
2015-04-17 16:33:52 +02:00
|
|
|
{
|
2017-07-28 12:10:10 +02:00
|
|
|
if (!hasResults()) {
|
2015-04-17 16:33:52 +02:00
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("No errors found, nothing to print."));
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.exec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrintableReport report;
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->saveResults(&report);
|
2017-07-28 11:12:05 +02:00
|
|
|
QTextDocument doc(report.getFormattedReportText());
|
2015-04-17 16:46:58 +02:00
|
|
|
doc.print(printer);
|
2015-04-17 16:33:52 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::updateSettings(bool showFullPath,
|
2009-06-03 20:18:22 +02:00
|
|
|
bool saveFullPath,
|
2009-06-09 09:51:27 +02:00
|
|
|
bool saveAllErrors,
|
2012-10-27 11:16:52 +02:00
|
|
|
bool showNoErrorsMessage,
|
2015-10-15 11:59:17 +02:00
|
|
|
bool showErrorId,
|
|
|
|
bool showInconclusive)
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->updateSettings(showFullPath, saveFullPath, saveAllErrors, showErrorId, showInconclusive);
|
2009-06-09 09:51:27 +02:00
|
|
|
mShowNoErrorsMessage = showNoErrorsMessage;
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
2019-06-25 15:29:15 +02:00
|
|
|
void ResultsView::updateStyleSetting(QSettings *settings)
|
2019-06-23 19:04:53 +02:00
|
|
|
{
|
2019-06-25 15:29:15 +02:00
|
|
|
CodeEditorStyle theStyle(CodeEditorStyle::loadSettings(settings));
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mCode->setStyle(theStyle);
|
2019-06-23 19:04:53 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::setCheckDirectory(const QString &dir)
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->setCheckDirectory(dir);
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
2020-03-07 11:33:08 +01:00
|
|
|
QString ResultsView::getCheckDirectory()
|
2016-01-15 16:52:22 +01:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
return mUI->mTree->getCheckDirectory();
|
2016-01-15 16:52:22 +01:00
|
|
|
}
|
|
|
|
|
2023-08-31 18:28:47 +02:00
|
|
|
void ResultsView::setCheckSettings(const Settings &settings)
|
|
|
|
{
|
|
|
|
delete mCheckSettings;
|
|
|
|
mCheckSettings = new Settings;
|
|
|
|
*mCheckSettings = settings;
|
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::checkingStarted(int count)
|
2009-06-09 10:21:17 +02:00
|
|
|
{
|
2023-08-25 13:38:27 +02:00
|
|
|
mSuccess = true;
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mProgress->setVisible(true);
|
|
|
|
mUI->mProgress->setMaximum(PROGRESS_MAX);
|
|
|
|
mUI->mProgress->setValue(0);
|
|
|
|
mUI->mProgress->setFormat(tr("%p% (%1 of %2 files checked)").arg(0).arg(count));
|
2010-07-04 17:54:41 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::checkingFinished()
|
2010-07-04 17:54:41 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mProgress->setVisible(false);
|
|
|
|
mUI->mProgress->setFormat("%p%");
|
2011-07-28 08:30:45 +02:00
|
|
|
|
2023-08-31 18:28:47 +02:00
|
|
|
{
|
|
|
|
Settings checkSettings;
|
|
|
|
const std::set<std::string> activeCheckers = mStatistics->getActiveCheckers();
|
|
|
|
CheckersReport checkersReport(mCheckSettings ? *mCheckSettings : checkSettings, activeCheckers);
|
|
|
|
mStatistics->setCheckersReport(QString::fromStdString(checkersReport.getReport(mCriticalErrors.toStdString())));
|
|
|
|
}
|
|
|
|
|
2020-05-03 17:20:38 +02:00
|
|
|
// TODO: Items can be mysteriously hidden when checking is finished, this function
|
|
|
|
// call should be redundant but it "unhides" the wrongly hidden items.
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->refreshTree();
|
2020-05-03 17:20:38 +02:00
|
|
|
|
2010-07-04 17:54:41 +02:00
|
|
|
//Should we inform user of non visible/not found errors?
|
2011-10-13 20:53:06 +02:00
|
|
|
if (mShowNoErrorsMessage) {
|
2010-07-04 17:54:41 +02:00
|
|
|
//Tell user that we found no errors
|
2017-07-28 12:10:10 +02:00
|
|
|
if (!hasResults()) {
|
2010-07-04 17:54:41 +02:00
|
|
|
QMessageBox msg(QMessageBox::Information,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
tr("No errors found."),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
this);
|
|
|
|
|
|
|
|
msg.exec();
|
|
|
|
} //If we have errors but they aren't visible, tell user about it
|
2022-03-19 19:54:20 +01:00
|
|
|
else if (!mUI->mTree->hasVisibleResults()) {
|
2021-08-07 20:51:18 +02:00
|
|
|
QString text = tr("Errors were found, but they are configured to be hidden.\n" \
|
2010-07-04 17:54:41 +02:00
|
|
|
"To toggle what kind of errors are shown, open view menu.");
|
|
|
|
QMessageBox msg(QMessageBox::Information,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
text,
|
|
|
|
QMessageBox::Ok,
|
|
|
|
this);
|
|
|
|
|
|
|
|
msg.exec();
|
|
|
|
}
|
|
|
|
}
|
2009-06-09 10:21:17 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
bool ResultsView::hasVisibleResults() const
|
2009-06-20 22:05:17 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
return mUI->mTree->hasVisibleResults();
|
2009-06-20 22:05:17 +02:00
|
|
|
}
|
2009-06-20 22:42:12 +02:00
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
bool ResultsView::hasResults() const
|
2009-06-20 22:42:12 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
return mUI->mTree->hasResults();
|
2009-06-20 22:42:12 +02:00
|
|
|
}
|
2009-07-02 10:32:29 +02:00
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::saveSettings(QSettings *settings)
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->saveSettings();
|
|
|
|
QByteArray state = mUI->mVerticalSplitter->saveState();
|
2010-11-23 20:57:16 +01:00
|
|
|
settings->setValue(SETTINGS_MAINWND_SPLITTER_STATE, state);
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mVerticalSplitter->restoreState(state);
|
2009-07-02 10:32:29 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::translate()
|
2009-07-02 10:46:26 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->retranslateUi(this);
|
|
|
|
mUI->mTree->translate();
|
2009-07-02 10:46:26 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::disableProgressbar()
|
2009-07-02 19:23:44 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mProgress->setEnabled(false);
|
2009-07-02 19:23:44 +02:00
|
|
|
}
|
2010-07-10 15:37:36 +02:00
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::readErrorsXml(const QString &filename)
|
2010-07-10 15:37:36 +02:00
|
|
|
{
|
2023-08-25 13:38:27 +02:00
|
|
|
mSuccess = false; // Don't know if results come from an aborted analysis
|
|
|
|
|
2011-02-05 11:12:34 +01:00
|
|
|
const int version = XmlReport::determineVersion(filename);
|
2011-10-13 20:53:06 +02:00
|
|
|
if (version == 0) {
|
2011-02-05 11:12:34 +01:00
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("Failed to read the report."));
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.exec();
|
|
|
|
return;
|
|
|
|
}
|
2017-07-29 19:36:01 +02:00
|
|
|
if (version == 1) {
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("XML format version 1 is no longer supported."));
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.exec();
|
|
|
|
return;
|
|
|
|
}
|
2011-02-05 11:12:34 +01:00
|
|
|
|
2018-10-17 06:38:14 +02:00
|
|
|
XmlReportV2 report(filename);
|
2011-02-05 11:41:29 +01:00
|
|
|
QList<ErrorItem> errors;
|
2018-10-17 06:38:14 +02:00
|
|
|
if (report.open()) {
|
|
|
|
errors = report.read();
|
|
|
|
} else {
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("Failed to read the report."));
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.exec();
|
2010-07-10 15:37:36 +02:00
|
|
|
}
|
2010-07-11 01:02:08 +02:00
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const ErrorItem& item : errors) {
|
2023-08-25 13:38:27 +02:00
|
|
|
handleCriticalError(item);
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->addErrorItem(item);
|
2010-07-11 01:02:08 +02:00
|
|
|
}
|
2018-02-20 13:40:10 +01:00
|
|
|
|
|
|
|
QString dir;
|
|
|
|
if (!errors.isEmpty() && !errors[0].errorPath.isEmpty()) {
|
|
|
|
QString relativePath = QFileInfo(filename).canonicalPath();
|
2023-08-22 12:01:30 +02:00
|
|
|
if (QFileInfo::exists(relativePath + '/' + errors[0].errorPath[0].file))
|
2018-02-20 13:40:10 +01:00
|
|
|
dir = relativePath;
|
|
|
|
}
|
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTree->setCheckDirectory(dir);
|
2010-07-10 15:37:36 +02:00
|
|
|
}
|
2010-11-22 22:13:12 +01:00
|
|
|
|
2017-07-28 12:10:10 +02:00
|
|
|
void ResultsView::updateDetails(const QModelIndex &index)
|
2010-11-22 22:13:12 +01:00
|
|
|
{
|
2022-12-19 20:01:12 +01:00
|
|
|
const QStandardItemModel *model = qobject_cast<const QStandardItemModel*>(mUI->mTree->model());
|
2010-11-22 22:13:12 +01:00
|
|
|
QStandardItem *item = model->itemFromIndex(index);
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!item) {
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mCode->clear();
|
|
|
|
mUI->mDetails->setText(QString());
|
2010-12-01 17:19:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-22 22:13:12 +01:00
|
|
|
// Make sure we are working with the first column
|
|
|
|
if (item->parent() && item->column() != 0)
|
|
|
|
item = item->parent()->child(item->row(), 0);
|
|
|
|
|
|
|
|
QVariantMap data = item->data().toMap();
|
2010-12-01 17:58:26 +01:00
|
|
|
|
|
|
|
// If there is no severity data then it is a parent item without summary and message
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!data.contains("severity")) {
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mCode->clear();
|
|
|
|
mUI->mDetails->setText(QString());
|
2010-12-01 17:58:26 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-30 22:37:25 +01:00
|
|
|
const QString message = data["message"].toString();
|
2018-08-07 10:44:25 +02:00
|
|
|
QString formattedMsg = message;
|
2015-10-14 18:10:14 +02:00
|
|
|
|
|
|
|
const QString file0 = data["file0"].toString();
|
2017-08-03 12:39:31 +02:00
|
|
|
if (!file0.isEmpty() && Path::isHeader(data["file"].toString().toStdString()))
|
2015-10-14 18:10:14 +02:00
|
|
|
formattedMsg += QString("\n\n%1: %2").arg(tr("First included by")).arg(QDir::toNativeSeparators(file0));
|
|
|
|
|
2020-05-03 17:20:38 +02:00
|
|
|
if (data["cwe"].toInt() > 0)
|
|
|
|
formattedMsg.prepend("CWE: " + QString::number(data["cwe"].toInt()) + "\n");
|
2022-03-19 19:54:20 +01:00
|
|
|
if (mUI->mTree->showIdColumn())
|
2012-10-27 11:16:52 +02:00
|
|
|
formattedMsg.prepend(tr("Id") + ": " + data["id"].toString() + "\n");
|
2020-05-03 17:20:38 +02:00
|
|
|
if (data["incomplete"].toBool())
|
|
|
|
formattedMsg += "\n" + tr("Bug hunting analysis is incomplete");
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mDetails->setText(formattedMsg);
|
2018-02-17 22:24:41 +01:00
|
|
|
|
|
|
|
const int lineNumber = data["line"].toInt();
|
|
|
|
|
|
|
|
QString filepath = data["file"].toString();
|
2023-08-22 12:01:30 +02:00
|
|
|
if (!QFileInfo::exists(filepath) && QFileInfo::exists(mUI->mTree->getCheckDirectory() + '/' + filepath))
|
2022-03-19 19:54:20 +01:00
|
|
|
filepath = mUI->mTree->getCheckDirectory() + '/' + filepath;
|
2018-02-17 22:24:41 +01:00
|
|
|
|
2020-07-18 18:14:55 +02:00
|
|
|
QStringList symbols;
|
|
|
|
if (data.contains("symbolNames"))
|
|
|
|
symbols = data["symbolNames"].toString().split("\n");
|
2018-02-18 12:06:54 +01:00
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
if (filepath == mUI->mCode->getFileName()) {
|
|
|
|
mUI->mCode->setError(lineNumber, symbols);
|
2020-07-18 18:14:55 +02:00
|
|
|
return;
|
2018-02-17 22:24:41 +01:00
|
|
|
}
|
2020-07-18 18:14:55 +02:00
|
|
|
|
|
|
|
QFile file(filepath);
|
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mCode->clear();
|
2020-07-18 18:14:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream in(&file);
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mCode->setError(in.readAll(), lineNumber, symbols);
|
|
|
|
mUI->mCode->setFileName(filepath);
|
2010-11-22 22:13:12 +01:00
|
|
|
}
|
2017-08-19 22:55:13 +02:00
|
|
|
|
|
|
|
void ResultsView::log(const QString &str)
|
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListLog->addItem(str);
|
2017-08-19 22:55:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsView::debugError(const ErrorItem &item)
|
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListLog->addItem(item.toString());
|
2017-08-19 22:55:13 +02:00
|
|
|
}
|
2017-12-05 20:42:16 +01:00
|
|
|
|
2017-12-06 21:39:53 +01:00
|
|
|
void ResultsView::logClear()
|
2017-12-05 20:42:16 +01:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListLog->clear();
|
2017-12-05 20:42:16 +01:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:39:53 +01:00
|
|
|
void ResultsView::logCopyEntry()
|
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
const QListWidgetItem * item = mUI->mListLog->currentItem();
|
2017-12-08 09:16:34 +01:00
|
|
|
if (nullptr != item) {
|
2017-12-06 21:39:53 +01:00
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
clipboard->setText(item->text());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsView::logCopyComplete()
|
|
|
|
{
|
|
|
|
QString logText;
|
2022-03-19 19:54:20 +01:00
|
|
|
for (int i=0; i < mUI->mListLog->count(); ++i) {
|
|
|
|
const QListWidgetItem * item = mUI->mListLog->item(i);
|
2017-12-08 09:16:34 +01:00
|
|
|
if (nullptr != item) {
|
2017-12-06 21:39:53 +01:00
|
|
|
logText += item->text();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
clipboard->setText(logText);
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:42:16 +01:00
|
|
|
void ResultsView::on_mListLog_customContextMenuRequested(const QPoint &pos)
|
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
if (mUI->mListLog->count() <= 0)
|
2018-02-20 14:32:07 +01:00
|
|
|
return;
|
2017-12-05 20:42:16 +01:00
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
const QPoint globalPos = mUI->mListLog->mapToGlobal(pos);
|
2017-12-05 20:42:16 +01:00
|
|
|
|
2018-02-20 14:32:07 +01:00
|
|
|
QMenu contextMenu;
|
|
|
|
contextMenu.addAction(tr("Clear Log"), this, SLOT(logClear()));
|
|
|
|
contextMenu.addAction(tr("Copy this Log entry"), this, SLOT(logCopyEntry()));
|
|
|
|
contextMenu.addAction(tr("Copy complete Log"), this, SLOT(logCopyComplete()));
|
|
|
|
|
|
|
|
contextMenu.exec(globalPos);
|
2017-12-05 20:42:16 +01:00
|
|
|
}
|
2023-08-25 13:38:27 +02:00
|
|
|
|
|
|
|
void ResultsView::stopAnalysis()
|
|
|
|
{
|
|
|
|
mSuccess = false;
|
|
|
|
mUI->mLabelCriticalErrors->setText(tr("Analysis was stopped"));
|
|
|
|
mUI->mLabelCriticalErrors->setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsView::handleCriticalError(const ErrorItem &item)
|
|
|
|
{
|
2023-08-29 12:00:52 +02:00
|
|
|
if (ErrorLogger::isCriticalErrorId(item.errorId.toStdString())) {
|
2023-08-31 18:28:47 +02:00
|
|
|
if (!mCriticalErrors.contains(item.errorId)) {
|
|
|
|
if (!mCriticalErrors.isEmpty())
|
|
|
|
mCriticalErrors += ",";
|
|
|
|
mCriticalErrors += item.errorId;
|
2023-12-18 18:26:23 +01:00
|
|
|
if (item.severity == Severity::internal)
|
|
|
|
mCriticalErrors += " (suppressed)";
|
2023-08-31 18:28:47 +02:00
|
|
|
}
|
2023-08-25 13:38:27 +02:00
|
|
|
QString msg = tr("There was a critical error with id '%1'").arg(item.errorId);
|
|
|
|
if (!item.file0.isEmpty())
|
|
|
|
msg += ", " + tr("when checking %1").arg(item.file0);
|
2023-12-18 18:26:23 +01:00
|
|
|
else
|
|
|
|
msg += ", " + tr("when checking a file");
|
2023-08-25 13:38:27 +02:00
|
|
|
msg += ". " + tr("Analysis was aborted.");
|
|
|
|
mUI->mLabelCriticalErrors->setText(msg);
|
|
|
|
mUI->mLabelCriticalErrors->setVisible(true);
|
|
|
|
mSuccess = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ResultsView::isSuccess() const {
|
|
|
|
return mSuccess;
|
|
|
|
}
|