2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2009-05-30 07:48:12 +02:00
|
|
|
* Copyright (C) 2007-2009 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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QVBoxLayout>
|
2009-06-03 20:18:22 +02:00
|
|
|
#include <QFile>
|
2009-06-09 09:51:27 +02:00
|
|
|
#include <QMessageBox>
|
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) :
|
|
|
|
QWidget(parent),
|
2009-06-09 09:51:27 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ResultsView::Progress(int value, int max)
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mProgress->setMaximum(max);
|
|
|
|
mUI.mProgress->setValue(value);
|
2009-06-09 08:30:28 +02:00
|
|
|
if (value >= max)
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mProgress->setVisible(false);
|
2009-06-09 09:51:27 +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
|
2009-07-02 10:32:29 +02:00
|
|
|
else if (!mUI.mTree->HasVisibleResults())
|
2009-06-09 09:51:27 +02:00
|
|
|
{
|
2009-06-09 10:21:17 +02:00
|
|
|
QString text = tr("Errors were found, but they are configured to be hidden.\n"\
|
2009-06-09 09:51:27 +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 08:30:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mProgress->setVisible(true);
|
2009-07-02 19:23:44 +02:00
|
|
|
mUI.mProgress->setEnabled(true);
|
2009-06-09 08:30:28 +02:00
|
|
|
}
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
2009-03-01 21:44:42 +01:00
|
|
|
void ResultsView::Error(const QString &file,
|
2009-03-01 08:38:21 +01:00
|
|
|
const QString &severity,
|
2009-03-01 21:44:42 +01:00
|
|
|
const QString &message,
|
|
|
|
const QStringList &files,
|
2009-06-03 20:18:22 +02:00
|
|
|
const QVariantList &lines,
|
|
|
|
const QString &id)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2009-06-09 09:51:27 +02:00
|
|
|
mErrorsFound = true;
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mTree->AddErrorItem(file, severity, message, files, lines, id);
|
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
|
|
|
{
|
2009-06-09 09:51:27 +02:00
|
|
|
if (!mErrorsFound)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (report)
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2009-07-06 11:30:49 +02:00
|
|
|
if (report->Create())
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-06-09 10:21:17 +02:00
|
|
|
void ResultsView::CheckingStarted()
|
|
|
|
{
|
2009-07-02 10:32:29 +02:00
|
|
|
mUI.mProgress->setVisible(true);
|
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);
|
|
|
|
}
|