File indexing completed on 2024-12-15 03:45:02
0001 /* 0002 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #ifndef KUSERFEEDBACK_CONSOLE_TIMEAGGREGATIONMODEL_H 0008 #define KUSERFEEDBACK_CONSOLE_TIMEAGGREGATIONMODEL_H 0009 0010 #include <QAbstractTableModel> 0011 #include <QDateTime> 0012 #include <QVector> 0013 0014 namespace KUserFeedback { 0015 namespace Console { 0016 0017 class Sample; 0018 0019 class TimeAggregationModel : public QAbstractTableModel 0020 { 0021 Q_OBJECT 0022 public: 0023 enum AggregationMode { 0024 AggregateYear, 0025 AggregateMonth, 0026 AggregateWeek, 0027 AggregateDay 0028 }; 0029 0030 enum Role { 0031 DateTimeRole = Qt::UserRole + 1, 0032 MaximumValueRole, 0033 TimeDisplayRole, 0034 DataDisplayRole, 0035 AccumulatedDisplayRole, 0036 SamplesRole, 0037 AllSamplesRole 0038 }; 0039 0040 explicit TimeAggregationModel(QObject *parent = nullptr); 0041 ~TimeAggregationModel() override; 0042 0043 void setSourceModel(QAbstractItemModel *model); 0044 0045 AggregationMode aggregationMode() const; 0046 void setAggregationMode(AggregationMode mode); 0047 0048 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0049 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0050 QVariant data(const QModelIndex &index, int role) const override; 0051 QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 0052 0053 private: 0054 void reload(); 0055 QDateTime aggregate(const QDateTime &dt) const; 0056 QString timeToString(const QDateTime &dt) const; 0057 0058 QAbstractItemModel *m_sourceModel = nullptr; 0059 struct Data { 0060 QDateTime time; 0061 QVector<Sample> samples; 0062 }; 0063 QVector<Data> m_data; 0064 int m_maxValue = 0; 0065 AggregationMode m_mode = AggregateYear; 0066 }; 0067 0068 } 0069 } 0070 0071 #endif // KUSERFEEDBACK_CONSOLE_TIMEAGGREGATIONMODEL_H