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

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 HISTOGRAMMODEL_H
0008 #define HISTOGRAMMODEL_H
0009 
0010 #include <QAbstractTableModel>
0011 
0012 #include <array>
0013 
0014 #include "treemodel.h"
0015 
0016 struct HistogramColumn
0017 {
0018     qint64 allocations;
0019     qint64 totalAllocated;
0020     Symbol symbol;
0021 };
0022 Q_DECLARE_TYPEINFO(HistogramColumn, Q_MOVABLE_TYPE);
0023 
0024 struct HistogramRow
0025 {
0026     HistogramRow()
0027     {
0028         columns.fill({0, 0, {}});
0029     }
0030     enum
0031     {
0032         NUM_COLUMNS = 10 + 1
0033     };
0034     QString sizeLabel;
0035     quint64 size = 0;
0036     std::array<HistogramColumn, NUM_COLUMNS> columns;
0037 };
0038 Q_DECLARE_TYPEINFO(HistogramRow, Q_MOVABLE_TYPE);
0039 Q_DECLARE_METATYPE(HistogramRow)
0040 
0041 struct HistogramData
0042 {
0043     QVector<HistogramRow> rows;
0044     std::shared_ptr<const ResultData> resultData;
0045 };
0046 Q_DECLARE_METATYPE(HistogramData)
0047 
0048 class HistogramModel : public QAbstractTableModel
0049 {
0050     Q_OBJECT
0051 public:
0052     explicit HistogramModel(QObject* parent = nullptr);
0053     ~HistogramModel() override;
0054 
0055     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0056     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
0057     int rowCount(const QModelIndex& parent = {}) const override;
0058     int columnCount(const QModelIndex& parent = {}) const override;
0059 
0060     void resetData(const HistogramData& data);
0061     void clearData();
0062 
0063 private:
0064     HistogramData m_data;
0065 };
0066 
0067 #endif // HISTOGRAMMODEL_H