Commit 86d6d19f authored by Volker Krause's avatar Volker Krause
Browse files

Add filter proxy for singular charts

parent c4d0d33d
......@@ -21,6 +21,7 @@ set(analyzer_lib_srcs
model/productmodel.cpp
model/ratiosetaggregationmodel.cpp
model/schemamodel.cpp
model/singlerowfilterproxymodel.cpp
model/surveymodel.cpp
model/timeaggregationmodel.cpp
......
......@@ -17,6 +17,8 @@
#include "aggregator.h"
#include <model/singlerowfilterproxymodel.h>
using namespace UserFeedback::Analyzer;
Aggregator::Aggregator() = default;
......@@ -52,6 +54,21 @@ QAbstractItemModel* Aggregator::timeAggregationModel()
return nullptr;
}
QAbstractItemModel* Aggregator::singularAggregationModel()
{
if (!m_singularModel) {
m_singularModel.reset(new SingleRowFilterProxyModel);
m_singularModel->setSourceModel(timeAggregationModel());
}
return m_singularModel.get();
}
void Aggregator::setSingularTime(int row)
{
singularAggregationModel();
m_singularModel->setRow(row);
}
QtCharts::QChart *Aggregator::singlularChart()
{
return nullptr;
......
......@@ -20,6 +20,8 @@
#include <core/aggregation.h>
#include <memory>
class QAbstractItemModel;
namespace QtCharts {
......@@ -30,6 +32,7 @@ namespace UserFeedback {
namespace Analyzer {
class Aggregation;
class SingleRowFilterProxyModel;
class Aggregator
{
......@@ -55,12 +58,15 @@ public:
virtual ChartModes chartModes() const;
virtual QAbstractItemModel *timeAggregationModel();
QAbstractItemModel* singularAggregationModel();
void setSingularTime(int row);
virtual QtCharts::QChart *singlularChart();
virtual QtCharts::QChart *timelineChart();
private:
QAbstractItemModel *m_sourceModel = nullptr;
std::unique_ptr<SingleRowFilterProxyModel> m_singularModel;
Aggregation m_aggregation;
};
......
......@@ -105,6 +105,11 @@ AnalyticsView::AnalyticsView(QWidget* parent) :
settings.endGroup();
connect(ui->chartType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AnalyticsView::chartSelected);
connect(ui->timeSlider, &QSlider::valueChanged, this, [this](int value) {
auto aggr = ui->chartType->currentData().value<Aggregator*>();
if (aggr)
aggr->setSingularTime(value);
});
}
AnalyticsView::~AnalyticsView()
......
......@@ -22,7 +22,9 @@
#include <QtCharts/QAreaSeries>
#include <QtCharts/QChart>
#include <QtCharts/QDateTimeAxis>
#include <QtCharts/QHPieModelMapper>
#include <QtCharts/QLineSeries>
#include <QtCharts/QPieSeries>
#include <QtCharts/QValueAxis>
#include <QtCharts/QVXYModelMapper>
......@@ -112,7 +114,14 @@ QtCharts::QChart* CategoryAggregator::singlularChart()
m_singlularChart.reset(new QChart);
m_singlularChart->setTheme(qApp->palette().color(QPalette::Window).lightnessF() < 0.25 ? QChart::ChartThemeDark : QChart::ChartThemeLight);
// TODO
auto series = new QPieSeries(m_singlularChart.get());
auto mapper = new QHPieModelMapper(m_singlularChart.get());
mapper->setModel(singularAggregationModel());
mapper->setFirstColumn(1);
mapper->setValuesRow(0);
mapper->setLabelsRow(0); // FIXME
mapper->setSeries(series);
m_singlularChart->addSeries(series);
return m_singlularChart.get();
}
/*
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 "singlerowfilterproxymodel.h"
using namespace UserFeedback::Analyzer;
SingleRowFilterProxyModel::SingleRowFilterProxyModel(QObject* parent) :
QSortFilterProxyModel(parent)
{
}
SingleRowFilterProxyModel::~SingleRowFilterProxyModel() = default;
void SingleRowFilterProxyModel::setRow(int row)
{
m_row = row;
invalidateFilter();
}
bool SingleRowFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
if (source_parent.isValid())
return false;
return source_row == m_row;
}
/*
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_SINGLEROWFILTERPROXYMODEL_H
#define USERFEEDBACK_ANALYZER_SINGLEROWFILTERPROXYMODEL_H
#include <QSortFilterProxyModel>
namespace UserFeedback {
namespace Analyzer {
/** Keep a single row from the source model. */
class SingleRowFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit SingleRowFilterProxyModel(QObject *parent = nullptr);
~SingleRowFilterProxyModel();
void setRow(int row);
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override;
private:
int m_row = 0;
};
}}
#endif // USERFEEDBACK_ANALYZER_SINGLEROWFILTERPROXYMODEL_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