-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDlgSnapshotDiffs.cpp
106 lines (70 loc) · 2.13 KB
/
DlgSnapshotDiffs.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
// DlgSnapshotDiffs.cpp
// Implements the DlgSnapshotDiffs class representing the dialog for displaying multiple diffs between snapshots
#include "Globals.h"
#include "DlgSnapshotDiffs.h"
#include "ui_DlgSnapshotDiffs.h"
#include "SnapshotDiff.h"
#include "Snapshot.h"
#include "Allocation.h"
#include "SnapshotDiffModel.h"
static const int TW_DATA_ROLE_DIFFPTR = 1037;
DlgSnapshotDiffs::DlgSnapshotDiffs(QWidget * a_Parent):
Super(a_Parent),
m_UI(new Ui::DlgSnapshotDiffs)
{
m_UI->setupUi(this);
// Connect the signals:
connect(m_UI->twDiffs, SIGNAL(itemSelectionChanged()), this, SLOT(onCurrentDiffChanged()));
// Set up the sorting proxy model:
m_SortingModel = std::make_shared<QSortFilterProxyModel>();
m_SortingModel->setSortRole(SnapshotDiffModel::dataRoleSort);
m_UI->tvDiff->setModel(m_SortingModel.get());
}
void DlgSnapshotDiffs::show(SnapshotDiffPtrs && a_Diffs)
{
// Store the diffs internally:
std::swap(a_Diffs, m_Diffs);
for (auto d: m_Diffs)
{
m_Models[d.get()] = nullptr;
}
// Create an item for each diff:
auto root = m_UI->twDiffs->invisibleRootItem();
for (auto d: m_Diffs)
{
QStringList columns;
columns << tr("%1").arg(d->getFirstSnapshot()->getTimestamp());
columns << tr("%1").arg(d->getSecondSnapshot()->getTimestamp());
auto item = new QTreeWidgetItem(columns);
item->setData(0, TW_DATA_ROLE_DIFFPTR, reinterpret_cast<quint64>(d.get()));
root->addChild(item);
}
Super::showMaximized();
}
void DlgSnapshotDiffs::onCurrentDiffChanged()
{
// Get the SnapshotDiffPtr representing the diff:
auto diff = reinterpret_cast<SnapshotDiff *>(m_UI->twDiffs->currentItem()->data(0, TW_DATA_ROLE_DIFFPTR).toULongLong());
SnapshotDiffPtr diffPtr;
for (auto d: m_Diffs)
{
if (d.get() == diff)
{
diffPtr = d;
break;
}
}
if (diffPtr == nullptr)
{
assert(!"Cannot find SnapshotDiffPtr for current item");
return;
}
// Get the model, create it if it doesn't exist yet
auto model = m_Models[diffPtr.get()];
if (model == nullptr)
{
model = std::make_shared<SnapshotDiffModel>(diffPtr);
m_Models[diffPtr.get()] = model;
}
m_SortingModel->setSourceModel(model.get());
}