File indexing completed on 2024-12-15 03:45:01

0001 /*
0002     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #ifndef KUSERFEEDBACK_CONSOLE_NUMERICAGGREGATIONMODEL_H
0008 #define KUSERFEEDBACK_CONSOLE_NUMERICAGGREGATIONMODEL_H
0009 
0010 #include <core/aggregationelement.h>
0011 
0012 #include <QAbstractTableModel>
0013 
0014 namespace KUserFeedback {
0015 namespace Console {
0016 
0017 class Sample;
0018 
0019 class NumericAggregationModel : public QAbstractTableModel
0020 {
0021     Q_OBJECT
0022 public:
0023     explicit NumericAggregationModel(QObject *parent = nullptr);
0024     ~NumericAggregationModel() override;
0025 
0026     void setSourceModel(QAbstractItemModel *model);
0027     void setAggregation(const AggregationElement &aggr);
0028 
0029     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0030     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0031     QVariant data(const QModelIndex &index, int role) const override;
0032     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0033 
0034 private:
0035     void recompute();
0036     QVector<double> sampleValues(const Sample &s) const;
0037 
0038     QAbstractItemModel *m_sourceModel = nullptr;
0039     AggregationElement m_aggr;
0040     struct Data {
0041         double lowerExtreme = 0.0;
0042         double lowerQuartile = 0.0;
0043         double median = 0.0;
0044         double upperQuartile = 0.0;
0045         double upperExtreme = 0.0;
0046     };
0047     QVector<Data> m_data;
0048 
0049     double m_maxValue = 0.0;
0050 };
0051 
0052 }
0053 }
0054 
0055 #endif // KUSERFEEDBACK_CONSOLE_NUMERICAGGREGATIONMODEL_H