Printing: Add progress updating ability to print dialog

The progress bar shows the progress of both the rendering part and the
templating part, unfortunately we can't check the progress of Grantlee
templating engine so the progess bar doesn't have a constant pace it
stops a little around 20%.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Gehad elrobey 2015-05-30 15:32:15 +02:00 committed by Dirk Hohndel
parent 231f90bd26
commit a820688aeb
5 changed files with 42 additions and 2 deletions

View file

@ -17,6 +17,7 @@ Printer::Printer(QPrinter *printer)
printer->setPaperSize(QPrinter::A4);
printer->setPrintRange(QPrinter::AllPages);
printer->setResolution(300);
done = 0;
}
void Printer::render()
@ -33,15 +34,25 @@ void Printer::render()
for (int i = 0; i < Pages; i++) {
webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer);
webView->page()->mainFrame()->scroll(0, A4_300DPI_HIGHT);
//rendering progress is 4/5 of total work
emit(progessUpdated((i * 80.0 / Pages) + done));
if (i < Pages - 1)
printer->newPage();
}
painter.end();
}
//value: ranges from 0 : 100 and shows the progress of the templating engine
void Printer::templateProgessUpdated(int value)
{
done = value / 5; //template progess if 1/5 of total work
emit progessUpdated(done);
}
void Printer::print()
{
TemplateLayout t;
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
webView = new QWebView();
webView->setHtml(t.generate());
render();

View file

@ -11,10 +11,17 @@ private:
QPrinter *printer;
QWebView *webView;
void render();
int done;
private slots:
void templateProgessUpdated(int value);
public:
Printer(QPrinter *printer);
void print();
signals:
void progessUpdated(int value);
};
#endif //PRINTER_H

View file

@ -96,6 +96,7 @@ void PrintDialog::printClicked(void)
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::TABLE:

View file

@ -10,10 +10,26 @@ TemplateLayout::TemplateLayout()
TemplateLayout::~TemplateLayout()
{
delete m_engine;
};
}
int TemplateLayout::getTotalWork()
{
int dives = 0, i;
struct dive *dive;
for_each_dive (i, dive) {
//TODO check for exporting selected dives only
if (!dive->selected)
continue;
dives++;
}
return dives;
}
QString TemplateLayout::generate()
{
int progress = 0;
int totalWork = getTotalWork();
QString htmlContent;
m_engine = new Grantlee::Engine(this);
@ -35,6 +51,8 @@ QString TemplateLayout::generate()
continue;
Dive d(dive);
diveList.append(QVariant::fromValue(d));
progress++;
emit progressUpdated(progress * 100.0 / totalWork);
}
mapping.insert("dives", diveList);
@ -52,7 +70,6 @@ QString TemplateLayout::generate()
qDebug() << "Can't render template";
return htmlContent;
}
return htmlContent;
}

View file

@ -13,6 +13,10 @@ public:
private:
Grantlee::Engine *m_engine;
int getTotalWork();
signals:
void progressUpdated(int value);
};
class Dive {