From 9a99aa4c58ff68b4c83363ce5696c41e14069ff6 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Wed, 10 Jul 2013 22:55:40 +0300 Subject: Print: use the actual dive table Currently only for the table print, but now we use the actual dive table to iterate trough all dives (find only selected if needed) and print their 'number' element in table rows. Also improves the new-page detection algorithm slightly. Signed-off-by: Lubomir I. Ivanov --- qt-ui/printlayout.cpp | 25 +++++++++++++++---------- qt-ui/printlayout.h | 3 ++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp index 0571f30d3..daec82af2 100644 --- a/qt-ui/printlayout.cpp +++ b/qt-ui/printlayout.cpp @@ -3,9 +3,9 @@ #include #include #include -#include #include "mainwindow.h" #include "printlayout.h" +#include "../dive.h" /* struct options { @@ -86,25 +86,30 @@ void PrintLayout::printTable() // setDefaultStyleSheet() doesn't work here? QString htmlText = styleSheet + ""; QString htmlTextPrev; - int pageCountNew = 1, pageCount = 1; + int pageCountNew = 1, pageCount; bool insertHeading = true; - while (pageCount < 3) { // should go trough dives (or selected) instead + int i; + struct dive *dive; + for_each_dive(i, dive) { + pageCount = pageCountNew; + if (!dive->selected && printOptions->print_selected) { + continue; + } if (insertHeading) { htmlText += insertTableHeadingRow(); insertHeading = false; } - doc.setHtml(htmlText); - pageCount = doc.pageCount(); htmlTextPrev = htmlText; - htmlText += insertTableDataRow(); + htmlText += insertTableDataRow(dive); doc.setHtml(htmlText); pageCountNew = doc.pageCount(); - // if the page count increases here we revert and add a heading instead + /* if the page count increases after adding this row we 'revert' + * and add a heading instead. */ if (pageCountNew > pageCount) { htmlText = htmlTextPrev; - doc.setHtml(htmlText); insertHeading = true; + i--; } } htmlText += "
"; @@ -117,7 +122,7 @@ QString PrintLayout::insertTableHeadingRow() return "TITLETITLE 2"; } -QString PrintLayout::insertTableDataRow() +QString PrintLayout::insertTableDataRow(struct dive *dive) { - return "hellohello"; + return "" + QString::number(dive->number) + "hello2"; } diff --git a/qt-ui/printlayout.h b/qt-ui/printlayout.h index 9328030f4..0b9bbc146 100644 --- a/qt-ui/printlayout.h +++ b/qt-ui/printlayout.h @@ -6,6 +6,7 @@ #include "../display.h" class PrintDialog; +struct dive; class PrintLayout : public QObject { Q_OBJECT @@ -29,7 +30,7 @@ private: void printTwoDives(); void printTable(); QString insertTableHeadingRow(); - QString insertTableDataRow(); + QString insertTableDataRow(struct dive *dive); }; #endif -- cgit v1.2.3-70-g09d2