-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathheapvizwindow.cpp
60 lines (48 loc) · 1.64 KB
/
heapvizwindow.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
#include "heapvizwindow.h"
#include "ui_heapvizwindow.h"
#include <QFileDialog>
#include <QInputDialog>
#include <QStatusBar>
#include <istream>
#include <fstream>
HeapVizWindow::HeapVizWindow(const std::string* inputfile,
QWidget *parent)
: QMainWindow(parent), ui(new Ui::HeapVizWindow) {
ui->setupUi(this);
statusBar()->showMessage("Initialized Main Window");
bool can_file_be_opened = false;
// Check if the input file can be opened.
QString input_filename = QString::fromStdString(*inputfile);
do {
std::ifstream ifs(input_filename.toUtf8().constData(), std::fstream::in);
if (ifs.fail()) {
input_filename = QFileDialog::getOpenFileName(this, tr("Open Heap Log JSON"), "",
tr("JSON Files (*.json)"));
} else {
can_file_be_opened = true;
}
} while (!can_file_be_opened);
emit setFileToDisplay(input_filename);
}
void HeapVizWindow::update() { printf("Update called"); }
HeapVizWindow::~HeapVizWindow() { delete ui; }
void HeapVizWindow::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Escape) {
close();
} else {
QWidget::keyPressEvent(e);
}
}
void HeapVizWindow::blockClicked(bool b, HeapBlock block) {
statusBar()->showMessage( b ? getBlockInformationAsString(block).c_str() : "No block");
}
void HeapVizWindow::showMessage(const std::string& message) {
QString message_to_show(message.c_str());
statusBar()->showMessage(message_to_show);
}
void HeapVizWindow::on_actionHighlight_blocks_with_size_triggered()
{
int size = QInputDialog::getInt(this, tr("Specify the size to highlight"),
tr("Block size"), 256);
emit setSizeToHighlight(size);
}