-
Notifications
You must be signed in to change notification settings - Fork 0
/
commdialog.cpp
74 lines (63 loc) · 2.61 KB
/
commdialog.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
#include "commdialog.h"
#include <QComboBox>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QSerialPortInfo>
CommDialog::CommDialog(QWidget *parent) :
QDialog(parent),
m_serialPortLabel(new QLabel(tr("Serial port:"))),
m_serialPortComboBox(new QComboBox),
m_trafficLabel(new QLabel(tr("No traffic."))),
m_statusLabel(new QLabel(tr("Status: Not running."))),
m_runButton(new QPushButton(tr("Start")))
{
const auto infos = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &info : infos)
m_serialPortComboBox->addItem(info.portName());
auto mainLayout = new QGridLayout;
mainLayout->addWidget(m_serialPortLabel, 0, 0);
mainLayout->addWidget(m_serialPortComboBox, 0, 1);
mainLayout->addWidget(m_runButton, 0, 2, 2, 1);
mainLayout->addWidget(m_trafficLabel, 3, 0, 1, 4);
mainLayout->addWidget(m_statusLabel, 4, 0, 1, 5);
setLayout(mainLayout);
setWindowTitle(tr("Comms Receiver"));
m_serialPortComboBox->setFocus();
// connect(m_runButton, &QPushButton::clicked, this, &CommDialog::startReceiver);
// connect(&m_thread, &ReceiverThread::request, this,&CommDialog::showRequest);
// connect(&m_thread, &ReceiverThread::error, this, &CommDialog::processError);
// connect(&m_thread, &ReceiverThread::timeout, this, &CommDialog::processTimeout);
connect(m_serialPortComboBox, &QComboBox::currentIndexChanged, this, &CommDialog::activateRunButton);
}
// void CommDialog::startReceiver()
// {
// m_runButton->setEnabled(false);
// m_statusLabel->setText(tr("Status: Running, connected to port %1.")
// .arg(m_serialPortComboBox->currentText()));
// // m_thread.startReceiver(m_serialPortComboBox->currentText());
// }
// void CommDialog::showRequest(const QString &s)
// {
// m_trafficLabel->setText(tr("Traffic, transaction #%1:"
// "\n\r-request: %2"
// "\n\r-response: %3")
// .arg(++m_transactionCount)
// .arg(s)
// .arg(m_responseLineEdit->text()));
// }
// void CommDialog::processError(const QString &s)
// {
// activateRunButton();
// m_statusLabel->setText(tr("Status: Not running, %1.").arg(s));
// m_trafficLabel->setText(tr("No traffic."));
// }
// void CommDialog::processTimeout(const QString &s)
// {
// m_statusLabel->setText(tr("Status: Running, %1.").arg(s));
// m_trafficLabel->setText(tr("No traffic."));
// }
void CommDialog::activateRunButton()
{
m_runButton->setEnabled(true);
}