diff --git a/gui/gui.pro b/gui/gui.pro
index 2e1805489..f2e54ce7c 100644
--- a/gui/gui.pro
+++ b/gui/gui.pro
@@ -6,9 +6,9 @@ DEPENDPATH += . \
INCLUDEPATH += . \
../lib
-# In Qt 5 widgets are in separate module
greaterThan(QT_MAJOR_VERSION, 4) {
- QT += widgets
+ QT += widgets # In Qt 5 widgets are in separate module
+ QT += printsupport # In Qt 5 QPrinter/QPrintDialog are in separate module
}
contains(LINKCORE, [yY][eE][sS]) {
@@ -88,6 +88,7 @@ HEADERS += aboutdialog.h \
logview.h \
mainwindow.h \
platforms.h \
+ printablereport.h \
project.h \
projectfile.h \
projectfiledialog.h \
@@ -121,6 +122,7 @@ SOURCES += aboutdialog.cpp \
main.cpp \
mainwindow.cpp\
platforms.cpp \
+ printablereport.cpp \
project.cpp \
projectfile.cpp \
projectfiledialog.cpp \
diff --git a/gui/main.ui b/gui/main.ui
index 26dad61a5..d579518ab 100644
--- a/gui/main.ui
+++ b/gui/main.ui
@@ -62,7 +62,7 @@
0
0
640
- 25
+ 21
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index 8bcfed7dd..0d1c22f6a 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -77,6 +77,8 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
connect(mLineEditFilter, SIGNAL(textChanged(const QString&)), mFilterTimer, SLOT(start()));
connect(mLineEditFilter, SIGNAL(returnPressed()), this, SLOT(FilterResults()));
+ connect(mUI.mActionPrint, SIGNAL(triggered()), this, SLOT(PrintReport()));
+ connect(mUI.mActionPrintPreview, SIGNAL(triggered()), this, SLOT(PrintPreview()));
connect(mUI.mActionQuit, SIGNAL(triggered()), this, SLOT(close()));
connect(mUI.mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles()));
connect(mUI.mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory()));
@@ -134,6 +136,9 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
EnableCheckButtons(true);
+ mUI.mActionPrint->setShortcut(QKeySequence::Print);
+ mUI.mActionPrint->setEnabled(false);
+ mUI.mActionPrintPreview->setEnabled(false);
mUI.mActionClearResults->setEnabled(false);
mUI.mActionSave->setEnabled(false);
mUI.mActionRecheck->setEnabled(false);
@@ -434,6 +439,16 @@ QStringList MainWindow::SelectFilesToCheck(QFileDialog::FileMode mode)
return selected;
}
+void MainWindow::PrintReport()
+{
+ mUI.mResults->Print();
+}
+
+void MainWindow::PrintPreview()
+{
+ mUI.mResults->PrintPreview();
+}
+
void MainWindow::CheckFiles()
{
DoCheckFiles(SelectFilesToCheck(QFileDialog::ExistingFiles));
@@ -695,6 +710,8 @@ void MainWindow::CheckDone()
if (mUI.mResults->HasResults()) {
mUI.mActionClearResults->setEnabled(true);
mUI.mActionSave->setEnabled(true);
+ mUI.mActionPrint->setEnabled(true);
+ mUI.mActionPrintPreview->setEnabled(true);
}
for (int i = 0; i < MaxRecentProjects + 1; i++) {
@@ -768,6 +785,8 @@ void MainWindow::ClearResults()
mUI.mResults->Clear(true);
mUI.mActionClearResults->setEnabled(false);
mUI.mActionSave->setEnabled(false);
+ mUI.mActionPrint->setEnabled(false);
+ mUI.mActionPrintPreview->setEnabled(false);
}
void MainWindow::OpenResults()
diff --git a/gui/mainwindow.h b/gui/mainwindow.h
index b7036331a..ddaffa7ed 100644
--- a/gui/mainwindow.h
+++ b/gui/mainwindow.h
@@ -72,6 +72,18 @@ public:
public slots:
+ /**
+ * @brief Slot opening a print dialog to print the current report
+ *
+ */
+ void PrintReport();
+
+ /**
+ * @brief Slot opening a print preview dialogPrintPreview
+ *
+ */
+ void PrintPreview();
+
/**
* @brief Slot for check files menu item
*
diff --git a/gui/printablereport.cpp b/gui/printablereport.cpp
new file mode 100644
index 000000000..1cb7cba13
--- /dev/null
+++ b/gui/printablereport.cpp
@@ -0,0 +1,63 @@
+/*
+ * Cppcheck - A tool for static C/C++ code analysis
+ * Copyright (C) 2007-2015 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 "printablereport.h"
+#include
+#include
+
+PrintableReport::PrintableReport() :
+ Report(QString()),
+ mReportDocument(new QTextDocument(this))
+{
+}
+
+PrintableReport::~PrintableReport()
+{
+}
+
+bool PrintableReport::Create()
+{
+ return true;
+}
+
+void PrintableReport::WriteHeader()
+{
+ // No header for printable report
+}
+
+void PrintableReport::WriteFooter()
+{
+ // No footer for printable report
+}
+
+void PrintableReport::WriteError(const ErrorItem &error)
+{
+ const QString file = QDir::toNativeSeparators(error.files[error.files.size() - 1]);
+ QString line = QString("%1,%2,").arg(file).arg(error.lines[error.lines.size() - 1]);
+ line += QString("%1,%2").arg(GuiSeverity::toString(error.severity)).arg(error.summary);
+
+ mFormattedReport += line;
+ mFormattedReport += "\n";
+}
+
+QTextDocument* PrintableReport::GetReport() const
+{
+ mReportDocument->setPlainText(mFormattedReport);
+ return mReportDocument;
+}
+
diff --git a/gui/printablereport.h b/gui/printablereport.h
new file mode 100644
index 000000000..6317d18b8
--- /dev/null
+++ b/gui/printablereport.h
@@ -0,0 +1,71 @@
+/*
+ * Cppcheck - A tool for static C/C++ code analysis
+ * Copyright (C) 2007-2015 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 .
+ */
+
+#ifndef PRINTABLE_REPORT_H
+#define PRINTABLE_REPORT_H
+
+#include "report.h"
+
+class QTextDocument;
+
+/// @addtogroup GUI
+/// @{
+
+
+/**
+* @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 PrintableReport : public Report {
+public:
+ PrintableReport();
+ virtual ~PrintableReport();
+
+ /**
+ * @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.
+ * @param error Error data.
+ */
+ virtual void WriteError(const ErrorItem &error);
+
+ QTextDocument* GetReport() const;
+
+private:
+
+ QString mFormattedReport;
+ QTextDocument* mReportDocument;
+};
+/// @}
+#endif // PRINTABLE_REPORT_H
diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp
index 6e8028975..8c29a1af4 100644
--- a/gui/resultsview.cpp
+++ b/gui/resultsview.cpp
@@ -22,6 +22,9 @@
#include
#include
#include
+#include
+#include
+#include
#include
#include "common.h"
#include "erroritem.h"
@@ -32,6 +35,7 @@
#include "xmlreportv1.h"
#include "xmlreportv2.h"
#include "csvreport.h"
+#include "printablereport.h"
#include "applicationlist.h"
#include "checkstatistics.h"
@@ -178,6 +182,40 @@ void ResultsView::Save(const QString &filename, Report::Type type) const
}
}
+void ResultsView::Print()
+{
+ QPrinter printer;
+ QPrintDialog dialog(&printer, this);
+ dialog.setWindowTitle(tr("Print Report"));
+ if (dialog.exec() != QDialog::Accepted)
+ return;
+
+ Print(&printer);
+}
+
+void ResultsView::PrintPreview()
+{
+ QPrinter printer;
+ QPrintPreviewDialog dialog(&printer, this);
+ connect(&dialog, SIGNAL(paintRequested(QPrinter*)), SLOT(Print(QPrinter*)));
+ dialog.exec();
+}
+
+void ResultsView::Print(QPrinter* printer)
+{
+ if (!mErrorsFound) {
+ QMessageBox msgBox;
+ msgBox.setText(tr("No errors found, nothing to print."));
+ msgBox.setIcon(QMessageBox::Critical);
+ msgBox.exec();
+ return;
+ }
+
+ PrintableReport report;
+ mUI.mTree->SaveResults(&report);
+ report.GetReport()->print(printer);
+}
+
void ResultsView::UpdateSettings(bool showFullPath,
bool saveFullPath,
bool saveAllErrors,
diff --git a/gui/resultsview.h b/gui/resultsview.h
index 068440e04..7d2046777 100644
--- a/gui/resultsview.h
+++ b/gui/resultsview.h
@@ -29,6 +29,7 @@
class ErrorItem;
class ApplicationList;
class QModelIndex;
+class QPrinter;
class QSettings;
class CheckStatistics;
@@ -75,6 +76,9 @@ public:
*/
void Save(const QString &filename, Report::Type type) const;
+ void Print();
+ void PrintPreview();
+
/**
* @brief Update tree settings
*
@@ -222,6 +226,8 @@ public slots:
*/
void UpdateDetails(const QModelIndex &index);
+ void Print(QPrinter* printer);
+
protected:
/**
* @brief Have any errors been found