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 <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2013-07-10 22:55:40 +03:00
parent eb4312c9ba
commit 9a99aa4c58
2 changed files with 17 additions and 11 deletions

View file

@ -3,9 +3,9 @@
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QApplication> #include <QApplication>
#include <QTextDocument> #include <QTextDocument>
#include <QAbstractTextDocumentLayout>
#include "mainwindow.h" #include "mainwindow.h"
#include "printlayout.h" #include "printlayout.h"
#include "../dive.h"
/* /*
struct options { struct options {
@ -86,25 +86,30 @@ void PrintLayout::printTable()
// setDefaultStyleSheet() doesn't work here? // setDefaultStyleSheet() doesn't work here?
QString htmlText = styleSheet + "<table cellspacing='0' width='100%'>"; QString htmlText = styleSheet + "<table cellspacing='0' width='100%'>";
QString htmlTextPrev; QString htmlTextPrev;
int pageCountNew = 1, pageCount = 1; int pageCountNew = 1, pageCount;
bool insertHeading = true; 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) { if (insertHeading) {
htmlText += insertTableHeadingRow(); htmlText += insertTableHeadingRow();
insertHeading = false; insertHeading = false;
} }
doc.setHtml(htmlText);
pageCount = doc.pageCount();
htmlTextPrev = htmlText; htmlTextPrev = htmlText;
htmlText += insertTableDataRow(); htmlText += insertTableDataRow(dive);
doc.setHtml(htmlText); doc.setHtml(htmlText);
pageCountNew = doc.pageCount(); 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) { if (pageCountNew > pageCount) {
htmlText = htmlTextPrev; htmlText = htmlTextPrev;
doc.setHtml(htmlText);
insertHeading = true; insertHeading = true;
i--;
} }
} }
htmlText += "</table>"; htmlText += "</table>";
@ -117,7 +122,7 @@ QString PrintLayout::insertTableHeadingRow()
return "<tr><th>TITLE</th><th>TITLE 2</th></tr>"; return "<tr><th>TITLE</th><th>TITLE 2</th></tr>";
} }
QString PrintLayout::insertTableDataRow() QString PrintLayout::insertTableDataRow(struct dive *dive)
{ {
return "<tr><td>hello</td></tr><tr><td>hello</td></tr>"; return "<tr><td>" + QString::number(dive->number) + "</td><td>hello2</td></tr>";
} }

View file

@ -6,6 +6,7 @@
#include "../display.h" #include "../display.h"
class PrintDialog; class PrintDialog;
struct dive;
class PrintLayout : public QObject { class PrintLayout : public QObject {
Q_OBJECT Q_OBJECT
@ -29,7 +30,7 @@ private:
void printTwoDives(); void printTwoDives();
void printTable(); void printTable();
QString insertTableHeadingRow(); QString insertTableHeadingRow();
QString insertTableDataRow(); QString insertTableDataRow(struct dive *dive);
}; };
#endif #endif