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_DETAILEDCOSTMODEL_H
0024 #define MASSIF_DETAILEDCOSTMODEL_H
0025 
0026 #include <QtCore/QAbstractTableModel>
0027 #include <QtCore/QVector>
0028 
0029 #include "modelitem.h"
0030 
0031 namespace Massif {
0032 
0033 class FileData;
0034 class SnapshotItem;
0035 class TreeLeafItem;
0036 
0037 /**
0038  * A model that gives a tabular access on the costs in a massif output file.
0039  */
0040 class DetailedCostModel : public QAbstractTableModel
0041 {
0042 public:
0043     DetailedCostModel(QObject* parent = 0);
0044     virtual ~DetailedCostModel();
0045 
0046     /**
0047      * That the source data for this model.
0048      */
0049     void setSource(const FileData* data);
0050 
0051     virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
0052     virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
0053     virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
0054     virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
0055 
0056     /**
0057      * Sets the maximum number of datasets in this model to @p count.
0058      */
0059     void setMaximumDatasetCount(int count);
0060 
0061     int maximumDatasetCount() const;
0062 
0063     typedef QMap<QModelIndex, const TreeLeafItem*> Peaks;
0064     /**
0065      * @return List of peaks with their heap tree leaf items.
0066      */
0067     Peaks peaks() const;
0068 
0069     /**
0070      * @return ModelItem for given index. At maximum one of the pointers in the pair will be valid.
0071      */
0072     ModelItem itemForIndex(const QModelIndex& idx) const;
0073 
0074     /**
0075      * @return Index for given item. Only one of the pointers in the pair should be valid.
0076      */
0077     QModelIndex indexForItem(const ModelItem& item) const;
0078 
0079     /**
0080      * @return Index for given snapshot, or invalid if it's not a detailed snapshot.
0081      */
0082     QModelIndex indexForSnapshot(const SnapshotItem* snapshot) const;
0083 
0084     /**
0085      * @return Index for given TreeLeafItem, or invalid if it's not covered by this model.
0086      */
0087     QModelIndex indexForTreeLeaf(const TreeLeafItem* node) const;
0088 
0089     /**
0090      * Select @p index, which changes the graphical representation of its data.
0091      */
0092     void setSelection(const QModelIndex& index);
0093 
0094     /**
0095      * Hide function @p func.
0096      */
0097     void hideFunction(const TreeLeafItem* node);
0098 
0099     /**
0100      * Hide all functions except for @p func.
0101      */
0102     void hideOtherFunctions(const TreeLeafItem* node);
0103 
0104 private:
0105     const FileData* m_data;
0106     // columns => label
0107     QVector<QByteArray> m_columns;
0108     // only to sort snapshots by number
0109     QVector<const SnapshotItem*> m_rows;
0110     typedef QHash<const SnapshotItem*, QVector<const TreeLeafItem*> > Nodes;
0111     // snapshot item => cost intensive nodes
0112     Nodes m_nodes;
0113     // peaks: Label => TreeLeafItem,Snapshot
0114     QHash<QByteArray, ModelItem> m_peaks;
0115     // selected item
0116     QModelIndex m_selection;
0117     int m_maxDatasetCount;
0118 };
0119 
0120 }
0121 
0122 #endif // MASSIF_DETAILEDCOSTMODEL_H