Add graph animation; support for line graphs
[harbour-pedalo.git] / src / statsmodel.cpp
index 52090c4..5bc8155 100644 (file)
@@ -1,12 +1,20 @@
 #include "statsmodel.h"
 
-StatsModel::StatsModel(QObject *parent) : QAbstractListModel(parent) {
-    roles[ValuesRole] = "values";
+StatsModel::StatsModel(QObject *parent) : QAbstractListModel(parent),
+    visibleIndex(-1)
+{
+    roles[TitleRole] = "title";
+    roles[BarValuesRole] = "barvalues";
+    roles[LineValuesRole] = "linevalues";
     roles[LabelsRole] = "labels";
+    roles[UnitsRole] = "units";
+    roles[MinValRole] = "minval";
+    roles[MaxValRole] = "maxval";
+    roles[StepRole] = "step";
 }
 
-void StatsModel::addStats(const Stats &stats) {
-    this->stats.append(stats);
+void StatsModel::addStats(Stats &stats) {
+    this->stats.append(&stats);
 }
 
 QHash<int, QByteArray> StatsModel::roleNames() const {
@@ -22,11 +30,23 @@ QVariant StatsModel::data(const QModelIndex & index, int role) const {
     if (index.row() < 0 || index.row() > stats.count())
         return QVariant();
 
-    const Stats &stat = stats[index.row()];
-    if (role == ValuesRole)
-        return QVariant::fromValue<QList<float>>(stat.getValues());
+    const Stats *stat = stats[index.row()];
+    if (role == TitleRole)
+        return stat->getTitle();
+    else if (role == BarValuesRole)
+        return QVariant::fromValue<QList<float>>(stat->getBarValues());
+    else if (role == LineValuesRole)
+        return QVariant::fromValue<QList<float>>(stat->getLineValues());
     else if (role == LabelsRole)
-        return stat.getLabels();
+        return stat->getLabels();
+    else if (role == UnitsRole)
+        return stat->getUnits();
+    else if (role == MinValRole)
+        return stat->getMinVal();
+    else if (role == MaxValRole)
+        return stat->getMaxVal();
+    else if (role == StepRole)
+        return stat->getStep();
     return QVariant();
 }
 
@@ -34,3 +54,8 @@ void StatsModel::clear() {
     stats.clear();
 }
 
+void StatsModel::updateAll() {
+    foreach (Stats * stat, stats) {
+        stat->update();
+    }
+}