-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBusView.cpp
More file actions
74 lines (61 loc) · 1.67 KB
/
BusView.cpp
File metadata and controls
74 lines (61 loc) · 1.67 KB
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
#include "BusView.h"
#include "ui_BusView.h"
#include <QHBoxLayout>
BusView::BusView(QWidget *parent) :
QWidget(parent),
ui(new Ui::BusView)
{
ui->setupUi(this);
QVBoxLayout* outerLayout = new QVBoxLayout();
setLayout(outerLayout);
outerLayout->addWidget(ui->candFramesLabel);
outerLayout->addWidget(ui->scrollArea);
QHBoxLayout* buttonLayout = new QHBoxLayout();
outerLayout->addLayout(buttonLayout);
buttonLayout->addStretch(85);
buttonLayout->addWidget(ui->transmitButton, 15);
}
void BusView::setBus(CanBus *newBus)
{
bus = newBus;
}
void clearLayout2(QLayout *layout) {
if (layout == NULL)
return;
QLayoutItem *item;
while((item = layout->takeAt(0))) {
if (item->layout()) {
clearLayout2(item->layout());
delete item->layout();
}
if (item->widget()) {
delete item->widget();
}
delete item;
}
}
void BusView::fetchCandidateFrames()
{
if (ui->scrollAreaWidgetContents->layout() == nullptr)
ui->scrollAreaWidgetContents->setLayout(new QVBoxLayout());
std::vector<CommunicationFrame*> frames = bus->getCandidateFrames();
QVBoxLayout* contentLayout = (QVBoxLayout*) ui->scrollAreaWidgetContents->layout();
clearLayout2(contentLayout);
for (auto frame : frames)
contentLayout->addWidget(new FrameWidget(frame));
}
void BusView::addListener(MessageHistoryView *newListener)
{
listener = newListener;
}
BusView::~BusView()
{
delete ui;
}
void BusView::on_transmitButton_clicked()
{
bus->transmitFrame();
fetchCandidateFrames();
if (listener != nullptr)
listener->fetchReceivedFrames();
}