aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gehad elrobey <gehadelrobey@gmail.com>2015-08-21 19:12:33 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2015-08-22 18:36:19 +0300
commit69f2921ffa856e93acb9bc920f3f761db2831880 (patch)
treed1d52b49b032e154780ab714e2fd93259c165a88
parent4553155cf319df3e06e8b29adcabe6125943335a (diff)
downloadsubsurface-69f2921ffa856e93acb9bc920f3f761db2831880.tar.gz
Printing: use the same code for both statistics and divelist print
- use the same generic code for both types of templates - check for the printing type before generating the template - remove unused printStatistics() method Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
-rw-r--r--printer.cpp66
-rw-r--r--printer.h1
-rw-r--r--qt-ui/printdialog.cpp20
3 files changed, 13 insertions, 74 deletions
diff --git a/printer.cpp b/printer.cpp
index 66fed7cf3..3068a6fef 100644
--- a/printer.cpp
+++ b/printer.cpp
@@ -213,7 +213,11 @@ void Printer::print()
webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
// export border width with at least 1 pixel
templateOptions->border_width = std::max(1, pageSize.width() / 1000);
- webView->setHtml(t.generate());
+ if (printOptions->type == print_options::DIVELIST) {
+ webView->setHtml(t.generate());
+ } else if (printOptions->type == print_options::STATISTICS ) {
+ webView->setHtml(t.generateStatistics());
+ }
if (printOptions->color_selected && printerPtr->colorMode()) {
printerPtr->setColorMode(QPrinter::Color);
} else {
@@ -238,60 +242,6 @@ void Printer::print()
}
}
-void Printer::print_statistics()
-{
- QPrinter *printerPtr;
- printerPtr = static_cast<QPrinter*>(paintDevice);
- stats_t total_stats;
-
- total_stats.selection_size = 0;
- total_stats.total_time.seconds = 0;
-
- QString html;
- html += "<table border=1>";
- html += "<tr>";
- html += "<td>Year</td>";
- html += "<td>Dives</td>";
- html += "<td>Total Time</td>";
- html += "<td>Avg Time</td>";
- html += "<td>Shortest Time</td>";
- html += "<td>Longest Time</td>";
- html += "<td>Avg Depth</td>";
- html += "<td>Min Depth</td>";
- html += "<td>Max Depth</td>";
- html += "<td>Avg SAC</td>";
- html += "<td>Min SAC</td>";
- html += "<td>Max SAC</td>";
- html += "<td>Min Temp</td>";
- html += "<td>Max Temp</td>";
- html += "</tr>";
- int i = 0;
- while (stats_yearly != NULL && stats_yearly[i].period) {
- html += "<tr>";
- html += "<td>" + QString::number(stats_yearly[i].period) + "</td>";
- html += "<td>" + QString::number(stats_yearly[i].selection_size) + "</td>";
- html += "<td>" + QString::fromUtf8(get_time_string(stats_yearly[i].total_time.seconds, 0)) + "</td>";
- html += "<td>" + QString::fromUtf8(get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size)) + "</td>";
- html += "<td>" + QString::fromUtf8(get_minutes(stats_yearly[i].shortest_time.seconds)) + "</td>";
- html += "<td>" + QString::fromUtf8(get_minutes(stats_yearly[i].longest_time.seconds)) + "</td>";
- html += "<td>" + get_depth_string(stats_yearly[i].avg_depth) + "</td>";
- html += "<td>" + get_depth_string(stats_yearly[i].min_depth) + "</td>";
- html += "<td>" + get_depth_string(stats_yearly[i].max_depth) + "</td>";
- html += "<td>" + get_volume_string(stats_yearly[i].avg_sac) + "</td>";
- html += "<td>" + get_volume_string(stats_yearly[i].min_sac) + "</td>";
- html += "<td>" + get_volume_string(stats_yearly[i].max_sac) + "</td>";
- html += "<td>" + QString::number(stats_yearly[i].min_temp == 0 ? 0 : get_temp_units(stats_yearly[i].min_temp, NULL)) + "</td>";
- html += "<td>" + QString::number(stats_yearly[i].max_temp == 0 ? 0 : get_temp_units(stats_yearly[i].max_temp, NULL)) + "</td>";
- html += "</tr>";
- total_stats.selection_size += stats_yearly[i].selection_size;
- total_stats.total_time.seconds += stats_yearly[i].total_time.seconds;
- i++;
- }
- html += "</table>";
- webView->setHtml(html);
- webView->print(printerPtr);
-}
-
void Printer::previewOnePage()
{
if (printMode == PREVIEW) {
@@ -302,7 +252,11 @@ void Printer::previewOnePage()
webView->page()->setViewportSize(pageSize);
// initialize the border settings
templateOptions->border_width = std::max(1, pageSize.width() / 1000);
- webView->setHtml(t.generate());
+ if (printOptions->type == print_options::DIVELIST) {
+ webView->setHtml(t.generate());
+ } else if (printOptions->type == print_options::STATISTICS ) {
+ webView->setHtml(t.generateStatistics());
+ }
bool ok;
int divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok);
diff --git a/printer.h b/printer.h
index 5c7652a8d..979cacd6a 100644
--- a/printer.h
+++ b/printer.h
@@ -39,7 +39,6 @@ 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 002f9b9f4..cf08062d2 100644
--- a/qt-ui/printdialog.cpp
+++ b/qt-ui/printdialog.cpp
@@ -178,15 +178,8 @@ void PrintDialog::printClicked(void)
{
QPrintDialog printDialog(&qprinter, this);
if (printDialog.exec() == QDialog::Accepted) {
- switch (printOptions.type) {
- case print_options::DIVELIST:
- connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
- printer->print();
- break;
- case print_options::STATISTICS:
- printer->print_statistics();
- break;
- }
+ connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
+ printer->print();
close();
}
}
@@ -194,14 +187,7 @@ void PrintDialog::printClicked(void)
void PrintDialog::onPaintRequested(QPrinter *printerPtr)
{
connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
- switch (printOptions.type) {
- case print_options::DIVELIST:
- printer->print();
- break;
- case print_options::STATISTICS:
- printer->print_statistics();
- break;
- }
+ printer->print();
progressBar->setValue(0);
disconnect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
}