202 lines
6.5 KiB
C++
202 lines
6.5 KiB
C++
#include "formserialportsettingdialog.h"
|
|
#include "ui_formserialportsettingdialog.h"
|
|
|
|
#include <QListView>
|
|
#include <QStandardItemModel>
|
|
#include <QPushButton>
|
|
#include <QMessageBox>
|
|
|
|
#include "globalparameters.h"
|
|
|
|
FormSerialPortSettingDialog::FormSerialPortSettingDialog(QWidget *parent)
|
|
: QDialog(parent)
|
|
, ui(new Ui::FormSerialPortSettingDialog)
|
|
{
|
|
ui->setupUi(this);
|
|
InitializeUi();
|
|
}
|
|
|
|
FormSerialPortSettingDialog::~FormSerialPortSettingDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void FormSerialPortSettingDialog::InitializeUi()
|
|
{
|
|
ui->delay_timeout->setText("1000");
|
|
ui->loop_time->setText("5000");
|
|
ui->slave_id->setText("1");
|
|
|
|
//设置奇偶校验
|
|
ui->cb_parity->setView(new QListView(this));
|
|
|
|
QStandardItemModel* model_parity = new QStandardItemModel(this);
|
|
|
|
vecParityItemData vparity;
|
|
vparity.push_back(std::make_pair(EMS_PARITY_NONE,tr("None")));
|
|
vparity.push_back(std::make_pair(EMS_PARITY_ODD,tr("Odd")));
|
|
vparity.push_back(std::make_pair(EMS_PARITY_EVEN,tr("Even")));
|
|
|
|
for (auto it = vparity.begin(); it != vparity.end(); it++)
|
|
{
|
|
int id = it->first;
|
|
QString name = it->second;
|
|
|
|
QStandardItem* item = new QStandardItem(name);
|
|
//QVariant var = QVariant::fromValue(data);
|
|
item->setData(id);
|
|
model_parity->appendRow(item);
|
|
}
|
|
|
|
ui->cb_parity->setModel(model_parity);
|
|
|
|
//设置数据位
|
|
ui->cb_data->setView(new QListView(this));
|
|
QStandardItemModel* model_databits = new QStandardItemModel(this);
|
|
vecDataBitsItemData vdatabits;
|
|
vdatabits.push_back(std::make_pair(EMS_DATA_8_BITS,tr("8 Data bits")));
|
|
vdatabits.push_back(std::make_pair(EMS_DATA_7_BITS,tr("7 Data bits")));
|
|
|
|
for (auto it = vdatabits.begin(); it != vdatabits.end(); it++)
|
|
{
|
|
int id = it->first;
|
|
QString name = it->second;
|
|
|
|
QStandardItem* item = new QStandardItem(name);
|
|
item->setData(id);
|
|
model_databits->appendRow(item);
|
|
}
|
|
|
|
ui->cb_data->setModel(model_databits);
|
|
|
|
//设置数据位
|
|
ui->cb_stop->setView(new QListView(this));
|
|
QStandardItemModel* model_stopbits = new QStandardItemModel(this);
|
|
vecDataBitsItemData vstopbits;
|
|
vstopbits.push_back(std::make_pair(EMS_1_STOP_BITS,tr("1 Stop bit")));
|
|
vstopbits.push_back(std::make_pair(EMS_2_STOP_BITS,tr("2 Stop bits")));
|
|
|
|
for (auto it = vstopbits.begin(); it != vstopbits.end(); it++)
|
|
{
|
|
int id = it->first;
|
|
QString name = it->second;
|
|
|
|
QStandardItem* item = new QStandardItem(name);
|
|
item->setData(id);
|
|
model_stopbits->appendRow(item);
|
|
}
|
|
|
|
ui->cb_stop->setModel(model_stopbits);
|
|
|
|
//设置串口模式
|
|
ui->cb_mode->setView(new QListView(this));
|
|
QStandardItemModel* model_mode = new QStandardItemModel(this);
|
|
vecDataBitsItemData vportmode;
|
|
vportmode.push_back(std::make_pair(EMS_RTU_MODE,tr("RTU")));
|
|
vportmode.push_back(std::make_pair(EMS_ASCII_MODE,tr("ASCII")));
|
|
|
|
for (auto it = vportmode.begin(); it != vportmode.end(); it++)
|
|
{
|
|
int id = it->first;
|
|
QString name = it->second;
|
|
|
|
QStandardItem* item = new QStandardItem(name);
|
|
item->setData(id);
|
|
model_mode->appendRow(item);
|
|
}
|
|
|
|
ui->cb_mode->setModel(model_mode);
|
|
|
|
//设置串口模式
|
|
ui->cb_baund->setView(new QListView(this));
|
|
QStandardItemModel* model_baund = new QStandardItemModel(this);
|
|
vecBaundItemData vbaund;
|
|
vbaund.push_back(std::make_pair(EMS_BAUND_2400,tr("2400")));
|
|
vbaund.push_back(std::make_pair(EMS_BAUND_2400,tr("4800")));
|
|
vbaund.push_back(std::make_pair(EMS_BAUND_2400,tr("9600")));
|
|
vbaund.push_back(std::make_pair(EMS_BAUND_2400,tr("19200")));
|
|
vbaund.push_back(std::make_pair(EMS_BAUND_2400,tr("38400")));
|
|
vbaund.push_back(std::make_pair(EMS_BAUND_2400,tr("57600")));
|
|
vbaund.push_back(std::make_pair(EMS_BAUND_2400,tr("115200")));
|
|
vbaund.push_back(std::make_pair(EMS_BAUND_2400,tr("128000")));
|
|
vbaund.push_back(std::make_pair(EMS_BAUND_2400,tr("153600")));
|
|
vbaund.push_back(std::make_pair(EMS_BAUND_2400,tr("230400")));
|
|
vbaund.push_back(std::make_pair(EMS_BAUND_2400,tr("460800")));
|
|
vbaund.push_back(std::make_pair(EMS_BAUND_2400,tr("921600")));
|
|
|
|
for (auto it = vbaund.begin(); it != vbaund.end(); it++)
|
|
{
|
|
int id = it->first;
|
|
QString name = it->second;
|
|
|
|
QStandardItem* item = new QStandardItem(name);
|
|
item->setData(id);
|
|
model_baund->appendRow(item);
|
|
}
|
|
|
|
ui->cb_baund->setModel(model_baund);
|
|
ui->cb_baund->setCurrentIndex(2);
|
|
|
|
//设置串口类型
|
|
ui->cb_type->setView(new QListView(this));
|
|
QStandardItemModel* model_type = new QStandardItemModel(this);
|
|
vecPortTypeItemData vporttype;
|
|
vporttype.push_back(std::make_pair(EMS_SERIALPORT_TYPE,tr("Serial Port")));
|
|
|
|
for (auto it = vporttype.begin(); it != vporttype.end(); it++)
|
|
{
|
|
int id = it->first;
|
|
QString name = it->second;
|
|
|
|
QStandardItem* item = new QStandardItem(name);
|
|
item->setData(id);
|
|
model_type->appendRow(item);
|
|
}
|
|
|
|
ui->cb_type->setModel(model_type);
|
|
|
|
ui->toolButton->setFixedSize(40, 30);
|
|
|
|
ui->buttonBox->clear();
|
|
QPushButton *okButton = ui->buttonBox->addButton(QDialogButtonBox::Ok);
|
|
QPushButton *cancelButton = ui->buttonBox->addButton(QDialogButtonBox::Cancel);
|
|
okButton->setFixedSize(100, 30);
|
|
cancelButton->setFixedSize(100, 30);
|
|
|
|
//设置串口号
|
|
ui->cb_serialport->setView(new QListView(this));
|
|
|
|
QStandardItemModel* model_serialport = new QStandardItemModel(this);
|
|
|
|
for (int i=0; i < AppData::getInstance()->SerialPortCount ; i++)
|
|
{
|
|
QString name = AppData::getInstance()->SerialPortPrefix + QString("%1").arg(i);
|
|
|
|
QStandardItem* item = new QStandardItem(name);
|
|
//QVariant var = QVariant::fromValue(data);
|
|
item->setData(name);
|
|
model_serialport->appendRow(item);
|
|
}
|
|
|
|
ui->cb_serialport->setModel(model_serialport);
|
|
|
|
connect(okButton, &QPushButton::clicked, this, &FormSerialPortSettingDialog::onOkClicked);
|
|
connect(cancelButton, &QPushButton::clicked, this, &FormSerialPortSettingDialog::onCancelClicked);
|
|
connect(ui->toolButton, &QPushButton::clicked, this, &FormSerialPortSettingDialog::onToolButtonClicked);
|
|
}
|
|
|
|
void FormSerialPortSettingDialog::onOkClicked()
|
|
{
|
|
QMessageBox::information(this, "onOkClicked", "Refresh");
|
|
}
|
|
|
|
void FormSerialPortSettingDialog::onCancelClicked()
|
|
{
|
|
QMessageBox::information(this, "onCancelClicked", "Refresh");
|
|
}
|
|
|
|
void FormSerialPortSettingDialog::onToolButtonClicked()
|
|
{
|
|
QMessageBox::information(this, "onToolButtonClicked", "Refresh");
|
|
}
|