From 5338339c2c90d5f93390589bda95477ab0b3dc66 Mon Sep 17 00:00:00 2001 From: Ameen Ali Date: Sun, 28 May 2017 16:16:28 +0200 Subject: [PATCH] GUI: Add button in statistics window to export statistics to PDF --- gui/stats.ui | 20 ++++++++++++++++-- gui/statsdialog.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++- gui/statsdialog.h | 1 + 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/gui/stats.ui b/gui/stats.ui index f94bb1d25..d565e934b 100644 --- a/gui/stats.ui +++ b/gui/stats.ui @@ -7,7 +7,7 @@ 0 0 502 - 272 + 274 @@ -342,7 +342,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -365,6 +374,13 @@ + + + + Pdf Export + + + diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp index c2b240407..56f7af54a 100644 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -15,7 +15,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - +#include +#include +#include +#include +#include #include #include #include @@ -32,6 +36,8 @@ StatsDialog::StatsDialog(QWidget *parent) mUI.setupUi(this); connect(mUI.mCopyToClipboard, SIGNAL(pressed()), this, SLOT(copyToClipboard())); + connect(mUI.mPDFexport, SIGNAL(pressed()), this, SLOT(PDFexport())); + } void StatsDialog::setProject(const Project& project) @@ -88,6 +94,47 @@ void StatsDialog::setScanDuration(double seconds) mUI.mScanDuration->setText(parts.join(tr(" and "))); } +void StatsDialog::PDFexport() +{ + const QString Stat = QString( + "

%1 %2

\n" + "

%3 : %4

\n" + "

%5 : %6

\n" + "

%7 : %8

\n" + "

%9 : %10

\n" + "

%11 : %12

\n" + "

%13 : %14

\n") + .arg("Statistics") + .arg(QDate::currentDate().toString("dd.MM.yyyy")) + .arg("Errors") + .arg(mStatistics->GetCount(ShowTypes::ShowErrors)) + .arg("Warnings") + .arg(mStatistics->GetCount(ShowTypes::ShowWarnings)) + .arg("Style warnings") + .arg(mStatistics->GetCount(ShowTypes::ShowStyle)) + .arg("Portability warnings") + .arg(mStatistics->GetCount(ShowTypes::ShowPortability)) + .arg("Performance warnings") + .arg(mStatistics->GetCount(ShowTypes::ShowPerformance)) + .arg("Information messages") + .arg(mStatistics->GetCount(ShowTypes::ShowInformation) + ); + + QString fileName = QFileDialog::getSaveFileName((QWidget*)0, "Export PDF", QString(), "*.pdf"); + if (QFileInfo(fileName).suffix().isEmpty()) { + fileName.append(".pdf"); + } + QPrinter printer(QPrinter::PrinterResolution); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setPaperSize(QPrinter::A4); + printer.setOutputFileName(fileName); + + QTextDocument doc; + doc.setHtml(Stat); + // doc.setPageSize(printer.pageRect().size()); + doc.print(&printer); + +} void StatsDialog::copyToClipboard() { diff --git a/gui/statsdialog.h b/gui/statsdialog.h index 2f0ea86a1..ce645595a 100644 --- a/gui/statsdialog.h +++ b/gui/statsdialog.h @@ -64,6 +64,7 @@ public: private slots: void copyToClipboard(); + void PDFexport(); private: Ui::StatsDialog mUI;