2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2011-01-09 20:33:36 +01:00
|
|
|
* Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team.
|
2009-03-01 08:38:21 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-03-01 08:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QDebug>
|
2009-06-03 20:18:22 +02:00
|
|
|
#include <QFile>
|
2009-06-09 09:51:27 +02:00
|
|
|
#include <QMessageBox>
|
2010-11-22 23:37:29 +01:00
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QStandardItem>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QString>
|
|
|
|
#include <QModelIndex>
|
2010-11-23 20:57:16 +01:00
|
|
|
#include <QSettings>
|
2011-07-28 08:30:45 +02:00
|
|
|
#include "common.h"
|
2010-07-14 13:24:46 +02:00
|
|
|
#include "erroritem.h"
|
2009-06-24 09:54:56 +02:00
|
|
|
#include "resultsview.h"
|
2010-07-17 21:34:07 +02:00
|
|
|
#include "resultstree.h"
|
2009-07-06 11:30:49 +02:00
|
|
|
#include "report.h"
|
2009-06-24 09:54:56 +02:00
|
|
|
#include "txtreport.h"
|
|
|
|
#include "xmlreport.h"
|
2011-02-04 22:56:14 +01:00
|
|
|
#include "xmlreportv1.h"
|
2011-02-03 20:40:35 +01:00
|
|
|
#include "xmlreportv2.h"
|
2009-07-06 11:30:49 +02:00
|
|
|
#include "csvreport.h"
|
2010-11-24 16:39:53 +01:00
|
|
|
#include "applicationlist.h"
|
2010-11-29 23:01:45 +01:00
|
|
|
#include "checkstatistics.h"
|
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),
|
|
|
|
mErrorsFound(false),
|
2010-11-29 23:01:45 +01:00
|
|
|
mShowNoErrorsMessage(true),
|
|
|
|
mStatistics(new CheckStatistics(this))
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.setupUi(this);
|
2010-11-24 09:48:07 +01:00
|
|
|
|
|
|
|
connect(mUI.mTree, SIGNAL(ResultsHidden(bool)), this, SIGNAL(ResultsHidden(bool)));
|
2010-11-23 21:37:31 +01:00
|
|
|
connect(mUI.mTree, SIGNAL(SelectionChanged(const QModelIndex &)), this, SLOT(UpdateDetails(const QModelIndex &)));
|
2009-07-02 10:32:29 +02:00
|
|
|
}
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
void ResultsView::Initialize(QSettings *settings, ApplicationList *list)
|
|
|
|
{
|
|
|
|
mUI.mProgress->setMinimum(0);
|
|
|
|
mUI.mProgress->setVisible(false);
|
2010-11-23 20:57:16 +01:00
|
|
|
|
|
|
|
QByteArray state = settings->value(SETTINGS_MAINWND_SPLITTER_STATE).toByteArray();
|
|
|
|
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
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mTree->Initialize(settings, list);
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultsView::~ResultsView()
|
|
|
|
{
|
|
|
|
//dtor
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsView::Clear()
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mTree->Clear();
|
2010-11-24 16:09:02 +01:00
|
|
|
mUI.mDetails->setText("");
|
2009-06-09 09:51:27 +02:00
|
|
|
mErrorsFound = false;
|
2010-11-29 23:01:45 +01:00
|
|
|
mStatistics->Clear();
|
2009-06-09 09:51:27 +02:00
|
|
|
|
|
|
|
//Clear the progressbar
|
2011-07-28 08:30:45 +02:00
|
|
|
mUI.mProgress->setMaximum(PROGRESS_MAX);
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mProgress->setValue(0);
|
2011-08-03 09:53:35 +02:00
|
|
|
mUI.mProgress->setFormat("%p%");
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2011-07-28 08:30:45 +02:00
|
|
|
void ResultsView::Progress(int value, const QString& description)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mProgress->setValue(value);
|
2011-08-03 09:53:35 +02:00
|
|
|
mUI.mProgress->setFormat(QString("%p% (%1)").arg(description));
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2010-07-14 13:24:46 +02:00
|
|
|
void ResultsView::Error(const ErrorItem &item)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-06-09 09:51:27 +02:00
|
|
|
mErrorsFound = true;
|
2010-07-10 19:30:31 +02:00
|
|
|
mUI.mTree->AddErrorItem(item);
|
2009-06-03 20:18:22 +02:00
|
|
|
emit GotResults();
|
2011-10-11 21:14:15 +02:00
|
|
|
mStatistics->AddItem(ShowTypes::SeverityToShowType(item.severity));
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
2009-03-22 18:39:44 +01:00
|
|
|
|
2011-10-11 21:14:15 +02:00
|
|
|
void ResultsView::ShowResults(ShowTypes::ShowType type, bool show)
|
2009-03-22 18:39:44 +01:00
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mTree->ShowResults(type, show);
|
2009-03-22 18:39:44 +01:00
|
|
|
}
|
2009-06-02 00:26:44 +02:00
|
|
|
|
|
|
|
void ResultsView::CollapseAllResults()
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mTree->collapseAll();
|
2009-06-02 00:26:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsView::ExpandAllResults()
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mTree->expandAll();
|
2009-06-02 00:26:44 +02:00
|
|
|
}
|
2009-06-03 20:18:22 +02:00
|
|
|
|
2010-11-21 19:55:34 +01:00
|
|
|
void ResultsView::ShowHiddenResults()
|
|
|
|
{
|
|
|
|
mUI.mTree->ShowHiddenResults();
|
|
|
|
}
|
|
|
|
|
2011-05-04 07:30:54 +02:00
|
|
|
void ResultsView::FilterResults(const QString& filter)
|
|
|
|
{
|
|
|
|
mUI.mTree->FilterResults(filter);
|
|
|
|
}
|
|
|
|
|
2009-07-06 11:30:49 +02:00
|
|
|
void ResultsView::Save(const QString &filename, Report::Type type)
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!mErrorsFound)
|
2009-06-09 09:51:27 +02:00
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
2009-08-01 08:42:52 +02:00
|
|
|
msgBox.setText(tr("No errors found, nothing to save."));
|
2009-07-06 11:37:54 +02:00
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
2009-06-09 09:51:27 +02:00
|
|
|
msgBox.exec();
|
|
|
|
}
|
|
|
|
|
2009-07-06 11:30:49 +02:00
|
|
|
Report *report = NULL;
|
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
switch (type)
|
2009-07-06 11:30:49 +02:00
|
|
|
{
|
|
|
|
case Report::CSV:
|
|
|
|
report = new CsvReport(filename, this);
|
|
|
|
break;
|
|
|
|
case Report::TXT:
|
|
|
|
report = new TxtReport(filename, this);
|
|
|
|
break;
|
|
|
|
case Report::XML:
|
2011-02-04 22:56:14 +01:00
|
|
|
report = new XmlReportV1(filename, this);
|
2009-07-06 11:30:49 +02:00
|
|
|
break;
|
2011-02-03 20:40:35 +01:00
|
|
|
case Report::XMLV2:
|
|
|
|
report = new XmlReportV2(filename, this);
|
|
|
|
break;
|
2009-07-06 11:30:49 +02:00
|
|
|
}
|
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (report)
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (report->Create())
|
2009-07-06 11:30:49 +02:00
|
|
|
mUI.mTree->SaveResults(report);
|
2009-06-24 09:54:56 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
report = NULL;
|
2009-06-24 09:54:56 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsView::UpdateSettings(bool showFullPath,
|
|
|
|
bool saveFullPath,
|
2009-06-09 09:51:27 +02:00
|
|
|
bool saveAllErrors,
|
|
|
|
bool showNoErrorsMessage)
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mTree->UpdateSettings(showFullPath, saveFullPath, saveAllErrors);
|
2009-06-09 09:51:27 +02:00
|
|
|
mShowNoErrorsMessage = showNoErrorsMessage;
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsView::SetCheckDirectory(const QString &dir)
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mTree->SetCheckDirectory(dir);
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
2010-07-04 17:54:41 +02:00
|
|
|
void ResultsView::CheckingStarted(int count)
|
2009-06-09 10:21:17 +02:00
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mProgress->setVisible(true);
|
2011-07-28 08:30:45 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsView::CheckingFinished()
|
|
|
|
{
|
|
|
|
mUI.mProgress->setVisible(false);
|
2011-07-28 08:30:45 +02:00
|
|
|
mUI.mProgress->setFormat("%p%");
|
|
|
|
|
2010-07-04 17:54:41 +02:00
|
|
|
//Should we inform user of non visible/not found errors?
|
|
|
|
if (mShowNoErrorsMessage)
|
|
|
|
{
|
|
|
|
//Tell user that we found no errors
|
|
|
|
if (!mErrorsFound)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
else if (!mUI.mTree->HasVisibleResults())
|
|
|
|
{
|
|
|
|
QString text = tr("Errors were found, but they are configured to be hidden.\n"\
|
|
|
|
"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
|
|
|
}
|
|
|
|
|
2009-06-20 22:05:17 +02:00
|
|
|
bool ResultsView::HasVisibleResults() const
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
return mUI.mTree->HasVisibleResults();
|
2009-06-20 22:05:17 +02:00
|
|
|
}
|
2009-06-20 22:42:12 +02:00
|
|
|
|
|
|
|
bool ResultsView::HasResults() const
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
return mUI.mTree->HasResults();
|
2009-06-20 22:42:12 +02:00
|
|
|
}
|
2009-07-02 10:32:29 +02:00
|
|
|
|
2010-11-23 20:57:16 +01:00
|
|
|
void ResultsView::SaveSettings(QSettings *settings)
|
2009-07-02 10:32:29 +02:00
|
|
|
{
|
|
|
|
mUI.mTree->SaveSettings();
|
2010-11-23 20:57:16 +01:00
|
|
|
QByteArray state = mUI.mVerticalSplitter->saveState();
|
|
|
|
settings->setValue(SETTINGS_MAINWND_SPLITTER_STATE, state);
|
|
|
|
mUI.mVerticalSplitter->restoreState(state);
|
2009-07-02 10:32:29 +02:00
|
|
|
}
|
|
|
|
|
2009-07-02 10:46:26 +02:00
|
|
|
void ResultsView::Translate()
|
|
|
|
{
|
|
|
|
mUI.mTree->Translate();
|
|
|
|
}
|
|
|
|
|
2009-07-02 19:23:44 +02:00
|
|
|
void ResultsView::DisableProgressbar()
|
|
|
|
{
|
|
|
|
mUI.mProgress->setEnabled(false);
|
|
|
|
}
|
2010-07-10 15:37:36 +02:00
|
|
|
|
|
|
|
void ResultsView::ReadErrorsXml(const QString &filename)
|
|
|
|
{
|
2011-02-05 11:12:34 +01:00
|
|
|
const int version = XmlReport::determineVersion(filename);
|
|
|
|
if (version == 0)
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("Failed to read the report."));
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.exec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlReport *report = NULL;
|
|
|
|
if (version == 1)
|
|
|
|
report = new XmlReportV1(filename, this);
|
|
|
|
else if (version == 2)
|
|
|
|
report = new XmlReportV2(filename, this);
|
|
|
|
|
2011-02-05 11:41:29 +01:00
|
|
|
QList<ErrorItem> errors;
|
2010-07-10 15:37:36 +02:00
|
|
|
if (report)
|
|
|
|
{
|
|
|
|
if (report->Open())
|
2010-07-11 01:02:08 +02:00
|
|
|
errors = report->Read();
|
2010-07-10 15:37:36 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("Failed to read the report."));
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.exec();
|
|
|
|
}
|
|
|
|
delete report;
|
|
|
|
report = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("Failed to read the report."));
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.exec();
|
|
|
|
}
|
2010-07-11 01:02:08 +02:00
|
|
|
|
2011-02-05 11:41:29 +01:00
|
|
|
ErrorItem item;
|
|
|
|
foreach(item, errors)
|
2010-07-11 01:02:08 +02:00
|
|
|
{
|
|
|
|
mUI.mTree->AddErrorItem(item);
|
|
|
|
}
|
2010-07-11 15:20:19 +02:00
|
|
|
mUI.mTree->SetCheckDirectory("");
|
2010-07-10 15:37:36 +02:00
|
|
|
}
|
2010-11-22 22:13:12 +01:00
|
|
|
|
2010-11-23 21:37:31 +01:00
|
|
|
void ResultsView::UpdateDetails(const QModelIndex &index)
|
2010-11-22 22:13:12 +01:00
|
|
|
{
|
|
|
|
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(mUI.mTree->model());
|
|
|
|
QStandardItem *item = model->itemFromIndex(index);
|
|
|
|
|
2010-12-01 17:19:37 +01:00
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
mUI.mDetails->setText("");
|
|
|
|
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
|
|
|
|
if (!data.contains("severity"))
|
|
|
|
{
|
|
|
|
mUI.mDetails->setText("");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-30 22:37:25 +01:00
|
|
|
const QString summary = data["summary"].toString();
|
|
|
|
const QString message = data["message"].toString();
|
|
|
|
const QString formattedMsg = QString("%1: %2\n%3: %4")
|
|
|
|
.arg(tr("Summary")).arg(summary)
|
|
|
|
.arg(tr("Message")).arg(message);
|
|
|
|
mUI.mDetails->setText(formattedMsg);
|
2010-11-22 22:13:12 +01:00
|
|
|
}
|