-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageHistoryView.cpp
More file actions
59 lines (50 loc) · 1.42 KB
/
MessageHistoryView.cpp
File metadata and controls
59 lines (50 loc) · 1.42 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
#include "MessageHistoryView.h"
#include "ui_MessageHistoryView.h"
#include <QVBoxLayout>
MessageHistoryView::MessageHistoryView(QWidget *parent) :
QWidget(parent),
ui(new Ui::MessageHistoryView)
{
ui->setupUi(this);
QVBoxLayout* outerLayout = new QVBoxLayout();
setLayout(outerLayout);
outerLayout->addWidget(ui->historyLabel);
outerLayout->addWidget(ui->scrollArea);
}
void MessageHistoryView::setDevice(NetworkDevice *newDevice)
{
device = newDevice;
fetchReceivedFrames();
}
void clearLayout1(QLayout *layout) {
if (layout == NULL)
return;
QLayoutItem *item;
while((item = layout->takeAt(0))) {
if (item->layout()) {
clearLayout1(item->layout());
delete item->layout();
}
if (item->widget()) {
delete item->widget();
}
delete item;
}
}
void MessageHistoryView::fetchReceivedFrames()
{
if (ui->scrollAreaWidgetContents->layout() == nullptr)
ui->scrollAreaWidgetContents->setLayout(new QVBoxLayout());
QVBoxLayout* contentLayout = (QVBoxLayout*) ui->scrollAreaWidgetContents->layout();
clearLayout1(contentLayout);
if (device != nullptr)
{
std::vector<CommunicationFrame*> frames = device->getReceivedFrames();
for (auto frame : frames)
contentLayout->addWidget(new FrameWidget(frame));
}
}
MessageHistoryView::~MessageHistoryView()
{
delete ui;
}