diff --git a/gui/cppcheck_de.ts b/gui/cppcheck_de.ts index b2aa0aff4..7922ca7f9 100644 --- a/gui/cppcheck_de.ts +++ b/gui/cppcheck_de.ts @@ -18,7 +18,7 @@ Cppcheck - A tool for static C/C++ code analysis. - + Copyright (C) 2007-2009 Daniel Marjamäki and cppcheck team. @@ -116,10 +116,10 @@ kate -l(line) (file) MainWindow - - - - + + + + Cppcheck @@ -284,59 +284,64 @@ kate -l(line) (file) - + Select files to check - + Select directory to check - + No suitable files found to check! - + Cannot exit while checking. Stop the checking before exiting. - + License - + Authors - - XML files (*.xml);;Text files (*.txt) + + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) - + Save the report file - + XML files (*.xml) - + + Text files (*.txt) + + + + Cppcheck - %1 - + Failed to change the language: %1 @@ -397,25 +402,25 @@ Stop the checking before exiting. ResultsTree - + File - + Severity - + Line - + Message @@ -453,22 +458,22 @@ Please check the application path and parameters are correct. - + all - + style - + security - + error @@ -476,18 +481,18 @@ Please check the application path and parameters are correct. ResultsView - - + + Cppcheck - + No errors found. - + Errors were found, but they are configured to be hidden. To toggle what kind of errors are shown, open view menu. diff --git a/gui/cppcheck_en.ts b/gui/cppcheck_en.ts index 8ddee44eb..63fec5f1c 100644 --- a/gui/cppcheck_en.ts +++ b/gui/cppcheck_en.ts @@ -18,7 +18,7 @@ Cppcheck - A tool for static C/C++ code analysis. Cppcheck - A tool for static C/C++ code analysis. - + Copyright (C) 2007-2009 Daniel Marjamäki and cppcheck team. Copyright (C) 2007-2009 Daniel Marjamäki and cppcheck team. @@ -129,10 +129,10 @@ kate -l(line) (file) MainWindow - - - - + + + + Cppcheck Cppcheck @@ -297,22 +297,22 @@ kate -l(line) (file) &Help - + Select files to check Select files to check - + Select directory to check Select directory to check - + No suitable files found to check! No suitable files found to check! - + Cannot exit while checking. Stop the checking before exiting. @@ -321,37 +321,46 @@ Stop the checking before exiting. Stop the checking before exiting. - + License License - + Authors Authors - - XML files (*.xml);;Text files (*.txt) - XML files (*.xml);;Text files (*.txt) + + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) + - + XML files (*.xml);;Text files (*.txt) + XML files (*.xml);;Text files (*.txt) + + + Save the report file Save the report file - + XML files (*.xml) XML files (*.xml) - + + Text files (*.txt) + + + + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -414,25 +423,25 @@ Stop the checking before exiting. ResultsTree - + File File - + Severity Severity - + Line Line - + Message Message @@ -472,22 +481,22 @@ Please check the application path and parameters are correct. Please check the application path and parameters are correct. - + all All - + style Style - + security Security - + error Error @@ -495,18 +504,18 @@ Please check the application path and parameters are correct. ResultsView - - + + Cppcheck Cppcheck - + No errors found. No errors found. - + Errors were found, but they are configured to be hidden. To toggle what kind of errors are shown, open view menu. Errors were found, but they are configured to be hidden. diff --git a/gui/cppcheck_fi.ts b/gui/cppcheck_fi.ts index 361ba3f91..80d04a6ee 100644 --- a/gui/cppcheck_fi.ts +++ b/gui/cppcheck_fi.ts @@ -18,7 +18,7 @@ Cppcheck - A tool for static C/C++ code analysis. Cppcheck - Työkalu C/C++ koodin staattiseen analysointiin. - + Copyright (C) 2007-2009 Daniel Marjamäki and cppcheck team. Copyright (C) 2007-2009 Daniel Marjamäki ja cppcheck tiimi. @@ -131,10 +131,10 @@ kate -l(line) (file) MainWindow - - - - + + + + Cppcheck Cppcheck @@ -299,22 +299,22 @@ kate -l(line) (file) &Ohje - + Select files to check Valitse tarkistettavat tiedostot - + Select directory to check Valitse tarkistettava hakemisto - + No suitable files found to check! Tarkistettavaksi sopivia tiedostoja ei löytynyt! - + Cannot exit while checking. Stop the checking before exiting. @@ -323,37 +323,46 @@ Stop the checking before exiting. Lopeta tarkistus ennen ohjelman sammuttamista. - + License Lisenssi - + Authors Tekijät - - XML files (*.xml);;Text files (*.txt) - XML-tiedostot (*.xml);;Tekstitiedostot (*.txt) + + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) + - + XML files (*.xml);;Text files (*.txt) + XML-tiedostot (*.xml);;Tekstitiedostot (*.txt) + + + Save the report file Tallenna raportti - + XML files (*.xml) XML-tiedostot (*xml) - + + Text files (*.txt) + + + + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -418,25 +427,25 @@ Lopeta tarkistus ennen ohjelman sammuttamista. ResultsTree - + File Tiedosto - + Severity Tyyppi - + Line Rivi - + Message Virhe @@ -476,22 +485,22 @@ Please check the application path and parameters are correct. Tarkista että ohjelman polku ja parametrit ovat oikeat. - + all Epävarmat - + style Tyyli - + security Tietoturva - + error Yleinen @@ -499,18 +508,18 @@ Tarkista että ohjelman polku ja parametrit ovat oikeat. ResultsView - - + + Cppcheck Cppcheck - + No errors found. Virheitä ei löytynyt. - + Errors were found, but they are configured to be hidden. To toggle what kind of errors are shown, open view menu. Virheitä löytyi, mutta asetuksissa kyseiset virheet on määritelty piilotettavaksi. diff --git a/gui/cppcheck_ru.ts b/gui/cppcheck_ru.ts index 15be0f364..70dce81fa 100644 --- a/gui/cppcheck_ru.ts +++ b/gui/cppcheck_ru.ts @@ -18,7 +18,7 @@ Cppcheck - A tool for static C/C++ code analysis. - + Copyright (C) 2007-2009 Daniel Marjamäki and cppcheck team. @@ -118,10 +118,10 @@ kate -l(line) (file) MainWindow - - - - + + + + Cppcheck @@ -286,59 +286,64 @@ kate -l(line) (file) - + Select files to check - + Select directory to check - + No suitable files found to check! - + Cannot exit while checking. Stop the checking before exiting. - + License - + Authors - - XML files (*.xml);;Text files (*.txt) + + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) - + Save the report file - + XML files (*.xml) - + + Text files (*.txt) + + + + Cppcheck - %1 - + Failed to change the language: %1 @@ -399,25 +404,25 @@ Stop the checking before exiting. ResultsTree - + File - + Severity - + Line - + Message @@ -455,22 +460,22 @@ Please check the application path and parameters are correct. - + all - + style - + security - + error @@ -478,18 +483,18 @@ Please check the application path and parameters are correct. ResultsView - - + + Cppcheck - + No errors found. - + Errors were found, but they are configured to be hidden. To toggle what kind of errors are shown, open view menu. diff --git a/gui/cppcheck_se.ts b/gui/cppcheck_se.ts index 15be0f364..70dce81fa 100644 --- a/gui/cppcheck_se.ts +++ b/gui/cppcheck_se.ts @@ -18,7 +18,7 @@ Cppcheck - A tool for static C/C++ code analysis. - + Copyright (C) 2007-2009 Daniel Marjamäki and cppcheck team. @@ -118,10 +118,10 @@ kate -l(line) (file) MainWindow - - - - + + + + Cppcheck @@ -286,59 +286,64 @@ kate -l(line) (file) - + Select files to check - + Select directory to check - + No suitable files found to check! - + Cannot exit while checking. Stop the checking before exiting. - + License - + Authors - - XML files (*.xml);;Text files (*.txt) + + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) - + Save the report file - + XML files (*.xml) - + + Text files (*.txt) + + + + Cppcheck - %1 - + Failed to change the language: %1 @@ -399,25 +404,25 @@ Stop the checking before exiting. ResultsTree - + File - + Severity - + Line - + Message @@ -455,22 +460,22 @@ Please check the application path and parameters are correct. - + all - + style - + security - + error @@ -478,18 +483,18 @@ Please check the application path and parameters are correct. ResultsView - - + + Cppcheck - + No errors found. - + Errors were found, but they are configured to be hidden. To toggle what kind of errors are shown, open view menu. diff --git a/gui/csvreport.cpp b/gui/csvreport.cpp new file mode 100644 index 000000000..0a67b3a9c --- /dev/null +++ b/gui/csvreport.cpp @@ -0,0 +1,69 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki and Cppcheck team. + * + * 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 +#include +#include "csvreport.h" + +CsvReport::CsvReport(const QString &filename, QObject * parent) : + Report(filename, parent) +{ +} + +CsvReport::~CsvReport() +{ + Close(); +} + +bool CsvReport::Create() +{ + bool success = false; + if (Report::Create()) + { + mTxtWriter.setDevice(Report::GetFile()); + success = true; + } + return success; +} + +void CsvReport::WriteHeader() +{ + // No header for CSV report +} + +void CsvReport::WriteFooter() +{ + // No footer for CSV report +} + +void CsvReport::WriteError(const QStringList &files, const QStringList &lines, + const QString &id, const QString &severity, const QString &msg) +{ + Q_UNUSED(id); + + /* + Error as CSV line + gui/test.cpp,23,error,Mismatching allocation and deallocation: k + */ + + QString line; + line += QString("%1,%2,").arg(files[files.size() - 1]).arg(lines[lines.size() - 1]); + line += QString("%1,%2").arg(severity).arg(msg); + + mTxtWriter << line << endl; +} diff --git a/gui/csvreport.h b/gui/csvreport.h new file mode 100644 index 000000000..ee762577a --- /dev/null +++ b/gui/csvreport.h @@ -0,0 +1,72 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki and Cppcheck team. + * + * 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 +#include +#include +#include +#include +#include "report.h" + +/** +* @brief CSV text file report. +* This report exports results as CSV (comma separated values). CSV files are +* easy to import to many other programs. +* @todo This class should be inherited from TxtReport? +*/ +class CsvReport : public Report +{ +public: + CsvReport(const QString &filename, QObject * parent = 0); + ~CsvReport(); + + /** + * @brief Create the report (file). + * @return true if succeeded, false if file could not be created. + */ + virtual bool Create(); + + /** + * @brief Write report header. + */ + virtual void WriteHeader(); + + /** + * @brief Write report footer. + */ + virtual void WriteFooter(); + + /** + * @brief Write error to report. + */ + virtual void WriteError(const QStringList &files, const QStringList &lines, + const QString &id, const QString &severity, + const QString &msg); + +private: + + /** + * @brief Text stream writer for writing the report in text format. + */ + QTextStream mTxtWriter; +}; + +#endif // CSV_REPORT_H diff --git a/gui/gui.pro b/gui/gui.pro index eeccb840f..de287af22 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -45,6 +45,7 @@ HEADERS += mainwindow.h \ txtreport.h \ xmlreport.h \ translationhandler.h \ + csvreport.h \ ../src/checkautovariables.h \ ../src/checkdangerousfunctions.h \ ../src/checkheaders.h \ @@ -85,6 +86,7 @@ SOURCES += main.cpp \ txtreport.cpp \ xmlreport.cpp \ translationhandler.cpp \ + csvreport.cpp \ ../src/checkautovariables.cpp \ ../src/checkdangerousfunctions.cpp \ ../src/checkmemoryleak.cpp \ diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index ed49f5895..4e8014fca 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -31,6 +31,7 @@ #include "threadhandler.h" #include "fileviewdialog.h" #include "projectfile.h" +#include "report.h" #include "../src/filelister.h" #include "../src/cppcheckexecutor.h" @@ -511,7 +512,7 @@ void MainWindow::ShowAuthors() void MainWindow::Save() { QString selectedFilter; - QString filter(tr("XML files (*.xml);;Text files (*.txt)")); + QString filter(tr("XML files (*.xml);;Text files (*.txt);;CSV files (*.csv)")); QString selectedFile = QFileDialog::getSaveFileName(this, tr("Save the report file"), QString(), @@ -520,22 +521,27 @@ void MainWindow::Save() if (!selectedFile.isEmpty()) { - //Check if xml file type was selected - bool xml = selectedFilter == tr("XML files (*.xml)"); - - //Force xml extension to the file - if (xml && !selectedFile.endsWith(".xml", Qt::CaseInsensitive)) + Report::Type type; + if (selectedFilter == tr("XML files (*.xml)")) { - selectedFile += ".xml"; + type = Report::XML; + if (!selectedFile.endsWith(".xml", Qt::CaseInsensitive)) + selectedFile += ".xml"; + } + else if (selectedFilter == tr("Text files (*.txt)")) + { + type = Report::TXT; + if (!selectedFile.endsWith(".txt", Qt::CaseInsensitive)) + selectedFile += ".txt"; + } + else + { + type = Report::CSV; + if (!selectedFile.endsWith(".csv", Qt::CaseInsensitive)) + selectedFile += ".csv"; } - //Force .txt extension - if (!xml && !selectedFile.endsWith(".txt", Qt::CaseInsensitive)) - { - selectedFile += ".txt"; - } - - mUI.mResults->Save(selectedFile, xml); + mUI.mResults->Save(selectedFile, type); } } diff --git a/gui/report.h b/gui/report.h index 0694be45e..dd8ecbd04 100644 --- a/gui/report.h +++ b/gui/report.h @@ -30,6 +30,14 @@ class Report : public QObject { public: + + enum Type + { + TXT, + XML, + CSV, + }; + Report(const QString &filename, QObject * parent = 0); virtual ~Report(); diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 1233e53cd..1366e4484 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -21,8 +21,10 @@ #include #include #include "resultsview.h" +#include "report.h" #include "txtreport.h" #include "xmlreport.h" +#include "csvreport.h" ResultsView::ResultsView(QWidget * parent) : QWidget(parent), @@ -129,7 +131,7 @@ void ResultsView::ExpandAllResults() mUI.mTree->expandAll(); } -void ResultsView::Save(const QString &filename, bool xml) +void ResultsView::Save(const QString &filename, Report::Type type) { if (!mErrorsFound) { @@ -138,11 +140,25 @@ void ResultsView::Save(const QString &filename, bool xml) msgBox.exec(); } - if (xml) + Report *report = NULL; + + switch (type) { - XmlReport report(filename); - if (report.Create()) - mUI.mTree->SaveResults(&report); + 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) + { + if (report->Create()) + mUI.mTree->SaveResults(report); else { QMessageBox msgBox; @@ -152,15 +168,9 @@ void ResultsView::Save(const QString &filename, bool xml) } else { - TxtReport report(filename); - if (report.Create()) - mUI.mTree->SaveResults(&report); - else - { - QMessageBox msgBox; - msgBox.setText("Failed to save the report."); - msgBox.exec(); - } + QMessageBox msgBox; + msgBox.setText("Failed to save the report."); + msgBox.exec(); } } diff --git a/gui/resultsview.h b/gui/resultsview.h index 0e50fc97b..2eb43928c 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -26,6 +26,7 @@ #include "../src/errorlogger.h" #include "resultstree.h" #include "common.h" +#include "report.h" #include "ui_resultsview.h" /** @@ -60,9 +61,9 @@ public: * @brief Save results to a file * * @param filename Filename to save results to - * @param xml should results be saved as xml (true) or txt (false) + * @param type Type of the report. */ - void Save(const QString &filename, bool xml); + void Save(const QString &filename, Report::Type type); /** * @brief Update tree settings