diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2015-05-28 18:12:11 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-05-29 14:12:48 -0700 |
commit | 7171d2e1ebc880cbee468a542e3fc907039539c5 (patch) | |
tree | 3c4bd5c93d29d546b924124c1031adea0645c7a7 /qt-models | |
parent | 9bc62748af1cbc0413f2cbc933650bad545f6d57 (diff) | |
download | subsurface-7171d2e1ebc880cbee468a542e3fc907039539c5.tar.gz |
Move the YearlyStatisticsModel to qt-models
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/models.cpp | 214 | ||||
-rw-r--r-- | qt-models/models.h | 29 | ||||
-rw-r--r-- | qt-models/yearlystatisticsmodel.cpp | 205 | ||||
-rw-r--r-- | qt-models/yearlystatisticsmodel.h | 33 |
4 files changed, 238 insertions, 243 deletions
diff --git a/qt-models/models.cpp b/qt-models/models.cpp index 15e66f5b5..85b26922d 100644 --- a/qt-models/models.cpp +++ b/qt-models/models.cpp @@ -36,20 +36,6 @@ const QPixmap &trashIcon() return trash; } -//################################################################################################# -//# -//# Tree Model - a Basic Tree Model so I don't need to kill myself repeating this for every model. -//# -//################################################################################################# - -/*! A DiveItem for use with a DiveTripModel - * - * A simple class which wraps basic stats for a dive (e.g. duration, depth) and - * tidies up after it's children. This is done manually as we don't inherit from - * QObject. - * -*/ - /*################################################################ * * Implementation of the Dive List. @@ -605,206 +591,6 @@ bool DiveTripModel::setData(const QModelIndex &index, const QVariant &value, int * ################################################################ */ -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 -{ - double value; - QVariant ret; - - if (role == Qt::FontRole) { - QFont font = defaultModelFont(); - font.setBold(stats_interval.is_year); - return font; - } else if (role != Qt::DisplayRole) { - return ret; - } - switch (column) { - case YEAR: - if (stats_interval.is_trip) { - ret = stats_interval.location; - } else { - 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 = get_depth_string(stats_interval.avg_depth); - break; - case MIN_DEPTH: - ret = get_depth_string(stats_interval.min_depth); - break; - case MAX_DEPTH: - ret = get_depth_string(stats_interval.max_depth); - break; - case AVG_SAC: - ret = get_volume_string(stats_interval.avg_sac); - break; - case MIN_SAC: - ret = get_volume_string(stats_interval.min_sac); - break; - case MAX_SAC: - ret = get_volume_string(stats_interval.max_sac); - break; - case AVG_TEMP: - if (stats_interval.combined_temp && stats_interval.combined_count) { - ret = QString::number(stats_interval.combined_temp / stats_interval.combined_count, 'f', 1); - } - break; - case MIN_TEMP: - value = get_temp_units(stats_interval.min_temp, NULL); - if (value > -100.0) - ret = QString::number(value, 'f', 1); - break; - case MAX_TEMP: - value = get_temp_units(stats_interval.max_temp, NULL); - if (value > -100.0) - ret = QString::number(value, 'f', 1); - break; - } - return ret; -} - -YearlyStatisticsModel::YearlyStatisticsModel(QObject *parent) -{ - columns = COLUMNS; - update_yearly_stats(); -} - -QVariant YearlyStatisticsModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - QVariant val; - if (role == Qt::FontRole) - val = defaultModelFont(); - - if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { - switch (section) { - case YEAR: - val = tr("Year \n > Month / Trip"); - break; - case DIVES: - val = tr("#"); - break; - case TOTAL_TIME: - val = tr("Duration \n Total"); - break; - case AVERAGE_TIME: - val = tr("\nAverage"); - break; - case SHORTEST_TIME: - val = tr("\nShortest"); - break; - case LONGEST_TIME: - val = tr("\nLongest"); - break; - case AVG_DEPTH: - val = QString(tr("Depth (%1)\n Average")).arg(get_depth_unit()); - break; - case MIN_DEPTH: - val = tr("\nMinimum"); - break; - case MAX_DEPTH: - val = tr("\nMaximum"); - break; - case AVG_SAC: - val = QString(tr("SAC (%1)\n Average")).arg(get_volume_unit()); - break; - case MIN_SAC: - val = tr("\nMinimum"); - break; - case MAX_SAC: - val = tr("\nMaximum"); - break; - case AVG_TEMP: - val = QString(tr("Temp. (%1)\n Average").arg(get_temp_unit())); - break; - case MIN_TEMP: - val = tr("\nMinimum"); - break; - case MAX_TEMP: - val = tr("\nMaximum"); - break; - } - } - 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); - iChild->parent = item; - month++; - } - rootItem->children.append(item); - item->parent = rootItem; - } - - - if (stats_by_trip != NULL && stats_by_trip[0].is_trip == true) { - YearStatisticsItem *item = new YearStatisticsItem(stats_by_trip[0]); - for (i = 1; stats_by_trip != NULL && stats_by_trip[i].is_trip; ++i) { - YearStatisticsItem *iChild = new YearStatisticsItem(stats_by_trip[i]); - item->children.append(iChild); - iChild->parent = item; - } - rootItem->children.append(item); - item->parent = rootItem; - } -} - /*################################################################# * # * # Table Print Model diff --git a/qt-models/models.h b/qt-models/models.h index e2a474e41..e6a3e5919 100644 --- a/qt-models/models.h +++ b/qt-models/models.h @@ -25,7 +25,6 @@ * */ - struct DiveItem : public TreeItem { enum Column { NR, @@ -61,7 +60,6 @@ struct DiveItem : public TreeItem { struct TripItem; - class DiveTripModel : public TreeModel { Q_OBJECT public: @@ -109,33 +107,6 @@ private: Layout currentLayout; }; -class YearlyStatisticsModel : public TreeModel { - Q_OBJECT -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 - }; - - virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - YearlyStatisticsModel(QObject *parent = 0); - void update_yearly_stats(); -}; - /* TablePrintModel: * for now we use a blank table model with row items TablePrintItem. * these are pretty much the same as DiveItem, but have color diff --git a/qt-models/yearlystatisticsmodel.cpp b/qt-models/yearlystatisticsmodel.cpp new file mode 100644 index 000000000..47d9891f2 --- /dev/null +++ b/qt-models/yearlystatisticsmodel.cpp @@ -0,0 +1,205 @@ +#include "yearlystatisticsmodel.h" +#include "dive.h" +#include "helpers.h" +#include "metrics.h" +#include "statistics.h" + +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 +{ + double value; + QVariant ret; + + if (role == Qt::FontRole) { + QFont font = defaultModelFont(); + font.setBold(stats_interval.is_year); + return font; + } else if (role != Qt::DisplayRole) { + return ret; + } + switch (column) { + case YEAR: + if (stats_interval.is_trip) { + ret = stats_interval.location; + } else { + 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 = get_depth_string(stats_interval.avg_depth); + break; + case MIN_DEPTH: + ret = get_depth_string(stats_interval.min_depth); + break; + case MAX_DEPTH: + ret = get_depth_string(stats_interval.max_depth); + break; + case AVG_SAC: + ret = get_volume_string(stats_interval.avg_sac); + break; + case MIN_SAC: + ret = get_volume_string(stats_interval.min_sac); + break; + case MAX_SAC: + ret = get_volume_string(stats_interval.max_sac); + break; + case AVG_TEMP: + if (stats_interval.combined_temp && stats_interval.combined_count) { + ret = QString::number(stats_interval.combined_temp / stats_interval.combined_count, 'f', 1); + } + break; + case MIN_TEMP: + value = get_temp_units(stats_interval.min_temp, NULL); + if (value > -100.0) + ret = QString::number(value, 'f', 1); + break; + case MAX_TEMP: + value = get_temp_units(stats_interval.max_temp, NULL); + if (value > -100.0) + ret = QString::number(value, 'f', 1); + break; + } + return ret; +} + +YearlyStatisticsModel::YearlyStatisticsModel(QObject *parent) +{ + columns = COLUMNS; + update_yearly_stats(); +} + +QVariant YearlyStatisticsModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + QVariant val; + if (role == Qt::FontRole) + val = defaultModelFont(); + + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { + switch (section) { + case YEAR: + val = tr("Year \n > Month / Trip"); + break; + case DIVES: + val = tr("#"); + break; + case TOTAL_TIME: + val = tr("Duration \n Total"); + break; + case AVERAGE_TIME: + val = tr("\nAverage"); + break; + case SHORTEST_TIME: + val = tr("\nShortest"); + break; + case LONGEST_TIME: + val = tr("\nLongest"); + break; + case AVG_DEPTH: + val = QString(tr("Depth (%1)\n Average")).arg(get_depth_unit()); + break; + case MIN_DEPTH: + val = tr("\nMinimum"); + break; + case MAX_DEPTH: + val = tr("\nMaximum"); + break; + case AVG_SAC: + val = QString(tr("SAC (%1)\n Average")).arg(get_volume_unit()); + break; + case MIN_SAC: + val = tr("\nMinimum"); + break; + case MAX_SAC: + val = tr("\nMaximum"); + break; + case AVG_TEMP: + val = QString(tr("Temp. (%1)\n Average").arg(get_temp_unit())); + break; + case MIN_TEMP: + val = tr("\nMinimum"); + break; + case MAX_TEMP: + val = tr("\nMaximum"); + break; + } + } + 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); + iChild->parent = item; + month++; + } + rootItem->children.append(item); + item->parent = rootItem; + } + + + if (stats_by_trip != NULL && stats_by_trip[0].is_trip == true) { + YearStatisticsItem *item = new YearStatisticsItem(stats_by_trip[0]); + for (i = 1; stats_by_trip != NULL && stats_by_trip[i].is_trip; ++i) { + YearStatisticsItem *iChild = new YearStatisticsItem(stats_by_trip[i]); + item->children.append(iChild); + iChild->parent = item; + } + rootItem->children.append(item); + item->parent = rootItem; + } +} diff --git a/qt-models/yearlystatisticsmodel.h b/qt-models/yearlystatisticsmodel.h new file mode 100644 index 000000000..5469ca9a2 --- /dev/null +++ b/qt-models/yearlystatisticsmodel.h @@ -0,0 +1,33 @@ +#ifndef YEARLYSTATISTICSMODEL_H +#define YEARLYSTATISTICSMODEL_H + +#include "treemodel.h" + +class YearlyStatisticsModel : public TreeModel { + Q_OBJECT +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 + }; + + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + YearlyStatisticsModel(QObject *parent = 0); + void update_yearly_stats(); +}; + +#endif |