-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
91 lines (79 loc) · 2.79 KB
/
Copy pathmainwindow.cpp
File metadata and controls
91 lines (79 loc) · 2.79 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "console.h"
#include "serialendpoint.h"
#include "canendpoint.h"
#include <QLabel>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
m_ui(new Ui::MainWindow),
m_status(new QLabel),
m_console(new Console)
{
m_endpoint[0] = new SerialEndpoint(this);
m_endpoint[1] = new CanEndpoint(this);
m_ui->setupUi(this);
m_console->setEnabled(true);
setCentralWidget(m_console);
m_ui->actionConnect->setEnabled(true);
m_ui->actionDisconnect->setEnabled(false);
m_ui->actionQuit->setEnabled(true);
m_ui->actionConfigure->setEnabled(true);
m_ui->statusBar->addWidget(m_status);
initActionsConnections();
connect(m_endpoint[0], &Endpoint::statusMessage, this, &MainWindow::showStatusMessage);
connect(m_endpoint[0], &Endpoint::getData, m_endpoint[1], &Endpoint::putData);
connect(m_endpoint[0], &Endpoint::getData,
[=]( const QByteArray &data ) { m_console->putData(data, QBrush(Qt::blue)); }
);
connect(m_endpoint[1], &Endpoint::statusMessage, this, &MainWindow::showStatusMessage);
connect(m_endpoint[1], &Endpoint::getData, m_endpoint[0], &Endpoint::putData);
connect(m_endpoint[1], &Endpoint::getData,
[=]( const QByteArray &data ) { m_console->putData(data, QBrush(Qt::red)); }
);
}
MainWindow::~MainWindow()
{
delete m_endpoint[0];
delete m_endpoint[1];
delete m_ui;
}
void MainWindow::connectEndpoint()
{
if (m_endpoint[0]->open() && m_endpoint[1]->open())
{
m_console->setEnabled(true);
m_ui->actionConnect->setEnabled(false);
m_ui->actionDisconnect->setEnabled(true);
m_ui->actionConfigure->setEnabled(false);
}
else
{
m_endpoint[0]->close();
m_endpoint[1]->close();
}
}
void MainWindow::disconnectEndpoint()
{
m_endpoint[0]->close();
m_endpoint[1]->close();
m_console->setEnabled(false);
m_ui->actionConnect->setEnabled(true);
m_ui->actionDisconnect->setEnabled(false);
m_ui->actionConfigure->setEnabled(true);
showStatusMessage(tr("Disconnected"));
}
void MainWindow::initActionsConnections()
{
connect(m_ui->actionConnect, &QAction::triggered, this, &MainWindow::connectEndpoint);
connect(m_ui->actionDisconnect, &QAction::triggered, this, &MainWindow::disconnectEndpoint);
connect(m_ui->actionQuit, &QAction::triggered, this, &MainWindow::close);
connect(m_ui->actionConfigure, &QAction::triggered, m_endpoint[0], &Endpoint::showDialog);
connect(m_ui->actionConfigure, &QAction::triggered, m_endpoint[1], &Endpoint::showDialog);
connect(m_ui->actionClear, &QAction::triggered, m_console, &Console::clear);
}
void MainWindow::showStatusMessage(const QString &message)
{
m_status->setText(message);
}