summaryrefslogtreecommitdiffstats
path: root/templatelayout.cpp
diff options
context:
space:
mode:
authorGravatar Gehad elrobey <gehadelrobey@gmail.com>2015-08-21 19:03:42 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2015-08-22 18:35:51 +0300
commitb0e84e7e2b2a6e7252cd24d6df9d0b93af127d77 (patch)
treeb339900ff868bebb8b744970ba2bcb9ed26529d6 /templatelayout.cpp
parent70e8862efc7189342ee9c016e85054538b4d7b99 (diff)
downloadsubsurface-b0e84e7e2b2a6e7252cd24d6df9d0b93af127d77.tar.gz
Printing: generate a Grantlee statistics template
As there are two types of templates, Grantlee need to support both. This commit adds the support to generating a statistics HTML code from a statistics template. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Diffstat (limited to 'templatelayout.cpp')
-rw-r--r--templatelayout.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/templatelayout.cpp b/templatelayout.cpp
index 9245befbe..c52968f09 100644
--- a/templatelayout.cpp
+++ b/templatelayout.cpp
@@ -108,6 +108,53 @@ QString TemplateLayout::generate()
return htmlContent;
}
+QString TemplateLayout::generateStatistics()
+{
+ QString htmlContent;
+ m_engine = new Grantlee::Engine(this);
+
+ QSharedPointer<Grantlee::FileSystemTemplateLoader> m_templateLoader =
+ QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader());
+ m_templateLoader->setTemplateDirs(QStringList() << getSubsurfaceDataPath("printing_templates/statistics"));
+ m_engine->addTemplateLoader(m_templateLoader);
+
+ Grantlee::registerMetaType<YearInfo>();
+ Grantlee::registerMetaType<template_options>();
+ Grantlee::registerMetaType<print_options>();
+
+ QVariantHash mapping;
+ QVariantList years;
+
+ int i = 0;
+ while (stats_yearly != NULL && stats_yearly[i].period) {
+ YearInfo year(stats_yearly[i]);
+ years.append(QVariant::fromValue(year));
+ i++;
+ }
+
+ mapping.insert("years", years);
+ mapping.insert("template_options", QVariant::fromValue(*templateOptions));
+ mapping.insert("print_options", QVariant::fromValue(*PrintOptions));
+
+ Grantlee::Context c(mapping);
+
+ Grantlee::Template t = m_engine->loadByName(PrintOptions->p_template);
+ if (!t || t->error()) {
+ qDebug() << "Can't load template";
+ return htmlContent;
+ }
+
+ htmlContent = t->render(&c);
+
+ if (t->error()) {
+ qDebug() << "Can't render template";
+ return htmlContent;
+ }
+
+ emit progressUpdated(100);
+ return htmlContent;
+}
+
QString TemplateLayout::readTemplate(QString template_name)
{
QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name);