aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/models.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-17 21:05:17 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-17 21:05:17 -0300
commit87e380c7a28b467705b470323275db3812e0fa90 (patch)
treea9f1015754e0ca2cb2c575605a430bc998b738e8 /qt-ui/models.cpp
parenta05ea5a6e8f50213559b096871905f9777059eb4 (diff)
downloadsubsurface-87e380c7a28b467705b470323275db3812e0fa90.tar.gz
Yearly stats are being displayed.
Yearly stats are being displayed. the code is similar to the GTK one, but I advise the reader that it's a bit risky ( I got an unreproducible crash but it seems to be fixed now. ). The selection behavior is *weird* and I have no idea why, but I'm very sleepy - will try to look at it again tomorrow. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r--qt-ui/models.cpp83
1 files changed, 82 insertions, 1 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index f2dcc3cd9..2de8ababa 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -8,6 +8,8 @@
#include "../helpers.h"
#include "../dive.h"
#include "../device.h"
+#include "../statistics.h"
+
#include <QCoreApplication>
#include <QDebug>
@@ -1282,9 +1284,70 @@ void DiveComputerModel::remove(const QModelIndex& i)
* ################################################################
*/
+class YearStatisticsItem : public TreeItem{
+public:
+ enum { YEAR,DIVES,TOTAL_TIME,AVERAGE_TIME,SHORTEST_TIME,LONGEST_TIME,AVG_DEPTH,MIN_DEPTH,
+ MAX_DEPTH,AVG_SAC,MIN_SAC,MAX_SAC,AVG_TEMP,MIN_TEMP,MAX_TEMP,COLUMNS};
+
+ QVariant data(int column, int role) const;
+ YearStatisticsItem(stats_t interval);
+private:
+ stats_t stats_interval;
+};
+
+YearStatisticsItem::YearStatisticsItem(stats_t interval)
+: stats_interval(interval)
+{
+}
+
+QVariant YearStatisticsItem::data(int column, int role) const
+{
+ const char *unit;
+ QVariant ret;
+
+ if (role != Qt::DisplayRole){
+ return ret;
+ }
+
+ switch(column){
+ case YEAR: ret = stats_interval.period; break;
+ case DIVES: ret = stats_interval.selection_size;break;
+ case TOTAL_TIME: ret = get_time_string(stats_interval.total_time.seconds, 0);break;
+ case AVERAGE_TIME: ret = get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size);break;
+ case SHORTEST_TIME: ret = get_minutes(stats_interval.shortest_time.seconds);break;
+ case LONGEST_TIME: ret = get_minutes(stats_interval.longest_time.seconds);break;
+ case AVG_DEPTH: ret = stats_interval.avg_depth.mm;break;
+ case MIN_DEPTH: ret = stats_interval.min_depth.mm;break;
+ case MAX_DEPTH: ret = stats_interval.max_depth.mm;break;
+ case AVG_SAC: ret = stats_interval.avg_sac.mliter;break;
+ case MIN_SAC: ret = stats_interval.min_sac.mliter;break;
+ case MAX_SAC: ret = stats_interval.max_sac.mliter;break;
+ case AVG_TEMP:{
+ get_temp_units(stats_interval.min_temp, &unit);
+ if (stats_interval.combined_temp && stats_interval.combined_count) {
+ ret = QString("%1 %2").arg(stats_interval.combined_temp / stats_interval.combined_count).arg(unit);
+ }
+ }break;
+ case MIN_TEMP:{
+ double value = get_temp_units(stats_interval.min_temp, &unit);
+ if (value > -100.0) {
+ ret = QString("%1 %2").arg(value).arg(unit);
+ }
+ }break;
+ case MAX_TEMP:{
+ double value = get_temp_units(stats_interval.max_temp, &unit);
+ if (value > -100.0) {
+ ret = QString("%1 %2").arg(value).arg(unit);
+ }
+ }break;
+ }
+ return ret;
+}
+
YearlyStatisticsModel::YearlyStatisticsModel(QObject* parent)
{
columns = COLUMNS;
+ update_yearly_stats();
}
QVariant YearlyStatisticsModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -1293,7 +1356,7 @@ QVariant YearlyStatisticsModel::headerData(int section, Qt::Orientation orientat
if (role == Qt::FontRole){
val = defaultModelFont();
}
-
+
if (role == Qt::DisplayRole && orientation == Qt::Horizontal){
switch(section){
case YEAR: val = tr("Year \n > Month"); break;
@@ -1315,3 +1378,21 @@ QVariant YearlyStatisticsModel::headerData(int section, Qt::Orientation orientat
}
return val;
}
+
+void YearlyStatisticsModel::update_yearly_stats()
+{
+ int i, month = 0;
+ unsigned int j, combined_months;
+
+ for (i = 0; stats_yearly != NULL && stats_yearly[i].period; ++i){
+ YearStatisticsItem *item = new YearStatisticsItem(stats_yearly[i]);
+ combined_months = 0;
+ for (j = 0; combined_months < stats_yearly[i].selection_size; ++j) {
+ combined_months += stats_monthly[month].selection_size;
+ YearStatisticsItem *iChild = new YearStatisticsItem(stats_monthly[month]);
+ item->children.append(iChild);
+ month++;
+ }
+ rootItem->children.append(item);
+ }
+}