Support multiple graphs
[harbour-pedalo.git] / src / statsmodel.cpp
diff --git a/src/statsmodel.cpp b/src/statsmodel.cpp
new file mode 100644 (file)
index 0000000..52090c4
--- /dev/null
@@ -0,0 +1,36 @@
+#include "statsmodel.h"
+
+StatsModel::StatsModel(QObject *parent) : QAbstractListModel(parent) {
+    roles[ValuesRole] = "values";
+    roles[LabelsRole] = "labels";
+}
+
+void StatsModel::addStats(const Stats &stats) {
+    this->stats.append(stats);
+}
+
+QHash<int, QByteArray> StatsModel::roleNames() const {
+    return roles;
+}
+
+int StatsModel::rowCount(const QModelIndex & parent) const {
+    Q_UNUSED(parent)
+    return stats.count();
+}
+
+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());
+    else if (role == LabelsRole)
+        return stat.getLabels();
+    return QVariant();
+}
+
+void StatsModel::clear() {
+    stats.clear();
+}
+