This repository has been archived by the owner on Mar 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialogserialportsettings.cpp
81 lines (68 loc) · 2.89 KB
/
dialogserialportsettings.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
75
76
77
78
79
80
81
//
// SmartServer
// Copyright (C) 2021 АО "Нефтеавтоматика"
//
// Разработчик
// Ананьев А.А. <Ananev-AA@nefteavtomatika.ru>
//
#include "dialogserialportsettings.h"
#include "ui_dialogserialportsettings.h"
///
/// \brief DialogSerialPortSettings::DialogSerialPortSettings
/// \param settings
/// \param parent
///
DialogSerialPortSettings::DialogSerialPortSettings(SerialPortSettings& settings, QWidget *parent)
: QDialog(parent)
, ui(new Ui::DialogSerialPortSettings)
,_settings(settings)
{
ui->setupUi(this);
setWindowFlags(Qt::Dialog |
Qt::WindowTitleHint |
Qt::WindowCloseButtonHint);
ui->baudRateSelector->addItem("1200", QSerialPort::Baud1200);
ui->baudRateSelector->addItem("2400", QSerialPort::Baud2400);
ui->baudRateSelector->addItem("4800", QSerialPort::Baud4800);
ui->baudRateSelector->addItem("9600", QSerialPort::Baud9600);
ui->baudRateSelector->addItem("19200", QSerialPort::Baud19200);
ui->baudRateSelector->addItem("38400", QSerialPort::Baud38400);
ui->baudRateSelector->addItem("57600", QSerialPort::Baud57600);
ui->baudRateSelector->addItem("115200", QSerialPort::Baud115200);
ui->dataBitsSelector->addItem("5", QSerialPort::Data5);
ui->dataBitsSelector->addItem("6", QSerialPort::Data6);
ui->dataBitsSelector->addItem("7", QSerialPort::Data7);
ui->dataBitsSelector->addItem("8", QSerialPort::Data8);
ui->paritySelector->addItem("None", QSerialPort::NoParity);
ui->paritySelector->addItem("Even", QSerialPort::EvenParity);
ui->paritySelector->addItem("Odd", QSerialPort::OddParity);
ui->stopBitsSelector->addItem("1", QSerialPort::OneStop);
ui->stopBitsSelector->addItem("1.5", QSerialPort::OneAndHalfStop);
ui->stopBitsSelector->addItem("2", QSerialPort::TwoStop);
int idx = ui->baudRateSelector->findData(settings.baudRate());
ui->baudRateSelector->setCurrentIndex(idx);
idx = ui->dataBitsSelector->findData(settings.dataBits());
ui->dataBitsSelector->setCurrentIndex(idx);
idx = ui->paritySelector->findData(settings.parity());
ui->paritySelector->setCurrentIndex(idx);
idx = ui->stopBitsSelector->findData(settings.stopBits());
ui->stopBitsSelector->setCurrentIndex(idx);
}
///
/// \brief DialogSerialPortSettings::~DialogSerialPortSettings
///
DialogSerialPortSettings::~DialogSerialPortSettings()
{
delete ui;
}
///
/// \brief DialogSerialPortSettings::accept
///
void DialogSerialPortSettings::accept()
{
_settings.setBaudRate(ui->baudRateSelector->currentData().value<QSerialPort::BaudRate>());
_settings.setDataBits(ui->dataBitsSelector->currentData().value<QSerialPort::DataBits>());
_settings.setParity(ui->paritySelector->currentData().value<QSerialPort::Parity>());
_settings.setStopBits(ui->stopBitsSelector->currentData().value<QSerialPort::StopBits>());
QDialog::accept();
}