-
Notifications
You must be signed in to change notification settings - Fork 2
/
interfaceconfigdialog.cpp
56 lines (50 loc) · 1.4 KB
/
interfaceconfigdialog.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
// ******************************************************
// * copyright (C) 2017 by Reinhardt Behm/[email protected]
// * All Rights reserved
// * created 10/23/2017 by behm
// ******************************************************
#include "interfaceconfigdialog.h"
#include "ui_interfaceconfigdialog.h"
#include "prop.h"
InterfaceConfigDialog::InterfaceConfigDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::InterfaceConfigDialog)
{
ui->setupUi(this);
foreach (const QSerialPortInfo &pi, QSerialPortInfo::availablePorts())
{
QString pn = pi.portName();
if (! pi.description().isEmpty())
{
pn += ": " +pi.description();
}
if (pi.hasVendorIdentifier())
{
pn += QString(" 0x%1:%2").arg(pi.vendorIdentifier(),4, 16,QChar('0')).arg(pi.productIdentifier(),4, 16,QChar('0'));
}
ui->portCombo->addItem(pn, pi.portName());
}
foreach (uint baud, QSerialPortInfo::standardBaudRates())
{
ui->baudCombo->addItem(QString::number(baud));
}
}
InterfaceConfigDialog::~InterfaceConfigDialog()
{
delete ui;
}
void InterfaceConfigDialog::setProp(Prop *prop)
{
m_prop = prop;
int idx = ui->portCombo->findData(prop->portName());
ui->portCombo->setCurrentIndex(idx);
ui->baudCombo->setCurrentText(QString::number(prop->baud()));
}
void InterfaceConfigDialog::accept()
{
if (m_prop)
{
m_prop->setDevice(ui->portCombo->currentData().toString(), ui->baudCombo->currentText().toUInt());
}
close();
}