Skip to content
Snippets Groups Projects
Commit 34a0761f authored by Volker Krause's avatar Volker Krause
Browse files

Remove the old chart code

parent 929f3df5
No related branches found
No related tags found
No related merge requests found
......@@ -40,7 +40,6 @@ set(analyzer_srcs
analytics/aggregator.cpp
analytics/analyticsview.cpp
analytics/categoryaggregator.cpp
analytics/chart.cpp
analytics/numericaggregator.cpp
analytics/ratiosetaggregator.cpp
analytics/totalaggregator.cpp
......
......@@ -20,7 +20,6 @@
#include "aggregator.h"
#include "categoryaggregator.h"
#include "chart.h"
#include "numericaggregator.h"
#include "ratiosetaggregator.h"
#include "totalaggregator.h"
......@@ -46,8 +45,7 @@ AnalyticsView::AnalyticsView(QWidget* parent) :
ui(new Ui::AnalyticsView),
m_dataModel(new DataModel(this)),
m_timeAggregationModel(new TimeAggregationModel(this)),
m_aggregatedDataModel(new AggregatedDataModel(this)),
m_chart(new Chart(this))
m_aggregatedDataModel(new AggregatedDataModel(this))
{
ui->setupUi(this);
......@@ -55,7 +53,6 @@ AnalyticsView::AnalyticsView(QWidget* parent) :
ui->aggregatedDataView->setModel(m_aggregatedDataModel);
m_timeAggregationModel->setSourceModel(m_dataModel);
m_chart->setModel(m_timeAggregationModel);
ui->actionAggregateYear->setData(TimeAggregationModel::AggregateYear);
ui->actionAggregateMonth->setData(TimeAggregationModel::AggregateMonth);
......@@ -106,7 +103,6 @@ AnalyticsView::AnalyticsView(QWidget* parent) :
m_timeAggregationModel->setAggregationMode(static_cast<TimeAggregationModel::AggregationMode>(aggrSetting));
settings.endGroup();
ui->chartView->setChart(m_chart->chart());
connect(ui->chartType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AnalyticsView::chartSelected);
}
......@@ -128,7 +124,6 @@ void AnalyticsView::setRESTClient(RESTClient* client)
void AnalyticsView::setProduct(const Product& product)
{
m_chart->setModel(nullptr);
m_dataModel->setProduct(product);
ui->chartType->clear();
......@@ -181,14 +176,8 @@ void AnalyticsView::updateChart()
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());
}
ui->chartView->setChart(aggr->timelineChart());
} else if (ui->actionSingularChart->isChecked()) {
ui->chartView->setChart(aggr->singlularChart());
}
......
......@@ -32,7 +32,6 @@ namespace Analyzer {
class Aggregator;
class AggregatedDataModel;
class Chart;
class DataModel;
class RESTClient;
class TimeAggregationModel;
......@@ -70,7 +69,6 @@ private:
DataModel *m_dataModel;
TimeAggregationModel *m_timeAggregationModel;
AggregatedDataModel *m_aggregatedDataModel;
Chart *m_chart;
QVector<Aggregator*> m_aggregators;
};
......
/*
Copyright (C) 2016 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "chart.h"
#include <model/categoryaggregationmodel.h>
#include <model/numericaggregationmodel.h>
#include <model/timeaggregationmodel.h>
#include <QtCharts/QAreaSeries>
#include <QtCharts/QBarCategoryAxis>
#include <QtCharts/QBoxPlotSeries>
#include <QtCharts/QChart>
#include <QtCharts/QDateTimeAxis>
#include <QtCharts/QLineSeries>
#include <QtCharts/QValueAxis>
#include <QtCharts/QVBoxPlotModelMapper>
#include <QtCharts/QVXYModelMapper>
#include <QAbstractItemModel>
#include <QApplication>
#include <QDateTime>
#include <numeric>
using namespace UserFeedback::Analyzer;
using namespace QtCharts;
Chart::Chart(QObject *parent) :
QObject(parent),
m_chart(new QChart),
m_xAxis(new QDateTimeAxis(this)),
m_boxXAxis(new QBarCategoryAxis(this)),
m_yAxis(new QValueAxis(this))
{
m_chart->setTheme(qApp->palette().color(QPalette::Window).lightnessF() < 0.25 ? QChart::ChartThemeDark : QChart::ChartThemeLight);
m_xAxis->setFormat(QStringLiteral("yyyy-MM-dd")); // TODO, follow aggregation mode
m_chart->addAxis(m_xAxis, Qt::AlignBottom);
m_chart->addAxis(m_boxXAxis, Qt::AlignBottom);
m_yAxis->setTickCount(5);
m_yAxis->setMinorTickCount(4);
m_chart->addAxis(m_yAxis, Qt::AlignLeft);
}
Chart::~Chart() = default;
QChart* Chart::chart() const
{
return m_chart.get();
}
void Chart::setModel(QAbstractItemModel* model)
{
if (m_model)
disconnect(m_model, &QAbstractItemModel::modelReset, this, &Chart::modelReset);
m_model = model;
if (!model) {
m_chart->removeAllSeries();
return;
}
connect(m_model, &QAbstractItemModel::modelReset, this, &Chart::modelReset);
modelReset();
}
void Chart::modelReset()
{
Q_ASSERT(m_model);
m_chart->removeAllSeries();
const auto colCount = m_model->columnCount();
if (m_model->rowCount() <= 0 || colCount <= 1)
return;
if (qobject_cast<NumericAggregationModel*>(m_model)) {
auto series = new QBoxPlotSeries(this);
series->setName(tr("TODO"));
auto mapper = new QVBoxPlotModelMapper(series);
mapper->setModel(m_model);
mapper->setFirstBoxSetColumn(1);
mapper->setLastBoxSetColumn(5);
mapper->setSeries(series);
m_chart->addSeries(series);
series->attachAxis(m_boxXAxis);
series->attachAxis(m_yAxis);
QStringList l;
for (int i = 0; i < m_model->rowCount(); ++i) {
l.push_back(m_model->index(i, 0).data(TimeAggregationModel::DateTimeRole).toDateTime().toString(QStringLiteral("yyyy-MM-dd")));
}
m_boxXAxis->setCategories(l);
m_boxXAxis->show();
m_xAxis->hide();
} else {
QLineSeries *prevSeries = nullptr;
for (int i = 1; i < colCount; ++i) {
auto series = new QLineSeries;
auto mapper = new QVXYModelMapper(series);
mapper->setModel(m_model);
mapper->setXColumn(0);
mapper->setYColumn(i);
mapper->setFirstRow(0);
mapper->setSeries(series);
auto areaSeries = new QAreaSeries(series, prevSeries);
series->setParent(areaSeries); // otherwise series isn't deleted by removeAllSeries!
areaSeries->setName(m_model->headerData(i, Qt::Horizontal).toString().toHtmlEscaped());
m_chart->addSeries(areaSeries);
areaSeries->attachAxis(m_xAxis);
areaSeries->attachAxis(m_yAxis);
prevSeries = series;
}
m_boxXAxis->hide();
m_xAxis->show();
}
// auto-scale axes
if (const auto rcount = m_model->rowCount()) {
const auto beginDt = m_model->index(0, 0).data(TimeAggregationModel::DateTimeRole).toDateTime();
const auto endDt = m_model->index(rcount - 1, 0).data(TimeAggregationModel::DateTimeRole).toDateTime();
m_xAxis->setRange(beginDt, endDt);
m_xAxis->setTickCount(std::min(rcount, 12));
const auto max = m_model->index(0, 0).data(TimeAggregationModel::MaximumValueRole).toInt();
m_yAxis->setRange(0, max);
m_yAxis->applyNiceNumbers();
}
}
/*
Copyright (C) 2016 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef USERFEEDBACK_ANALYZER_CHART_H
#define USERFEEDBACK_ANALYZER_CHART_H
#include <QObject>
#include <memory>
class QAbstractItemModel;
namespace QtCharts {
class QBarCategoryAxis;
class QChart;
class QDateTimeAxis;
class QValueAxis;
}
namespace UserFeedback {
namespace Analyzer {
class Chart : public QObject
{
Q_OBJECT
public:
explicit Chart(QObject *parent = nullptr);
~Chart();
QtCharts::QChart *chart() const;
void setModel(QAbstractItemModel* model);
private:
void modelReset();
std::unique_ptr<QtCharts::QChart> m_chart;
QAbstractItemModel *m_model = nullptr;
QtCharts::QDateTimeAxis *m_xAxis;
QtCharts::QBarCategoryAxis *m_boxXAxis;
QtCharts::QValueAxis *m_yAxis;
};
}
}
#endif // USERFEEDBACK_ANALYZER_CHART_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment