Commit f1116bd9 authored by Volker Krause's avatar Volker Krause
Browse files

Move numeric timeline chart to new Aggregator API

parent 6b49f296
......@@ -80,6 +80,7 @@ AnalyticsView::AnalyticsView(QWidget* parent) :
auto chartModeGroup = new QActionGroup(this);
chartModeGroup->addAction(ui->actionSingularChart);
chartModeGroup->addAction(ui->actionTimelineChart);
connect(chartModeGroup, &QActionGroup::triggered, this, &AnalyticsView::updateChart);
auto chartMode = new QMenu(tr("&Char mode"), this);
chartMode->addAction(ui->actionSingularChart);
......@@ -111,6 +112,8 @@ AnalyticsView::AnalyticsView(QWidget* parent) :
AnalyticsView::~AnalyticsView()
{
disconnect(ui->chartView->chart(), &QObject::destroyed, this, &AnalyticsView::updateChart);
QSettings settings;
settings.beginGroup(QStringLiteral("Analytics"));
settings.setValue(QStringLiteral("TimeAggregationMode"), m_timeAggregationModel->aggregationMode());
......@@ -166,8 +169,32 @@ void AnalyticsView::chartSelected()
ui->actionTimelineChart->setChecked(chartMode & Aggregator::Timeline);
}
m_chart->setModel(aggr->timeAggregationModel());
// ui->chartView->setChart(aggr->timelineChart());
updateChart();
}
void AnalyticsView::updateChart()
{
auto aggr = ui->chartType->currentData().value<Aggregator*>();
if (!aggr)
return;
if (ui->chartView->chart())
disconnect(ui->chartView->chart(), &QObject::destroyed, this, &AnalyticsView::updateChart);
// TODO
if (ui->actionTimelineChart->isChecked()) {
if (aggr->timelineChart()) {
ui->chartView->setChart(aggr->timelineChart());
} else {
ui->chartView->setChart(m_chart->chart());
m_chart->setModel(aggr->timeAggregationModel());
}
} else if (ui->actionSingularChart->isChecked()) {
ui->chartView->setChart(aggr->singlularChart());
}
if (ui->chartView->chart())
connect(ui->chartView->chart(), &QObject::destroyed, this, &AnalyticsView::updateChart);
}
Aggregator* AnalyticsView::createAggregator(const Aggregation& aggr) const
......
......@@ -57,6 +57,7 @@ signals:
private:
void chartSelected();
void updateChart();
Aggregator* createAggregator(const Aggregation &aggr) const;
......
......@@ -18,8 +18,19 @@
#include "numericaggregator.h"
#include <model/numericaggregationmodel.h>
#include <model/timeaggregationmodel.h>
#include <QtCharts/QBarCategoryAxis>
#include <QtCharts/QBoxPlotSeries>
#include <QtCharts/QChart>
#include <QtCharts/QHBoxPlotModelMapper>
#include <QtCharts/QValueAxis>
#include <QApplication>
#include <QDateTime>
using namespace UserFeedback::Analyzer;
using namespace QtCharts;
NumericAggregator::NumericAggregator() = default;
NumericAggregator::~NumericAggregator() = default;
......@@ -45,11 +56,42 @@ QAbstractItemModel* NumericAggregator::timeAggregationModel()
m_model->setSourceModel(sourceModel());
const auto e = aggregation().elements().at(0);
m_model->setAggregationValue(e.schemaEntry().name() + QLatin1Char('.') + e.schemaEntryElement().name());
QObject::connect(m_model.get(), &QAbstractItemModel::modelReset, [this]() {
m_timelineChart.reset();
});
}
return m_model.get();
}
QtCharts::QChart* NumericAggregator::timelineChart()
{
return nullptr;
if (m_timelineChart)
return m_timelineChart.get();
m_timelineChart.reset(new QChart);
m_timelineChart->setTheme(qApp->palette().color(QPalette::Window).lightnessF() < 0.25 ? QChart::ChartThemeDark : QChart::ChartThemeLight);
auto xAxis = new QBarCategoryAxis(m_timelineChart.get());
auto yAxis = new QValueAxis(m_timelineChart.get());
m_timelineChart->addAxis(xAxis, Qt::AlignBottom);
m_timelineChart->addAxis(yAxis, Qt::AlignLeft);
auto series = new QBoxPlotSeries(m_timelineChart.get());
series->setName(displayName());
auto mapper = new QHBoxPlotModelMapper(series);
mapper->setModel(timeAggregationModel());
mapper->setFirstColumn(1);
mapper->setFirstBoxSetRow(0);
mapper->setLastBoxSetRow(timeAggregationModel()->rowCount());
mapper->setSeries(series);
m_timelineChart->addSeries(series);
series->attachAxis(xAxis);
series->attachAxis(yAxis);
QStringList l;
for (int i = 0; i < m_model->rowCount(); ++i) {
l.push_back(timeAggregationModel()->index(i, 0).data(TimeAggregationModel::DateTimeRole).toDateTime().toString(QStringLiteral("yyyy-MM-dd")));
}
xAxis->setCategories(l);
return m_timelineChart.get();
}
......@@ -40,6 +40,7 @@ public:
private:
std::unique_ptr<NumericAggregationModel> m_model;
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