Commit 26a7edd7 authored by Volker Krause's avatar Volker Krause
Browse files

Make both individual and accumulated values available for categories

The singular chart now also shows correct values.
parent 7213eb6a
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include <model/categoryaggregationmodel.h> #include <model/categoryaggregationmodel.h>
#include <model/extrarowsproxymodel.h> #include <model/extrarowsproxymodel.h>
#include <model/rolemappingproxymodel.h>
#include <model/timeaggregationmodel.h>
#include <QtCharts/QAreaSeries> #include <QtCharts/QAreaSeries>
#include <QtCharts/QChart> #include <QtCharts/QChart>
...@@ -79,11 +81,14 @@ QtCharts::QChart* CategoryAggregator::timelineChart() ...@@ -79,11 +81,14 @@ QtCharts::QChart* CategoryAggregator::timelineChart()
m_timelineChart->addAxis(yAxis, Qt::AlignLeft); m_timelineChart->addAxis(yAxis, Qt::AlignLeft);
QLineSeries *prevSeries = nullptr; QLineSeries *prevSeries = nullptr;
auto model = new RoleMappingProxyModel(m_timelineChart.get());
model->setSourceModel(timeAggregationModel());
model->addRoleMapping(Qt::DisplayRole, TimeAggregationModel::AccumulatedDisplayRole);
for (int i = 1; i < timeAggregationModel()->columnCount(); ++i) { for (int i = 1; i < timeAggregationModel()->columnCount(); ++i) {
auto series = new QLineSeries; auto series = new QLineSeries;
auto mapper = new QVXYModelMapper(series); auto mapper = new QVXYModelMapper(series);
mapper->setModel(timeAggregationModel()); mapper->setModel(model);
mapper->setXColumn(0); mapper->setXColumn(0);
mapper->setYColumn(i); mapper->setYColumn(i);
mapper->setFirstRow(0); mapper->setFirstRow(0);
......
...@@ -78,12 +78,14 @@ QVariant CategoryAggregationModel::data(const QModelIndex& index, int role) cons ...@@ -78,12 +78,14 @@ QVariant CategoryAggregationModel::data(const QModelIndex& index, int role) cons
} }
const auto idx = index.row() * m_categories.size() + index.column() - 1; const auto idx = index.row() * m_categories.size() + index.column() - 1;
if (role == Qt::DisplayRole) { switch (role) {
return m_data[idx]; case TimeAggregationModel::AccumulatedDisplayRole:
} else if (role == TimeAggregationModel::DataDisplayRole) {
if (index.column() == 1)
return m_data[idx]; return m_data[idx];
return m_data[idx] - m_data[idx - 1]; case Qt::DisplayRole:
case TimeAggregationModel::DataDisplayRole:
if (index.column() == 1)
return m_data[idx];
return m_data[idx] - m_data[idx - 1];
} }
return {}; return {};
......
...@@ -136,7 +136,7 @@ QVariant TimeAggregationModel::data(const QModelIndex& index, int role) const ...@@ -136,7 +136,7 @@ QVariant TimeAggregationModel::data(const QModelIndex& index, int role) const
if (!index.isValid()) if (!index.isValid())
return {}; return {};
if (role == Qt::DisplayRole || role == DataDisplayRole) { if (role == Qt::DisplayRole || role == DataDisplayRole || role == AccumulatedDisplayRole) {
const auto d = m_data.at(index.row()); const auto d = m_data.at(index.row());
switch (index.column()) { switch (index.column()) {
case 0: return d.time.toMSecsSinceEpoch(); // this is required by QtCharts... case 0: return d.time.toMSecsSinceEpoch(); // this is required by QtCharts...
......
...@@ -43,6 +43,7 @@ public: ...@@ -43,6 +43,7 @@ public:
MaximumValueRole, MaximumValueRole,
TimeDisplayRole, TimeDisplayRole,
DataDisplayRole, DataDisplayRole,
AccumulatedDisplayRole,
SamplesRole, SamplesRole,
AllSamplesRole AllSamplesRole
}; };
......
...@@ -103,12 +103,14 @@ private slots: ...@@ -103,12 +103,14 @@ private slots:
QCOMPARE(model.index(0, 0).data(TimeAggregationModel::TimeDisplayRole).toString(), QLatin1String("2016-11-27")); QCOMPARE(model.index(0, 0).data(TimeAggregationModel::TimeDisplayRole).toString(), QLatin1String("2016-11-27"));
QCOMPARE(model.index(0, 1).data(Qt::DisplayRole).toInt(), 0); QCOMPARE(model.index(0, 1).data(Qt::DisplayRole).toInt(), 0);
QCOMPARE(model.index(0, 2).data(Qt::DisplayRole).toInt(), 1); QCOMPARE(model.index(0, 2).data(Qt::DisplayRole).toInt(), 1);
QCOMPARE(model.index(0, 3).data(Qt::DisplayRole).toInt(), 3); // values are cumulative QCOMPARE(model.index(0, 3).data(Qt::DisplayRole).toInt(), 2);
QCOMPARE(model.index(0, 3).data(TimeAggregationModel::AccumulatedDisplayRole).toInt(), 3);
QCOMPARE(model.index(1, 0).data(TimeAggregationModel::TimeDisplayRole).toString(), QLatin1String("2016-11-28")); QCOMPARE(model.index(1, 0).data(TimeAggregationModel::TimeDisplayRole).toString(), QLatin1String("2016-11-28"));
QCOMPARE(model.index(1, 1).data(Qt::DisplayRole).toInt(), 1); QCOMPARE(model.index(1, 1).data(Qt::DisplayRole).toInt(), 1);
QCOMPARE(model.index(1, 2).data(Qt::DisplayRole).toInt(), 1); QCOMPARE(model.index(1, 2).data(Qt::DisplayRole).toInt(), 0);
QCOMPARE(model.index(0, 3).data(Qt::DisplayRole).toInt(), 3); QCOMPARE(model.index(0, 3).data(Qt::DisplayRole).toInt(), 2);
QCOMPARE(model.index(0, 3).data(TimeAggregationModel::AccumulatedDisplayRole).toInt(), 3);
QCOMPARE(model.index(0, 0).data(TimeAggregationModel::MaximumValueRole).toInt(), 3); QCOMPARE(model.index(0, 0).data(TimeAggregationModel::MaximumValueRole).toInt(), 3);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment