Rabbit Remote Control 0.1.0-de
Loading...
Searching...
No Matches
DlgSettingsSerialPort.cpp
1#include <QLoggingCategory>
2#include <QSerialPortInfo>
3#include "ParameterPlugin.h"
4#include "DlgSettingsSerialPort.h"
5#include "ui_DlgSettingsSerialPort.h"
6
7static Q_LOGGING_CATEGORY(log, "SerialPort.Dlg")
9 : QDialog(parent)
10 , ui(new Ui::CDlgSettingsSerialPort)
11 , m_pPara(pPara)
12{
13 ui->setupUi(this);
14
15 m_pFrmParaAppearnce =
16 new CParameterTerminalUI(this);
17 if(m_pFrmParaAppearnce) {
18 m_pFrmParaAppearnce->SetParameter(&m_pPara->m_Terminal);
19 ui->tabWidget->addTab(m_pFrmParaAppearnce,
20 m_pFrmParaAppearnce->windowTitle());
21 }
22
23 ui->leName->setText(m_pPara->GetName());
24 foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
25 {
26 /*
27 qDebug(log)
28 << "Port:" << info.portName() << " "
29 << "Location:" << info.systemLocation() << " "
30 << "Description:" << info.description() << " "
31 << "Manufacturer:" << info.manufacturer() << " "
32 << "Serial number:" << info.serialNumber() << " "
33 << "Vendor Identifier:"
34 << (info.hasVendorIdentifier()
35 ? QByteArray::number(info.vendorIdentifier(), 16)
36 : QByteArray()) << " "
37 << "Product Identifier:"
38 << (info.hasProductIdentifier()
39 ? QByteArray::number(info.productIdentifier(), 16)
40 : QByteArray()); //*/
41 QString szPort;
42 szPort = info.portName();
43 //szPort = info.systemLocation();
44 // if(!info.description().isEmpty())
45 // {
46 // szPort += "(" + info.description() + ")";
47 // }
48 ui->cbSerialPort->addItem(szPort);
49 }
50 int nSerialPort = m_pPara->GetSerialPort();
51 QSerialPortInfo info;
52 if(-1 < nSerialPort && nSerialPort < ui->cbSerialPort->count()) {
53 ui->cbSerialPort->setCurrentIndex(nSerialPort);
54 }
55 if(-1 != ui->cbSerialPort->currentIndex())
56 info = QSerialPortInfo::availablePorts().at(ui->cbSerialPort->currentIndex());
57 QSerialPort serialPort(info);
58
59 if(!m_pPara->GetSerialPortName().isEmpty()
60 && ui->cbSerialPort->currentText() != m_pPara->GetSerialPortName()) {
61 ui->cbSerialPort->setCurrentText(m_pPara->GetSerialPortName());
62 serialPort.setPortName(m_pPara->GetSerialPortName());
63 }
64
65 foreach(const qint32 &baudRate, QSerialPortInfo::standardBaudRates())
66 {
67 ui->cbBaudRate->addItem(QString::number(baudRate));
68 }
69 QString szBaudRate;
70 if(-1 == nSerialPort)
71 szBaudRate = QString::number(serialPort.baudRate());
72 else
73 szBaudRate = QString::number(m_pPara->GetBaudRate());
74 ui->cbBaudRate->setCurrentText(szBaudRate);
75
76 ui->cbDataBits->addItem("8", QSerialPort::DataBits::Data8);
77 ui->cbDataBits->addItem("7", QSerialPort::DataBits::Data7);
78 ui->cbDataBits->addItem("6", QSerialPort::DataBits::Data6);
79 ui->cbDataBits->addItem("5", QSerialPort::DataBits::Data5);
80 QSerialPort::DataBits dataBits;
81 if(-1 == nSerialPort)
82 dataBits = serialPort.dataBits();
83 else
84 dataBits = m_pPara->GetDataBits();
85 int nIndex = ui->cbDataBits->findData(dataBits);
86 ui->cbDataBits->setCurrentIndex(nIndex);
87
88 ui->cbParity->addItem(tr("None"), QSerialPort::Parity::NoParity);
89 ui->cbParity->addItem(tr("Even"), QSerialPort::Parity::EvenParity);
90 ui->cbParity->addItem(tr("Odd"), QSerialPort::Parity::OddParity);
91 ui->cbParity->addItem(tr("Space"), QSerialPort::Parity::SpaceParity);
92 ui->cbParity->addItem(tr("Mark"), QSerialPort::Parity::MarkParity);
93 QSerialPort::Parity parity;
94 if(-1 == nSerialPort)
95 parity = serialPort.parity();
96 else
97 parity = m_pPara->GetParity();
98 nIndex = ui->cbParity->findData(parity);
99 ui->cbParity->setCurrentIndex(nIndex);
100
101 ui->cbStopBits->addItem("1", QSerialPort::StopBits::OneStop);
102 ui->cbStopBits->addItem("1.5", QSerialPort::StopBits::OneAndHalfStop);
103 ui->cbStopBits->addItem("2", QSerialPort::StopBits::TwoStop);
104 QSerialPort::StopBits stopBits;
105 if(-1 == nSerialPort)
106 stopBits = serialPort.stopBits();
107 else
108 stopBits = m_pPara->GetStopBits();
109 nIndex = ui->cbStopBits->findData(stopBits);
110 ui->cbStopBits->setCurrentIndex(nIndex);
111
112 ui->cbFlowControl->addItem(tr("None"), QSerialPort::FlowControl::NoFlowControl);
113 ui->cbFlowControl->addItem(tr("HardWare"), QSerialPort::FlowControl::HardwareControl);
114 ui->cbFlowControl->addItem(tr("SoftWare"), QSerialPort::FlowControl::SoftwareControl);
115 QSerialPort::FlowControl flowControl;
116 if(-1 == nSerialPort)
117 flowControl = serialPort.flowControl();
118 else
119 flowControl = m_pPara->GetFlowControl();
120 nIndex = ui->cbFlowControl->findData(flowControl);
121 ui->cbFlowControl->setCurrentIndex(nIndex);
122}
123
124CDlgSettingsSerialPort::~CDlgSettingsSerialPort()
125{
126 delete ui;
127}
128
129void CDlgSettingsSerialPort::accept()
130{
131 if(m_pFrmParaAppearnce)
132 m_pFrmParaAppearnce->Accept();
133
134 m_pPara->SetName(ui->leName->text());
135 m_pPara->SetSerialPort(ui->cbSerialPort->currentIndex());
136 m_pPara->SetSerialPortName(ui->cbSerialPort->currentText());
137 m_pPara->SetBaudRate(ui->cbBaudRate->currentText().toInt());
138 m_pPara->SetParity((QSerialPort::Parity)ui->cbParity->currentData().toInt());
139 m_pPara->SetDataBits((QSerialPort::DataBits)ui->cbDataBits->currentData().toInt());
140 m_pPara->SetStopBits((QSerialPort::StopBits)ui->cbStopBits->currentData().toInt());
141 m_pPara->SetFlowControl((QSerialPort::FlowControl)ui->cbFlowControl->currentData().toInt());
142 QDialog::accept();
143}
virtual int Accept() override
Accept parameters.