Commit 74ace635 authored by Volker Krause's avatar Volker Krause
Browse files

Port TotalAggregator to the new charts API

parent f1116bd9
......@@ -93,5 +93,7 @@ QtCharts::QChart* NumericAggregator::timelineChart()
l.push_back(timeAggregationModel()->index(i, 0).data(TimeAggregationModel::DateTimeRole).toDateTime().toString(QStringLiteral("yyyy-MM-dd")));
}
xAxis->setCategories(l);
yAxis->setMinorTickCount(4);
return m_timelineChart.get();
}
......@@ -17,7 +17,20 @@
#include "totalaggregator.h"
#include <QtCharts/QAreaSeries>
#include <QtCharts/QChart>
#include <QtCharts/QDateTimeAxis>
#include <QtCharts/QLineSeries>
#include <QtCharts/QValueAxis>
#include <QtCharts/QVXYModelMapper>
#include <QApplication>
#include <QAbstractItemModel>
#include <numeric>
using namespace UserFeedback::Analyzer;
using namespace QtCharts;
TotalAggregator::TotalAggregator() = default;
TotalAggregator::~TotalAggregator() = default;
......@@ -39,6 +52,37 @@ QAbstractItemModel* TotalAggregator::timeAggregationModel()
QtCharts::QChart* TotalAggregator::timelineChart()
{
// TODO
return nullptr;
if (m_timelineChart)
return m_timelineChart.get();
QObject::connect(sourceModel(), &QAbstractItemModel::modelReset, sourceModel(), [this]() {
m_timelineChart.reset();
}, Qt::UniqueConnection);
m_timelineChart.reset(new QChart);
m_timelineChart->setTheme(qApp->palette().color(QPalette::Window).lightnessF() < 0.25 ? QChart::ChartThemeDark : QChart::ChartThemeLight);
auto xAxis = new QDateTimeAxis(m_timelineChart.get());
xAxis->setFormat(QStringLiteral("yyyy-MM-dd")); // TODO, follow aggregation mode
auto yAxis = new QValueAxis(m_timelineChart.get());
m_timelineChart->addAxis(xAxis, Qt::AlignBottom);
m_timelineChart->addAxis(yAxis, Qt::AlignLeft);
auto series = new QLineSeries(m_timelineChart.get());
series->setName(displayName());
auto mapper = new QVXYModelMapper(series);
mapper->setModel(timeAggregationModel());
mapper->setXColumn(0);
mapper->setYColumn(1);
mapper->setFirstRow(0);
mapper->setSeries(series);
m_timelineChart->addSeries(series);
series->attachAxis(xAxis);
series->attachAxis(yAxis);
xAxis->setTickCount(std::min(timeAggregationModel()->rowCount(), 12));
yAxis->setMin(0);
yAxis->setMinorTickCount(4);
return m_timelineChart.get();
}
......@@ -22,6 +22,8 @@
#include <QCoreApplication>
#include <memory>
namespace UserFeedback {
namespace Analyzer {
......@@ -36,6 +38,9 @@ public:
QString displayName() const override;
QAbstractItemModel* timeAggregationModel() override;
QtCharts::QChart* timelineChart() override;
private:
std::unique_ptr<QtCharts::QChart> m_timelineChart;
};
}}
......
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