-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmainwindow.cpp
97 lines (84 loc) · 2.65 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
// SPDX-License-Identifier: GPL-3.0
#include <QMessageBox>
#include <QWindow>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "trace.h"
#include "keyeventfilter.h"
#include "sessionitem.h"
MainWindow * MainWindow::instance = nullptr;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
instance = this;
ui->setupUi(this);
KeyEventFilter::install(this);
traceLeft = new TraceView(this);
traceRight = new TraceView(this);
diffview = new DiffView(this);
ui->traceSplitter->addWidget(traceLeft);
ui->traceSplitter->addWidget(traceRight);
ui->diffSplitter->addWidget(diffview);
traceLeft->show();
traceRight->show();
connect(traceLeft, &TraceView::packetChanged, this, &MainWindow::onPacketChange);
connect(traceRight, &TraceView::packetChanged, this, &MainWindow::onPacketChange);
connect(diffview, &DiffView::filterSubmitted, this, [this](QString f) {
Q_UNUSED(f);
onPacketChange(nullptr);
});
reloadSessionMenu();
}
void MainWindow::moveSelection(int dir)
{
traceLeft->moveSelection(dir);
traceRight->moveSelection(dir);
}
MainWindow::~MainWindow()
{
sesList.save();
delete ui;
}
void MainWindow::onSessionItemClick(bool checked)
{
Q_UNUSED(checked);
SessionItem* it = static_cast<SessionItem*>(QObject::sender());
traceLeft->asyncOpen(it->ses_.fileA, it->ses_.filterA);
traceRight->asyncOpen(it->ses_.fileB, it->ses_.filterB);
diffview->setFilter(it->ses_.diffFilter);
}
void MainWindow::reloadSessionMenu()
{
ui->menuPrevious_sessions->clear();
for (Session& s : sesList.ses_) {
auto it = new SessionItem(ui->menuPrevious_sessions, &s);
ui->menuPrevious_sessions->addAction(it);
connect(it, &SessionItem::triggered, this, &MainWindow::onSessionItemClick);
}
}
void MainWindow::updateSession()
{
if (traceLeft->getTrace() && traceRight->getTrace()) {
sesList.add(traceLeft->getTrace()->getFilename(), traceLeft->getTrace()->getFilter(),
traceRight->getTrace()->getFilename(), traceRight->getTrace()->getFilter(),
diffview->getFilter());
reloadSessionMenu();
}
}
void MainWindow::onPacketChange(TraceView* tv)
{
Q_UNUSED(tv);
Trace::Node *left, *right;
left = traceLeft->getLastNode();
right = traceRight->getLastNode();
diff.clear();
if (left && right)
computeDiff(diff, left, right, diffview->getFilter());
diffview->updateDiff();
updateSession();
}
void MainWindow::on_actionAbout_triggered()
{
QMessageBox::about(this, "About WireDiff", "WireDiff is free software licensed under the GPLv3.");
}