Commit 77fd51c4 authored by Volker Krause's avatar Volker Krause
Browse files

Pass the entire aggregation settings to the category model

Necessary to eventually support hierarchical category aggregation here.
parent 01a03ff8
......@@ -44,17 +44,20 @@ private slots:
{
CategoryAggregationModel model;
ModelTest modelTest(&model);
model.setAggregation(AggregationElement());
AggregationElement aggr;
model.setAggregation(Aggregation());
AggregationElement aggrElem;
{
SchemaEntry entry;
entry.setName(QLatin1String("applicationVersion"));
aggr.setSchemaEntry(entry);
aggrElem.setSchemaEntry(entry);
SchemaEntryElement elem;
elem.setName(QLatin1String("value"));
aggr.setSchemaEntryElement(elem);
aggr.setType(AggregationElement::Value);
aggrElem.setSchemaEntryElement(elem);
aggrElem.setType(AggregationElement::Value);
}
Aggregation aggr;
aggr.setType(Aggregation::Category);
aggr.setElements({aggrElem});
model.setAggregation(aggr);
TimeAggregationModel timeModel;
......@@ -79,16 +82,19 @@ private slots:
{
CategoryAggregationModel model;
ModelTest modelTest(&model);
AggregationElement aggr;
AggregationElement aggrElem;
{
SchemaEntry entry;
entry.setName(QLatin1String("applicationVersion"));
aggr.setSchemaEntry(entry);
aggrElem.setSchemaEntry(entry);
SchemaEntryElement elem;
elem.setName(QLatin1String("value"));
aggr.setSchemaEntryElement(elem);
aggr.setType(AggregationElement::Value);
aggrElem.setSchemaEntryElement(elem);
aggrElem.setType(AggregationElement::Value);
}
Aggregation aggr;
aggr.setType(Aggregation::Category);
aggr.setElements({aggrElem});
model.setAggregation(aggr);
TimeAggregationModel timeModel;
......
......@@ -53,8 +53,7 @@ QAbstractItemModel* CategoryAggregator::timeAggregationModel()
if (!m_model && !aggregation().elements().isEmpty()) {
m_model.reset(new CategoryAggregationModel);
m_model->setSourceModel(sourceModel());
const auto e = aggregation().elements().at(0);
m_model->setAggregation(e);
m_model->setAggregation(aggregation());
QObject::connect(m_model.get(), &QAbstractItemModel::modelReset, [this]() {
updateSingularChart();
updateTimelineChart();
......
......@@ -36,6 +36,11 @@ static const struct {
Aggregation::Aggregation() = default;
Aggregation::~Aggregation() = default;
bool Aggregation::isValid() const
{
return m_type != None && m_elements.size() > 0;
}
Aggregation::Type Aggregation::type() const
{
return m_type;
......
......@@ -45,6 +45,8 @@ public:
Aggregation();
~Aggregation();
bool isValid() const;
Type type() const;
void setType(Type t);
......
......@@ -45,7 +45,7 @@ void CategoryAggregationModel::setSourceModel(QAbstractItemModel* model)
recompute();
}
void CategoryAggregationModel::setAggregation(const AggregationElement& aggr)
void CategoryAggregationModel::setAggregation(const Aggregation& aggr)
{
m_aggr = aggr;
recompute();
......@@ -129,7 +129,7 @@ void CategoryAggregationModel::recompute()
QSet<QString> categories;
const auto allSamples = m_sourceModel->index(0, 0).data(TimeAggregationModel::AllSamplesRole).value<QVector<Sample>>();
foreach (const auto &s, allSamples)
categories.insert(sampleValue(s).toString());
categories.insert(sampleValue(s, 0).toString());
m_categories.reserve(categories.size());
foreach (const auto &cat, categories)
m_categories.push_back(cat);
......@@ -142,7 +142,7 @@ void CategoryAggregationModel::recompute()
for (int row = 0; row < rowCount; ++row) {
const auto samples = m_sourceModel->index(row, 0).data(TimeAggregationModel::SamplesRole).value<QVector<Sample>>();
foreach (const auto &sample, samples) {
const auto catIt = std::lower_bound(m_categories.constBegin(), m_categories.constEnd(), sampleValue(sample).toString());
const auto catIt = std::lower_bound(m_categories.constBegin(), m_categories.constEnd(), sampleValue(sample, 0).toString());
Q_ASSERT(catIt != m_categories.constEnd());
const auto idx = colCount * row + std::distance(m_categories.constBegin(), catIt);
m_data[idx]++;
......@@ -158,13 +158,14 @@ void CategoryAggregationModel::recompute()
endResetModel();
}
QVariant CategoryAggregationModel::sampleValue(const Sample& s) const
QVariant CategoryAggregationModel::sampleValue(const Sample& s, int depth) const
{
switch (m_aggr.type()) {
const auto elem = m_aggr.elements().at(depth);
switch (elem.type()) {
case AggregationElement::Value:
return s.value(m_aggr.schemaEntry().name() + QLatin1String(".") + m_aggr.schemaEntryElement().name());
return s.value(elem.schemaEntry().name() + QLatin1String(".") + elem.schemaEntryElement().name());
case AggregationElement::Size:
const auto l = s.value(m_aggr.schemaEntry().name());
const auto l = s.value(elem.schemaEntry().name());
return l.value<QVariantList>().size();
break;
}
......
......@@ -18,7 +18,7 @@
#ifndef USERFEEDBACK_CONSOLE_CATEGORYAGGREGATIONMODEL_H
#define USERFEEDBACK_CONSOLE_CATEGORYAGGREGATIONMODEL_H
#include <core/aggregationelement.h>
#include <core/aggregation.h>
#include <QAbstractTableModel>
#include <QVector>
......@@ -37,7 +37,7 @@ public:
~CategoryAggregationModel();
void setSourceModel(QAbstractItemModel *model);
void setAggregation(const AggregationElement &aggr);
void setAggregation(const Aggregation &aggr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
......@@ -46,10 +46,10 @@ public:
private:
void recompute();
QVariant sampleValue(const Sample &s) const;
QVariant sampleValue(const Sample &s, int depth) const;
QAbstractItemModel *m_sourceModel = nullptr;
AggregationElement m_aggr;
Aggregation m_aggr;
QVector<QString> m_categories;
int *m_data = nullptr;
int m_maxValue;
......
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