emsApplication/applications/emsConfigurer/formserialportsettingdialog...

156 lines
5.0 KiB
C++
Raw Normal View History

#include "formserialportsettingdialog.h"
2024-10-17 20:25:43 +08:00
#include "ui_formserialportsettingdialog.h"
#include <QListView>
#include <QStandardItemModel>
#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);
}