-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnapshotModel.cpp
118 lines (73 loc) · 2.8 KB
/
SnapshotModel.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
// SnapshotModel.cpp
// Implements the SnapshotModel class representing the model for displaying project's snapshots
#include "Globals.h"
#include "SnapshotModel.h"
#include <QStandardItem>
#include "Project.h"
#include "Snapshot.h"
#include "FormatNumber.h"
SnapshotModel::SnapshotModel(ProjectPtr a_Project):
Super(nullptr),
m_Project(a_Project),
m_IcoAllocations(":/icoAllocations.png")
{
// Insert the columns:
initColumns();
// Initialize the basic parameters:
setSortRole(SortRole);
// Insert current snapshots, and connect to project's signal to insert future added snapshots:
for (const auto & s: a_Project->getSnapshots())
{
addSnapshot(s);
}
connect(m_Project.get(), SIGNAL(addedSnapshot(SnapshotPtr)), this, SLOT(onProjectAddedSnapshot(SnapshotPtr)));
}
SnapshotPtr SnapshotModel::getItemSnapshot(const QModelIndex & a_Index) const
{
auto timestamp = data(a_Index, SnapshotTimestampRole);
return m_Project->getSnapshotAtTimestamp(timestamp.toULongLong());
}
Qt::ItemFlags SnapshotModel::flags(const QModelIndex & a_Index) const
{
// Drop the "editable" flag for all items:
auto res = Super::flags(a_Index);
return res & (~Qt::ItemIsEditable);
}
void SnapshotModel::onProjectAddedSnapshot(SnapshotPtr a_Snapshot)
{
addSnapshot(a_Snapshot);
}
void SnapshotModel::initColumns()
{
auto cTimestamp = new QStandardItem(tr("Timestamp"));
cTimestamp->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
setHorizontalHeaderItem(colTimestamp, cTimestamp);
auto cHeapSize = new QStandardItem(tr("Heap size (KiB)"));
cHeapSize->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
setHorizontalHeaderItem(colHeapSize, cHeapSize);
auto cHeapExtraSize = new QStandardItem(tr("Heap extra size (KiB)"));
cHeapExtraSize->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
setHorizontalHeaderItem(colHeapExtraSize, cHeapExtraSize);
}
void SnapshotModel::addSnapshot(SnapshotPtr a_Snapshot)
{
QList<QStandardItem *> row;
auto iTimestamp = new QStandardItem(formatBigNumber(a_Snapshot->getTimestamp()));
iTimestamp->setData(a_Snapshot->getTimestamp(), SnapshotTimestampRole);
iTimestamp->setData(a_Snapshot->getTimestamp(), SortRole);
iTimestamp->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
if (a_Snapshot->hasAllocations())
{
iTimestamp->setIcon(m_IcoAllocations);
}
row << iTimestamp;
auto iHeapSize = new QStandardItem(formatMemorySize(a_Snapshot->getHeapSize()));
iHeapSize->setData(a_Snapshot->getHeapSize(), SortRole);
iHeapSize->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
row << iHeapSize;
auto iHeapExtraSize = new QStandardItem(formatMemorySize(a_Snapshot->getHeapExtraSize()));
iHeapExtraSize->setData(a_Snapshot->getHeapExtraSize(), SortRole);
iHeapExtraSize->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
row << iHeapExtraSize;
appendRow(row);
}