From 1a2f154cf49041a223e5801328beb68cb8b42442 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Thu, 6 Aug 2015 20:39:38 +0200 Subject: Printing: add statistics print Add statistics table print option. Signed-off-by: Lubomir I. Ivanov Signed-off-by: Gehad elrobey --- printer.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ printer.h | 1 + qt-ui/printdialog.cpp | 24 +++++++++------------- 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/printer.cpp b/printer.cpp index 2c1dcdc2f..eee0fdbd6 100644 --- a/printer.cpp +++ b/printer.cpp @@ -1,5 +1,7 @@ #include "printer.h" #include "templatelayout.h" +#include "statistics.h" +#include "helpers.h" #include #include @@ -172,6 +174,60 @@ void Printer::print() render(Pages); } +void Printer::print_statistics() +{ + QPrinter *printerPtr; + printerPtr = static_cast(paintDevice); + stats_t total_stats; + + total_stats.selection_size = 0; + total_stats.total_time.seconds = 0; + + QString html; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + int i = 0; + while (stats_yearly != NULL && stats_yearly[i].period) { + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + html += ""; + total_stats.selection_size += stats_yearly[i].selection_size; + total_stats.total_time.seconds += stats_yearly[i].total_time.seconds; + i++; + } + html += "
YearDivesTotal TimeAvg TimeShortest TimeLongest TimeAvg DepthMin DepthMax DepthAvg SACMin SACMax SACMin TempMax Temp
" + QString::number(stats_yearly[i].period) + "" + QString::number(stats_yearly[i].selection_size) + "" + QString::fromUtf8(get_time_string(stats_yearly[i].total_time.seconds, 0)) + "" + QString::fromUtf8(get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size)) + "" + QString::fromUtf8(get_minutes(stats_yearly[i].shortest_time.seconds)) + "" + QString::fromUtf8(get_minutes(stats_yearly[i].longest_time.seconds)) + "" + get_depth_string(stats_yearly[i].avg_depth) + "" + get_depth_string(stats_yearly[i].min_depth) + "" + get_depth_string(stats_yearly[i].max_depth) + "" + get_volume_string(stats_yearly[i].avg_sac) + "" + get_volume_string(stats_yearly[i].min_sac) + "" + get_volume_string(stats_yearly[i].max_sac) + "" + QString::number(stats_yearly[i].min_temp == 0 ? 0 : get_temp_units(stats_yearly[i].min_temp, NULL)) + "" + QString::number(stats_yearly[i].max_temp == 0 ? 0 : get_temp_units(stats_yearly[i].max_temp, NULL)) + "
"; + webView->setHtml(html); + webView->print(printerPtr); +} + void Printer::previewOnePage() { if (printMode == PREVIEW) { diff --git a/printer.h b/printer.h index b4cf3ac2a..c0775fa4b 100644 --- a/printer.h +++ b/printer.h @@ -38,6 +38,7 @@ public: Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode); ~Printer(); void print(); + void print_statistics(); void previewOnePage(); signals: diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 6c50ae99b..08fdf7064 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -164,13 +164,6 @@ void PrintDialog::onFinished() void PrintDialog::previewClicked(void) { - if (printOptions.type == print_options::STATISTICS) { - QMessageBox msgBox; - msgBox.setText("This feature is not implemented yet"); - msgBox.exec(); - return; - } - QPrintPreviewDialog previewDialog(&qprinter, this, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowTitleHint); @@ -180,13 +173,6 @@ void PrintDialog::previewClicked(void) void PrintDialog::printClicked(void) { - if (printOptions.type == print_options::STATISTICS) { - QMessageBox msgBox; - msgBox.setText("This feature is not implemented yet"); - msgBox.exec(); - return; - } - QPrintDialog printDialog(&qprinter, this); if (printDialog.exec() == QDialog::Accepted) { switch (printOptions.type) { @@ -195,6 +181,7 @@ void PrintDialog::printClicked(void) printer->print(); break; case print_options::STATISTICS: + printer->print_statistics(); break; } close(); @@ -204,7 +191,14 @@ void PrintDialog::printClicked(void) void PrintDialog::onPaintRequested(QPrinter *printerPtr) { connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int))); - printer->print(); + switch (printOptions.type) { + case print_options::DIVELIST: + printer->print(); + break; + case print_options::STATISTICS: + printer->print_statistics(); + break; + } progressBar->setValue(0); disconnect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int))); } -- cgit v1.2.3-70-g09d2