From 70e8862efc7189342ee9c016e85054538b4d7b99 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <gehadelrobey@gmail.com>
Date: Fri, 21 Aug 2015 19:00:46 +0200
Subject: [PATCH] Printing: export a statistics data structure to the Grantlee
 backend

Add a YearInfo class which represents a year statistics. Export the
class to the Grantlee backend, also export all it's members to the
printing backend.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
---
 templatelayout.cpp | 10 +++++++++
 templatelayout.h   | 52 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/templatelayout.cpp b/templatelayout.cpp
index 2da048266..9245befbe 100644
--- a/templatelayout.cpp
+++ b/templatelayout.cpp
@@ -316,3 +316,13 @@ void Dive::put_sac()
 		m_sac = QString::number(value, 'f', decimal).append(unit);
 	}
 }
+
+YearInfo::YearInfo()
+{
+
+}
+
+YearInfo::~YearInfo()
+{
+
+}
diff --git a/templatelayout.h b/templatelayout.h
index 41a3cbfa9..47ca31f4c 100644
--- a/templatelayout.h
+++ b/templatelayout.h
@@ -4,6 +4,8 @@
 #include <grantlee_templates.h>
 #include "mainwindow.h"
 #include "printoptions.h"
+#include "statistics.h"
+#include "helpers.h"
 
 int getTotalWork(print_options *printOptions);
 void find_all_templates();
@@ -98,9 +100,22 @@ public:
 	QString sac() const;
 };
 
+class YearInfo {
+public:
+	stats_t *year;
+	YearInfo(stats_t& year)
+		:year(&year)
+	{
+
+	}
+	YearInfo();
+	~YearInfo();
+};
+
 Q_DECLARE_METATYPE(Dive)
 Q_DECLARE_METATYPE(template_options)
 Q_DECLARE_METATYPE(print_options)
+Q_DECLARE_METATYPE(YearInfo)
 
 GRANTLEE_BEGIN_LOOKUP(Dive)
 if (property == "number")
@@ -182,4 +197,41 @@ if (property == "grayscale") {
 }
 GRANTLEE_END_LOOKUP
 
+GRANTLEE_BEGIN_LOOKUP(YearInfo)
+
+if (property == "year") {
+	return object.year->period;
+} else if (property == "dives") {
+	return object.year->selection_size;
+} else if (property == "min_temp") {
+	const char *unit;
+	double temp = get_temp_units(object.year->min_temp, &unit);
+	return object.year->min_temp == 0 ? "0" : QString::number(temp, 'g', 2) + unit;
+} else if (property == "max_temp") {
+	const char *unit;
+	double temp = get_temp_units(object.year->max_temp, &unit);
+	return object.year->max_temp == 0 ? "0" : QString::number(temp, 'g', 2) + unit;
+} else if (property == "total_time") {
+	return get_time_string(object.year->total_time.seconds, 0);
+} else if (property == "avg_time") {
+	return get_minutes(object.year->total_time.seconds / object.year->selection_size);
+} else if (property == "shortest_time") {
+	return get_minutes(object.year->shortest_time.seconds);
+} else if (property == "longest_time") {
+	return get_minutes(object.year->longest_time.seconds);
+} else if (property == "avg_depth") {
+	return get_depth_string(object.year->avg_depth);
+} else if (property == "min_depth") {
+	return get_depth_string(object.year->min_depth);
+} else if (property == "max_depth") {
+	return get_depth_string(object.year->max_depth);
+} else if (property == "avg_sac") {
+	return get_volume_string(object.year->avg_sac);
+} else if (property == "min_sac") {
+	return get_volume_string(object.year->min_sac);
+} else if (property == "max_sac") {
+	return get_volume_string(object.year->max_sac);
+}
+GRANTLEE_END_LOOKUP
+
 #endif