2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2010-04-13 21:23:17 +02:00
|
|
|
* Copyright (C) 2007-2010 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>
|
|
|
|
#include <QVBoxLayout>
|
2009-06-03 20:18:22 +02:00
|
|
|
#include <QFile>
|
2009-06-09 09:51:27 +02:00
|
|
|
#include <QMessageBox>
|
2010-07-14 13:24:46 +02:00
|
|
|
#include "erroritem.h"
|
2009-06-24 09:54:56 +02:00
|
|
|
#include "resultsview.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"
|
2009-07-06 11:30:49 +02:00
|
|
|
#include "csvreport.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),
|
|
|
|
mShowNoErrorsMessage(true)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.setupUi(this);
|
|
|
|
}
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
void ResultsView::Initialize(QSettings *settings, ApplicationList *list)
|
|
|
|
{
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mProgress->setMinimum(0);
|
|
|
|
mUI.mProgress->setVisible(false);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
|
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();
|
2009-06-09 09:51:27 +02:00
|
|
|
mErrorsFound = false;
|
|
|
|
|
|
|
|
//Clear the progressbar
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mProgress->setMaximum(100);
|
|
|
|
mUI.mProgress->setValue(0);
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2010-07-04 17:54:41 +02:00
|
|
|
void ResultsView::Progress(int value)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mProgress->setValue(value);
|
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();
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
2009-03-22 18:39:44 +01:00
|
|
|
|
|
|
|
void ResultsView::ShowResults(ShowTypes type, bool show)
|
|
|
|
{
|
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
|
|
|
|
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:
|
|
|
|
report = new XmlReport(filename, this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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);
|
2010-07-04 17:54:41 +02:00
|
|
|
mUI.mProgress->setMaximum(count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultsView::CheckingFinished()
|
|
|
|
{
|
|
|
|
mUI.mProgress->setVisible(false);
|
|
|
|
//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
|
|
|
|
|
|
|
void ResultsView::SaveSettings()
|
|
|
|
{
|
|
|
|
mUI.mTree->SaveSettings();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
XmlReport *report = new XmlReport(filename, this);
|
2010-07-11 01:02:08 +02:00
|
|
|
QList<ErrorLine> 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
|
|
|
|
|
|
|
ErrorLine line;
|
|
|
|
foreach(line, errors)
|
|
|
|
{
|
|
|
|
ErrorItem item(line);
|
|
|
|
mUI.mTree->AddErrorItem(item);
|
|
|
|
}
|
2010-07-11 15:20:19 +02:00
|
|
|
mUI.mTree->SetCheckDirectory("");
|
2010-07-10 15:37:36 +02:00
|
|
|
}
|