Commit 13bac488 authored by Volker Krause's avatar Volker Krause
Browse files

Fix singular ratio set charts

parent 31f70778
......@@ -101,11 +101,13 @@ private slots:
QCOMPARE(model.rowCount(), 3);
QCOMPARE(model.index(0, 0).data(TimeAggregationModel::TimeDisplayRole).toString(), QLatin1String("2016-11-27"));
QCOMPARE(model.index(0, 1).data(Qt::DisplayRole).toDouble(), 0.3);
QCOMPARE(model.index(0, 2).data(Qt::DisplayRole).toDouble(), 1.0); // cumulative
QCOMPARE(model.index(0, 2).data(Qt::DisplayRole).toDouble(), 0.7);
QCOMPARE(model.index(0, 2).data(TimeAggregationModel::AccumulatedDisplayRole).toDouble(), 1.0);
QCOMPARE(model.index(1, 0).data(TimeAggregationModel::TimeDisplayRole).toString(), QLatin1String("2016-11-28"));
QCOMPARE(model.index(1, 1).data(Qt::DisplayRole).toDouble(), 1.0);
QCOMPARE(model.index(1, 2).data(Qt::DisplayRole).toDouble(), 1.0);
QCOMPARE(model.index(1, 2).data(Qt::DisplayRole).toDouble(), 0.0);
QCOMPARE(model.index(1, 2).data(TimeAggregationModel::AccumulatedDisplayRole).toDouble(), 1.0);
QCOMPARE(model.index(2, 0).data(TimeAggregationModel::TimeDisplayRole).toString(), QLatin1String("2016-11-29"));
QCOMPARE(model.index(2, 1).data(Qt::DisplayRole).toDouble(), 0.0);
......
......@@ -20,6 +20,8 @@
#include <model/extrarowsproxymodel.h>
#include <model/ratiosetaggregationmodel.h>
#include <model/rolemappingproxymodel.h>
#include <model/timeaggregationmodel.h>
#include <QtCharts/QAreaSeries>
#include <QtCharts/QChart>
......@@ -82,12 +84,16 @@ void RatioSetAggregator::updateTimelineChart()
return;
m_timelineChart->removeAllSeries();
auto model = new RoleMappingProxyModel(m_timelineChart.get());
model->setSourceModel(timeAggregationModel());
model->addRoleMapping(Qt::DisplayRole, TimeAggregationModel::AccumulatedDisplayRole);
QLineSeries *prevSeries = nullptr;
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);
......@@ -95,7 +101,7 @@ void RatioSetAggregator::updateTimelineChart()
auto areaSeries = new QAreaSeries(series, prevSeries);
series->setParent(areaSeries); // otherwise series isn't deleted by removeAllSeries!
areaSeries->setName(timeAggregationModel()->headerData(i, Qt::Horizontal).toString().toHtmlEscaped());
areaSeries->setName(model->headerData(i, Qt::Horizontal).toString().toHtmlEscaped());
m_timelineChart->addSeries(areaSeries);
areaSeries->attachAxis(m_timelineChart->axisX());
......@@ -104,7 +110,7 @@ void RatioSetAggregator::updateTimelineChart()
prevSeries = series;
}
qobject_cast<QDateTimeAxis*>(m_timelineChart->axisX())->setTickCount(std::min(timeAggregationModel()->rowCount(), 12));
qobject_cast<QDateTimeAxis*>(m_timelineChart->axisX())->setTickCount(std::min(model->rowCount(), 12));
m_timelineChart->axisY()->setRange(0, 1); // TODO can we turn this into *100% for display?
}
......
......@@ -74,12 +74,14 @@ QVariant RatioSetAggregationModel::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 {};
......
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