Support multiple graphs
[harbour-pedalo.git] / src / statsmodel.cpp
1 #include "statsmodel.h"
2
3 StatsModel::StatsModel(QObject *parent) : QAbstractListModel(parent) {
4 roles[ValuesRole] = "values";
5 roles[LabelsRole] = "labels";
6 }
7
8 void StatsModel::addStats(const Stats &stats) {
9 this->stats.append(stats);
10 }
11
12 QHash<int, QByteArray> StatsModel::roleNames() const {
13 return roles;
14 }
15
16 int StatsModel::rowCount(const QModelIndex & parent) const {
17 Q_UNUSED(parent)
18 return stats.count();
19 }
20
21 QVariant StatsModel::data(const QModelIndex & index, int role) const {
22 if (index.row() < 0 || index.row() > stats.count())
23 return QVariant();
24
25 const Stats &stat = stats[index.row()];
26 if (role == ValuesRole)
27 return QVariant::fromValue<QList<float>>(stat.getValues());
28 else if (role == LabelsRole)
29 return stat.getLabels();
30 return QVariant();
31 }
32
33 void StatsModel::clear() {
34 stats.clear();
35 }
36