-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
155 lines (126 loc) · 4.8 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "settingsdialog.h"
#include <QFileDialog>
#include "settings.h"
#include <QFile>
#include <sstream>
RefsView::RefsView(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
tcpServer(this)
{
ui->setupUi(this);
ui->splitter->setSizes(QList<int>({1, 1}));
connect(ui->view, SIGNAL(statusChanged(QString)), ui->viewStatus, SLOT(setText(QString)));
connect(ui->treeWidget, SIGNAL(expanded(QModelIndex)), this, SLOT(resizeCols()));
connect(&stateHolder, &StateHolder::frameChanged, ui->view, &View::changeFrame);
connect(&stateHolder, &StateHolder::frameChanged, this, &RefsView::onframeChanged);
connect(&stateHolder, &StateHolder::fieldSizeChange, ui->view, &View::fieldSizeChange);
connect(&stateHolder, &StateHolder::field3d, ui->view, &View::field3d);
connect(&stateHolder, &StateHolder::staticObject, ui->view, &View::addStaticObject);
connect(&tcpServer, &TcpServer::newObj, &stateHolder, &StateHolder::process);
connect(&tcpServer, &TcpServer::onNewConnection, &stateHolder, &StateHolder::onNewConnection);
connect(ui->scrollTick, &QScrollBar::valueChanged, &stateHolder, &StateHolder::tickChanged);
connect(ui->treeWidget, &QTreeWidget::itemCollapsed, this, &RefsView::itemCollapsed);
connect(ui->treeWidget, &QTreeWidget::itemExpanded, this, &RefsView::itemExpanded);
connect(ui->view, &View::keyEvent, &tcpServer, &TcpServer::sendKeyEvent);
connect(this, &RefsView::onFileOpen, &stateHolder, &StateHolder::onFileOpen);
tcpServer.start();
}
RefsView::~RefsView()
{
delete ui;
}
QString getItemName(QTreeWidgetItem *item) {
QString t = item->text(0);
QTreeWidgetItem *parent = dynamic_cast<QTreeWidgetItem *>(item->parent());
if (parent)
return parent->text(0) + "->" + t;
return t;
}
void addSObjToTree(const SObj &obj, QTreeWidgetItem *parentItem)
{
for (const auto &p : obj) {
QTreeWidgetItem *pitem = new QTreeWidgetItem(parentItem);
pitem->setText(0, QString::fromUtf8(p.first.data(), p.first.size()));
std::string val = toString(p.second);
pitem->setText(1, QString::fromUtf8(val.data(), val.size()));
}
}
void RefsView::addObjToTree(const Obj &obj)
{
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget);
item->setText(0, QString::fromUtf8(obj.type.data(), obj.type.size()));
QString parentName = getItemName(item);
if (expandedItems.count(parentName))
item->setExpanded(true);
addSObjToTree(obj.props, item);
for (auto &&o : obj.subObjs) {
QTreeWidgetItem *oitem = new QTreeWidgetItem(item);
oitem->setText(0, QString::fromUtf8(o.first.data(), o.first.size()));
QString itemName = getItemName(oitem);
if (expandedItems.count(itemName))
oitem->setExpanded(true);
addSObjToTree(o.second, oitem);
}
if (obj.type == "log")
{
std::string str = getStr("text", obj.props);
ui->logText->appendPlainText(QString::fromUtf8(str.c_str()));
}
}
void RefsView::onframeChanged(std::shared_ptr<Frame> renderFrame, int totalCount)
{
ui->treeWidget->clear();
ui->logText->clear();
if (!renderFrame)
{
ui->scrollTick->setRange(0, 0);
ui->statusBar->showMessage("");
}
else
{
std::lock_guard<std::recursive_mutex> guard(renderFrame->mutex);
bool oldState = ui->scrollTick->blockSignals(true);
ui->scrollTick->setRange(0, totalCount - 1);
ui->scrollTick->setValue(renderFrame->tick);
ui->scrollTick->blockSignals(oldState);
for (const Obj &obj : renderFrame->objs)
{
addObjToTree(obj);
}
resizeCols();
ui->statusBar->showMessage(QString("Tick: ") + QString::number(renderFrame->tick + 1) + "/" + QString::number(totalCount));
}
}
void RefsView::resizeCols()
{
ui->treeWidget->resizeColumnToContents(0);
}
void RefsView::on_actionOptions_triggered()
{
SettingsDialog settingsDialog(this);
connect(&settingsDialog, &SettingsDialog::settingsChanged, &tcpServer, &TcpServer::settingsChanged);
connect(&settingsDialog, &SettingsDialog::settingsChanged, ui->view, &View::settingsChanged);
settingsDialog.setModal(true);
settingsDialog.exec();
}
void RefsView::itemExpanded(QTreeWidgetItem *item)
{
QString name = getItemName(item);
expandedItems.insert(name);
}
void RefsView::itemCollapsed(QTreeWidgetItem *item)
{
QString name = getItemName(item);
expandedItems.erase(name);
}
void RefsView::on_actionOpen_triggered()
{
Settings settings;
QString fileName = QFileDialog::getOpenFileName(this, "Open file", settings.outputDir, "Dump files (*.vbin)", nullptr, QFileDialog::DontResolveSymlinks);
if (fileName.isEmpty())
return;
emit onFileOpen(fileName);
}