Commit 6b49f296 authored by Volker Krause's avatar Volker Krause
Browse files

Add an aggregator for the total sample chart too

This avoids having to special-case it all over the place.
parent edd772f4
......@@ -43,6 +43,7 @@ set(analyzer_srcs
analytics/chart.cpp
analytics/numericaggregator.cpp
analytics/ratiosetaggregator.cpp
analytics/totalaggregator.cpp
schemaeditor/aggregationeditwidget.cpp
schemaeditor/schemaeditor.cpp
......
......@@ -23,6 +23,7 @@
#include "chart.h"
#include "numericaggregator.h"
#include "ratiosetaggregator.h"
#include "totalaggregator.h"
#include <model/aggregateddatamodel.h>
#include <model/datamodel.h>
......@@ -129,15 +130,15 @@ void AnalyticsView::setProduct(const Product& product)
ui->chartType->clear();
m_aggregatedDataModel->clear();
qDeleteAll(m_aggregationModels);
m_aggregationModels.clear();
m_aggregatedDataModel->addSourceModel(m_timeAggregationModel);
ui->chartType->addItem(tr("Samples"));
qDeleteAll(m_aggregators);
m_aggregators.clear();
m_aggregatedDataModel->addSourceModel(m_timeAggregationModel);
auto totalsAggr = new TotalAggregator;
totalsAggr->setSourceModel(m_timeAggregationModel);
ui->chartType->addItem(tr("Samples"), QVariant::fromValue<Aggregator*>(totalsAggr));
foreach (const auto &aggr, product.aggregations()) {
auto aggregator = createAggregator(aggr);
if (!aggregator)
......@@ -154,8 +155,10 @@ void AnalyticsView::setProduct(const Product& product)
void AnalyticsView::chartSelected()
{
auto aggr = ui->chartType->currentData().value<Aggregator*>();
if (!aggr)
return;
const auto chartMode = aggr ? aggr->chartModes() : Aggregator::Timeline;
const auto chartMode = aggr->chartModes();
ui->actionSingularChart->setEnabled(chartMode & Aggregator::Singular);
ui->actionTimelineChart->setEnabled(chartMode & Aggregator::Timeline);
if (chartMode != (Aggregator::Timeline | Aggregator::Singular)) {
......@@ -163,10 +166,7 @@ void AnalyticsView::chartSelected()
ui->actionTimelineChart->setChecked(chartMode & Aggregator::Timeline);
}
if (!aggr)
m_chart->setModel(m_timeAggregationModel);
else
m_chart->setModel(aggr->timeAggregationModel());
m_chart->setModel(aggr->timeAggregationModel());
// ui->chartView->setChart(aggr->timelineChart());
}
......
......@@ -68,7 +68,6 @@ private:
RESTClient *m_client = nullptr;
DataModel *m_dataModel;
TimeAggregationModel *m_timeAggregationModel;
QVector<QAbstractItemModel*> m_aggregationModels;
AggregatedDataModel *m_aggregatedDataModel;
Chart *m_chart;
......
/*
Copyright (C) 2017 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 "totalaggregator.h"
using namespace UserFeedback::Analyzer;
TotalAggregator::TotalAggregator() = default;
TotalAggregator::~TotalAggregator() = default;
Aggregator::ChartModes TotalAggregator::chartModes() const
{
return Timeline;
}
QString TotalAggregator::displayName() const
{
return tr("Samples");
}
QAbstractItemModel* TotalAggregator::timeAggregationModel()
{
return sourceModel();
}
QtCharts::QChart* TotalAggregator::timelineChart()
{
// TODO
return nullptr;
}
/*
Copyright (C) 2017 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_TOTALAGGREGATOR_H
#define USERFEEDBACK_ANALYZER_TOTALAGGREGATOR_H
#include "aggregator.h"
#include <QCoreApplication>
namespace UserFeedback {
namespace Analyzer {
class TotalAggregator : public Aggregator
{
Q_DECLARE_TR_FUNCTIONS(UserFeedback::Analyzer::TotalAggregator)
public:
TotalAggregator();
~TotalAggregator();
ChartModes chartModes() const override;
QString displayName() const override;
QAbstractItemModel* timeAggregationModel() override;
QtCharts::QChart* timelineChart() override;
};
}}
#endif // USERFEEDBACK_ANALYZER_TOTALAGGREGATOR_H
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