Add graph animation; support for line graphs
[harbour-pedalo.git] / src / statsmodel.cpp
1 #include "statsmodel.h"
2
3 StatsModel::StatsModel(QObject *parent) : QAbstractListModel(parent),
4 visibleIndex(-1)
5 {
6 roles[TitleRole] = "title";
7 roles[BarValuesRole] = "barvalues";
8 roles[LineValuesRole] = "linevalues";
9 roles[LabelsRole] = "labels";
10 roles[UnitsRole] = "units";
11 roles[MinValRole] = "minval";
12 roles[MaxValRole] = "maxval";
13 roles[StepRole] = "step";
14 }
15
16 void StatsModel::addStats(Stats &stats) {
17 this->stats.append(&stats);
18 }
19
20 QHash<int, QByteArray> StatsModel::roleNames() const {
21 return roles;
22 }
23
24 int StatsModel::rowCount(const QModelIndex & parent) const {
25 Q_UNUSED(parent)
26 return stats.count();
27 }
28
29 QVariant StatsModel::data(const QModelIndex & index, int role) const {
30 if (index.row() < 0 || index.row() > stats.count())
31 return QVariant();
32
33 const Stats *stat = stats[index.row()];
34 if (role == TitleRole)
35 return stat->getTitle();
36 else if (role == BarValuesRole)
37 return QVariant::fromValue<QList<float>>(stat->getBarValues());
38 else if (role == LineValuesRole)
39 return QVariant::fromValue<QList<float>>(stat->getLineValues());
40 else if (role == LabelsRole)
41 return stat->getLabels();
42 else if (role == UnitsRole)
43 return stat->getUnits();
44 else if (role == MinValRole)
45 return stat->getMinVal();
46 else if (role == MaxValRole)
47 return stat->getMaxVal();
48 else if (role == StepRole)
49 return stat->getStep();
50 return QVariant();
51 }
52
53 void StatsModel::clear() {
54 stats.clear();
55 }
56
57 void StatsModel::updateAll() {
58 foreach (Stats * stat, stats) {
59 stat->update();
60 }
61 }