-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHistoryModel.h
139 lines (85 loc) · 3.49 KB
/
HistoryModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// HistoryModel.h
// Declares the HistoryModel class representing a Qt model for displaying the project history in a view / graph
#ifndef HISTORYMODEL_H
#define HISTORYMODEL_H
#include <memory>
#include <QAbstractTableModel>
#include <QSortFilterProxyModel>
#include <QColor>
#include "AllocationPath.h"
#include "AllocationStats.h"
// fwd:
class Project;
typedef std::shared_ptr<Project> ProjectPtr;
class Allocation;
/** Basic model that provides the raw data for the sorted model. */
class HistoryModel:
public QAbstractTableModel
{
typedef QAbstractTableModel Super;
Q_OBJECT
public:
/* Column indices. */
enum
{
colFunctionName = 0,
colMinAllocationSize = 1,
colMaxAllocationSize = 2,
colAvgAllocationSize = 3,
colDiffAllocationSize = 4,
colHierarchy = 5,
colPosition = 6,
colMaxPlusOne,
colMax = colMaxPlusOne - 1,
};
// fwd:
struct GraphedAllocationPath;
typedef std::shared_ptr<GraphedAllocationPath> GraphedAllocationPathPtr;
/** Represents a single allocation path that has been selected for graphing. */
struct GraphedAllocationPath
{
/** The allocation path represented by this instance. */
AllocationPath m_AllocationPath;
/** The stats for this path. */
AllocationStats m_Stats;
/** Color of this path used for the graph. */
QColor m_Color;
/** Creates a new instance of this class and fills it with the specified data. */
GraphedAllocationPath(
const AllocationPath & a_AllocationPath,
const AllocationStats & a_Stats
);
};
explicit HistoryModel(ProjectPtr a_Project);
/** Returns all the allocation paths that are to be graphed. */
const std::vector<GraphedAllocationPathPtr> & getGraphedAllocationPaths() const { return m_GraphedAllocationPaths; }
/** Returns true iff the path at the specified index can expand (has at least two children somewhere down its hierarchy). */
bool canItemExpand(const QModelIndex & a_Index) const;
/** Returns true iff the path at the specified index can collapse (has a grandparent). */
bool canItemCollapse(const QModelIndex & a_Index) const;
/** Returns true if the index is valid, in regard to row / column dimensions of the model. */
bool isValidIndex(const QModelIndex & a_Index) const;
signals:
/** Emitted after the model has expanded or collapsed a path, or a path's position changed. */
void modelDataChanged();
public slots:
/** Resets the entire model.
Called after the underlying project changes so much that incremental changes are no longer easy. */
void resetModel();
/** Called by the treeview when the item is expanded and thus its children should be graphed. */
void expandItem(const QModelIndex & a_Item);
/** Called by the treeview when the item is collapsed and thus its children should not be graphed anymore. */
void collapseItem(const QModelIndex & a_Item);
void expandItem(int a_Index);
protected:
/** The project for which the history is being modelled. */
ProjectPtr m_Project;
/** The allocation paths that are to be graphed, together with their color and stats. */
std::vector<GraphedAllocationPathPtr> m_GraphedAllocationPaths;
// QAbstractItemModel overrides:
virtual int rowCount(const QModelIndex & a_Parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex & a_Parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex & a_Index, int a_Role) const override;
virtual QVariant headerData(int a_Section, Qt::Orientation a_Orientation, int a_Role = Qt::DisplayRole) const override;
};
#endif // HISTORYMODEL_H