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 @@
#include <model/categoryaggregationmodel.h>
#include <model/extrarowsproxymodel.h>
#include <model/rolemappingproxymodel.h>
#include <model/timeaggregationmodel.h>
#include <QtCharts/QAreaSeries>
#include <QtCharts/QChart>
......@@ -79,11 +81,14 @@ QtCharts::QChart* CategoryAggregator::timelineChart()
m_timelineChart->addAxis(yAxis, Qt::AlignLeft);
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) {
auto series = new QLineSeries;
auto mapper = new QVXYModelMapper(series);
mapper->setModel(timeAggregationModel());
mapper->setModel(model);
mapper->setXColumn(0);
mapper->setYColumn(i);
mapper->setFirstRow(0);
......
......@@ -78,12 +78,14 @@ QVariant CategoryAggregationModel::data(const QModelIndex& index, int role) cons
}
const auto idx = index.row() * m_categories.size() + index.column() - 1;
if (role == Qt::DisplayRole) {
return m_data[idx];
} else if (role == TimeAggregationModel::DataDisplayRole) {
if (index.column() == 1)
switch (role) {
case TimeAggregationModel::AccumulatedDisplayRole:
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 {};
......
......@@ -136,7 +136,7 @@ QVariant TimeAggregationModel::data(const QModelIndex& index, int role) const
if (!index.isValid())
return {};
if (role == Qt::DisplayRole || role == DataDisplayRole) {
if (role == Qt::DisplayRole || role == DataDisplayRole || role == AccumulatedDisplayRole) {
const auto d = m_data.at(index.row());
switch (index.column()) {
case 0: return d.time.toMSecsSinceEpoch(); // this is required by QtCharts...
......
......@@ -43,6 +43,7 @@ public:
MaximumValueRole,
TimeDisplayRole,
DataDisplayRole,
AccumulatedDisplayRole,
SamplesRole,
AllSamplesRole
};
......
......@@ -103,12 +103,14 @@ private slots:
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, 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, 1).data(Qt::DisplayRole).toInt(), 1);
QCOMPARE(model.index(1, 2).data(Qt::DisplayRole).toInt(), 1);
QCOMPARE(model.index(0, 3).data(Qt::DisplayRole).toInt(), 3);
QCOMPARE(model.index(1, 2).data(Qt::DisplayRole).toInt(), 0);
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);
}
......
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