Commit 4458f614 authored by Volker Krause's avatar Volker Krause
Browse files

Add extra rows proxy model, so we get labels in the singular pie charts

parent 86d6d19f
......@@ -17,6 +17,7 @@ set(analyzer_lib_srcs
model/aggregationelementmodel.cpp
model/categoryaggregationmodel.cpp
model/datamodel.cpp
model/extrarowsproxymodel.cpp
model/numericaggregationmodel.cpp
model/productmodel.cpp
model/ratiosetaggregationmodel.cpp
......
......@@ -18,6 +18,7 @@
#include "categoryaggregator.h"
#include <model/categoryaggregationmodel.h>
#include <model/extrarowsproxymodel.h>
#include <QtCharts/QAreaSeries>
#include <QtCharts/QChart>
......@@ -116,10 +117,12 @@ QtCharts::QChart* CategoryAggregator::singlularChart()
auto series = new QPieSeries(m_singlularChart.get());
auto mapper = new QHPieModelMapper(m_singlularChart.get());
mapper->setModel(singularAggregationModel());
auto modelWithLabels = new ExtraRowsProxyModel(mapper);
modelWithLabels->setSourceModel(singularAggregationModel());
mapper->setModel(modelWithLabels);
mapper->setFirstColumn(1);
mapper->setValuesRow(0);
mapper->setLabelsRow(0); // FIXME
mapper->setLabelsRow(1);
mapper->setSeries(series);
m_singlularChart->addSeries(series);
......
/*
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 "extrarowsproxymodel.h"
using namespace UserFeedback::Analyzer;
ExtraRowsProxyModel::ExtraRowsProxyModel(QObject* parent) :
QIdentityProxyModel(parent)
{
}
ExtraRowsProxyModel::~ExtraRowsProxyModel() = default;
int ExtraRowsProxyModel::rowCount(const QModelIndex& parent) const
{
if (!sourceModel())
return 0;
if (parent.isValid())
return sourceModel()->rowCount(mapToSource(parent));
return sourceModel()->rowCount() + m_extraRowCount;
}
QVariant ExtraRowsProxyModel::data(const QModelIndex& index, int role) const
{
if (!sourceModel())
return {};
if (!index.isValid() || index.parent().isValid() || index.row() < sourceModel()->rowCount())
return QIdentityProxyModel::data(index, role);
return extraData(index.row() - sourceModel()->rowCount(), index.column(), role);
}
QModelIndex ExtraRowsProxyModel::index(int row, int column, const QModelIndex& parent) const
{
if (!sourceModel())
return {};
if (parent.isValid() || row < sourceModel()->rowCount())
return QIdentityProxyModel::index(row, column, parent);
if (row >= rowCount())
return {};
return createIndex(row, column);
}
QModelIndex ExtraRowsProxyModel::parent(const QModelIndex& child) const
{
if (!sourceModel())
return {};
if (child.internalId() == 0 && child.row() >= sourceModel()->rowCount())
return {};
return QIdentityProxyModel::parent(child);
}
QVariant ExtraRowsProxyModel::extraData(int row, int column, int role) const
{
// TODO split into sperate model!
Q_UNUSED(row);
if (role == Qt::DisplayRole)
return headerData(column, Qt::Horizontal, Qt::DisplayRole);
return {};
}
/*
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_EXTRAROWSPROXYMODEL_H
#define USERFEEDBACK_ANALYZER_EXTRAROWSPROXYMODEL_H
#include <QIdentityProxyModel>
namespace UserFeedback {
namespace Analyzer {
class ExtraRowsProxyModel : public QIdentityProxyModel
{
Q_OBJECT
public:
explicit ExtraRowsProxyModel(QObject *parent = nullptr);
~ExtraRowsProxyModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex & index, int role) const override;
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
QModelIndex parent(const QModelIndex & child) const override;
protected:
virtual QVariant extraData(int row, int column, int role) const;
private:
int m_extraRowCount = 1;
};
}}
#endif // USERFEEDBACK_ANALYZER_EXTRAROWSPROXYMODEL_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