File indexing completed on 2024-05-19 05:44:22

0001 /*
0002     SPDX-FileCopyrightText: 2015-2017 Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef CHARTMODEL_H
0008 #define CHARTMODEL_H
0009 
0010 #include <array>
0011 
0012 #include <QAbstractTableModel>
0013 #include <QVector>
0014 
0015 #include "resultdata.h"
0016 
0017 #include <memory>
0018 
0019 struct ChartRows
0020 {
0021     ChartRows()
0022     {
0023         cost.fill(0);
0024     }
0025     enum
0026     {
0027         MAX_NUM_COST = 21
0028     };
0029     // time in ms
0030     qint64 timeStamp = 0;
0031     std::array<qint64, MAX_NUM_COST> cost;
0032 };
0033 Q_DECLARE_TYPEINFO(ChartRows, Q_MOVABLE_TYPE);
0034 
0035 struct ChartData
0036 {
0037     QVector<ChartRows> rows;
0038     QHash<int, Symbol> labels;
0039     std::shared_ptr<const ResultData> resultData;
0040 };
0041 Q_DECLARE_METATYPE(ChartData)
0042 Q_DECLARE_TYPEINFO(ChartData, Q_MOVABLE_TYPE);
0043 
0044 class ChartModel : public QAbstractTableModel
0045 {
0046     Q_OBJECT
0047 public:
0048     enum Type
0049     {
0050         Consumed,
0051         Allocations,
0052         Temporary,
0053     };
0054     explicit ChartModel(Type type, QObject* parent = nullptr);
0055     virtual ~ChartModel();
0056 
0057     Type type() const;
0058     QString typeString() const;
0059 
0060     QVariant headerData(int section, Qt::Orientation orientation = Qt::Horizontal,
0061                         int role = Qt::DisplayRole) const override;
0062     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
0063     int rowCount(const QModelIndex& parent = QModelIndex()) const override;
0064     int columnCount(const QModelIndex& parent = QModelIndex()) const override;
0065 
0066     int maximumDatasetCount() const
0067     {
0068         return m_maxDatasetCount;
0069     }
0070     void setMaximumDatasetCount(int count);
0071 
0072     qint64 totalCostAt(qint64 timeStamp) const;
0073 
0074 public slots:
0075     void resetData(const ChartData& data);
0076     void clearData();
0077 
0078 private:
0079     void resetColors();
0080 
0081     ChartData m_data;
0082     Type m_type;
0083     // we cache the pens and brushes as constructing them requires allocations
0084     // otherwise
0085     QVector<QPen> m_columnDataSetPens;
0086     QVector<QBrush> m_columnDataSetBrushes;
0087     int m_maxDatasetCount;
0088 };
0089 
0090 #endif // CHARTMODEL_H