-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeLocationStatsModel.cpp
224 lines (175 loc) · 4.38 KB
/
CodeLocationStatsModel.cpp
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// CodeLocationStatsModel.cpp
// Implements the CodeLocationStatsModel class representing the model for visualising CodeLocationStats
#include "Globals.h"
#include "CodeLocationStatsModel.h"
#include "Project.h"
#include "CodeLocation.h"
#include "CodeLocationStats.h"
#include "FormatNumber.h"
CodeLocationStatsModel::CodeLocationStatsModel(ProjectPtr a_Project):
Super(nullptr),
m_Project(a_Project)
{
rebuildModel();
connect(a_Project.get(), SIGNAL(addedSnapshot(SnapshotPtr)), this, SLOT(addedSnapshot(SnapshotPtr)));
}
void CodeLocationStatsModel::addedSnapshot(SnapshotPtr a_Snapshot)
{
Q_UNUSED(a_Snapshot);
rebuildModel();
}
void CodeLocationStatsModel::rebuildModel()
{
beginResetModel();
m_Stats = std::move(m_Project->getCodeLocationStats()->getAllStats());
endResetModel();
}
int CodeLocationStatsModel::rowCount(const QModelIndex & a_Parent) const
{
if (a_Parent.column() > 0)
{
return 0;
}
return static_cast<int>(m_Stats.size());
}
int CodeLocationStatsModel::columnCount(const QModelIndex &) const
{
return 8;
}
QVariant CodeLocationStatsModel::data(const QModelIndex & a_Index, int a_Role) const
{
if ((a_Index.row() < 0) || (static_cast<size_t>(a_Index.row()) > m_Stats.size()))
{
return QVariant();
}
const auto & stat = m_Stats[a_Index.row()];
switch (a_Role)
{
case Qt::TextAlignmentRole:
{
switch (a_Index.column())
{
case 0: return Qt::AlignRight;
case 1: return Qt::AlignLeft;
case 2: return Qt::AlignLeft;
case 3: return Qt::AlignRight;
case 4: return Qt::AlignRight;
case 5: return Qt::AlignRight;
case 6: return Qt::AlignRight;
case 7: return Qt::AlignRight;
}
break;
} // case Qt::TextAlignmentRole
case Qt::DisplayRole:
{
switch (a_Index.column())
{
case 0:
{
if (stat.m_CodeLocation == nullptr)
{
return QString::fromUtf8("<unknown>");
}
return QString::fromUtf8("0x%1").arg(
static_cast<qulonglong>(stat.m_CodeLocation->getAddress()),
16,
16,
static_cast<QChar>('0')
);
}
case 1:
{
if (stat.m_CodeLocation == nullptr)
{
return QString::fromUtf8("<unknown>");
}
return stat.m_CodeLocation->getFunctionName();
}
case 2:
{
if (stat.m_CodeLocation == nullptr)
{
return QString::fromUtf8("<unknown>");
}
return stat.m_CodeLocation->getFileName();
}
case 3:
{
if (stat.m_CodeLocation == nullptr)
{
return QString::fromUtf8("<unknown>");
}
return stat.m_CodeLocation->getFileLineNum();
}
case 4: return formatBigNumber(stat.m_MaxAllocationSize);
case 5: return formatBigNumber(stat.m_MinAllocationSize);
case 6: return formatBigNumber(stat.m_AvgAllocationSize);
case 7: return formatBigSignedNumber(stat.m_MaxAllocationSize - stat.m_MinAllocationSize);
}
break;
} // case Qt::DisplayRole
case SortRole:
{
switch (a_Index.column())
{
case 0:
{
if (stat.m_CodeLocation == nullptr)
{
return QString::fromUtf8("<unknown>");
}
return stat.m_CodeLocation->getAddress();
}
case 1:
{
if (stat.m_CodeLocation == nullptr)
{
return QString::fromUtf8("<unknown>");
}
return stat.m_CodeLocation->getFunctionName();
}
case 2:
{
if (stat.m_CodeLocation == nullptr)
{
return QString::fromUtf8("<unknown>");
}
return stat.m_CodeLocation->getFileName();
}
case 3:
{
if (stat.m_CodeLocation == nullptr)
{
return QString::fromUtf8("<unknown>");
}
return stat.m_CodeLocation->getFileLineNum();
}
case 4: return stat.m_MaxAllocationSize;
case 5: return stat.m_MinAllocationSize;
case 6: return stat.m_AvgAllocationSize;
case 7: return stat.m_MaxAllocationSize - stat.m_MinAllocationSize;
}
break;
}
}
return QVariant();
}
QVariant CodeLocationStatsModel::headerData(int a_Section, Qt::Orientation a_Orientation, int a_Role) const
{
if ((a_Orientation != Qt::Horizontal) || (a_Role != Qt::DisplayRole))
{
return Super::headerData(a_Section, a_Orientation, a_Role);
}
switch (a_Section)
{
case 0: return tr("Address");
case 1: return tr("Function");
case 2: return tr("File");
case 3: return tr("Line");
case 4: return tr("Max");
case 5: return tr("Min");
case 6: return tr("Avg");
case 7: return tr("Diff");
}
return QVariant();
}