File indexing completed on 2024-04-28 17:02:22
0001 /* 0002 This file is part of Massif Visualizer 0003 0004 Copyright 2010 Milian Wolff <mail@milianw.de> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Lesser General Public 0008 License as published by the Free Software Foundation; either 0009 version 2.1 of the License, or (at your option) version 3, or any 0010 later version accepted by the membership of KDE e.V. (or its 0011 successor approved by the membership of KDE e.V.), which shall 0012 act as a proxy defined in Section 6 of version 3 of the license. 0013 0014 This library is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 Lesser General Public License for more details. 0018 0019 You should have received a copy of the GNU Lesser General Public 0020 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #ifndef MASSIF_DATATREEMODEL_H 0024 #define MASSIF_DATATREEMODEL_H 0025 0026 #include <QtCore/QAbstractItemModel> 0027 0028 #include "modelitem.h" 0029 0030 namespace Massif { 0031 0032 class FileData; 0033 class TreeLeafItem; 0034 class SnapshotItem; 0035 0036 /** 0037 * A model that gives a tree representation of the full Massif data. Useful for e.g. ListViews. 0038 */ 0039 class DataTreeModel : public QAbstractItemModel 0040 { 0041 public: 0042 DataTreeModel(QObject* parent = 0); 0043 virtual ~DataTreeModel(); 0044 0045 /** 0046 * That the source data for this model. 0047 */ 0048 void setSource(const FileData* data); 0049 0050 /** 0051 * @return Item for given index. At maximum one of the pointers in the pair will be valid. 0052 */ 0053 ModelItem itemForIndex(const QModelIndex& idx) const; 0054 0055 /** 0056 * @return Index for given item. At maximum one of the pointers should be valid in the input pair. 0057 */ 0058 QModelIndex indexForItem(const ModelItem& item) const; 0059 0060 /** 0061 * @return Index for given snapshot, or invalid if it's not a detailed snapshot. 0062 */ 0063 QModelIndex indexForSnapshot(const SnapshotItem* snapshot) const; 0064 0065 /** 0066 * @return Index for given TreeLeafItem, or invalid if it's not covered by this model. 0067 */ 0068 QModelIndex indexForTreeLeaf(const TreeLeafItem* node) const; 0069 0070 enum CustomRoles { 0071 RawLabelRole = Qt::UserRole + 1, 0072 TreeItemRole, 0073 ModelItemRole, 0074 }; 0075 0076 virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; 0077 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; 0078 virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; 0079 virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; 0080 virtual QModelIndex parent(const QModelIndex& child) const; 0081 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 0082 0083 const SnapshotItem* snapshotForTreeLeaf(const TreeLeafItem* node) const; 0084 private: 0085 const FileData* m_data; 0086 0087 void mapNodeToRow(const TreeLeafItem* node, const int row); 0088 QHash<const TreeLeafItem*, int> m_nodeToRow; 0089 QHash<const TreeLeafItem*, const SnapshotItem*> m_heapRootToSnapshot; 0090 }; 0091 0092 } 0093 0094 #endif // MASSIF_DATATREEMODEL_H