File indexing completed on 2024-05-19 05:44:26
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 TREEMODEL_H 0008 #define TREEMODEL_H 0009 0010 #include <QAbstractItemModel> 0011 #include <QVector> 0012 0013 #include "../allocationdata.h" 0014 #include "locationdata.h" 0015 #include "summarydata.h" 0016 0017 #include <memory> 0018 0019 class ResultData; 0020 0021 struct RowData 0022 { 0023 AllocationData cost; 0024 Symbol symbol; 0025 const RowData* parent; 0026 QVector<RowData> children; 0027 bool operator<(const Symbol& rhs) const 0028 { 0029 return symbol < rhs; 0030 } 0031 }; 0032 Q_DECLARE_TYPEINFO(RowData, Q_MOVABLE_TYPE); 0033 0034 struct TreeData 0035 { 0036 QVector<RowData> rows; 0037 std::shared_ptr<const ResultData> resultData; 0038 }; 0039 Q_DECLARE_METATYPE(TreeData) 0040 0041 class TreeModel : public QAbstractItemModel 0042 { 0043 Q_OBJECT 0044 public: 0045 TreeModel(QObject* parent); 0046 virtual ~TreeModel(); 0047 0048 enum Columns 0049 { 0050 LocationColumn, 0051 PeakColumn, 0052 LeakedColumn, 0053 AllocationsColumn, 0054 TemporaryColumn, 0055 NUM_COLUMNS 0056 }; 0057 0058 enum Roles 0059 { 0060 SortRole = Qt::UserRole, 0061 MaxCostRole, 0062 SymbolRole, 0063 ResultDataRole, 0064 }; 0065 0066 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0067 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; 0068 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; 0069 QModelIndex parent(const QModelIndex& child) const override; 0070 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 0071 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 0072 0073 public slots: 0074 void resetData(const TreeData& data); 0075 void setSummary(const SummaryData& data); 0076 void clearData(); 0077 0078 private: 0079 /// @return the row resembled by @p index 0080 const RowData* toRow(const QModelIndex& index) const; 0081 /// @return the row number of @p row in its parent 0082 int rowOf(const RowData* row) const; 0083 0084 TreeData m_data; 0085 RowData m_maxCost; 0086 }; 0087 0088 #endif // TREEMODEL_H