/****************************************************************************
**
** Copyright (C) 2012 Denis Shienkov <[email protected]>
** Copyright (C) 2012 Laszlo Papp <[email protected]>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtSerialPort module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//-------------------------------------------------
//
// Project created by QQ1977800361 2015-04-27T21:34:39
//
//-----------------------------------------------
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include <QtSerialPort/QSerialPortInfo>
#include <QIntValidator>
#include <QLineEdit>
QT_USE_NAMESPACE
static const char blankString[] = QT_TRANSLATE_NOOP("SettingsDialog", "N/A");
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SettingsDialog)
{
ui->setupUi(this);
//QIntValidator类提供了一个确保一个字符串包含一个在一定有效范围内的整数的验证器。
intValidator = new QIntValidator(0, 4000000, this); //只允许 edit 输入整数0到 4000000
ui->baudRateBox->setInsertPolicy(QComboBox::NoInsert);
connect(ui->applyButton, SIGNAL(clicked()),
this, SLOT(apply()));
connect(ui->serialPortInfoListBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(showPortInfo(int)));
connect(ui->baudRateBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(checkCustomBaudRatePolicy(int)));
connect(ui->serialPortInfoListBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(checkCustomDevicePathPolicy(int)));
fillPortsParameters();
fillPortsInfo();
updateSettings();
}
SettingsDialog::~SettingsDialog()
{
delete ui;
}
SettingsDialog::Settings SettingsDialog::settings() const
{
return currentSettings;
}
void SettingsDialog::showPortInfo(int idx)
{
if (idx == -1)
return;
QStringList list = ui->serialPortInfoListBox->itemData(idx).toStringList();
ui->descriptionLabel->setText(tr("Description: %1").arg(list.count() > 1 ? list.at(1) : tr(blankString)));
ui->manufacturerLabel->setText(tr("Manufacturer: %1").arg(list.count() > 2 ? list.at(2) : tr(blankString)));
ui->serialNumberLabel->setText(tr("Serial number: %1").arg(list.count() > 3 ? list.at(3) : tr(blankString)));
ui->locationLabel->setText(tr("Location: %1").arg(list.count() > 4 ? list.at(4) : tr(blankString)));
ui->vidLabel->setText(tr("Vendor Identifier: %1").arg(list.count() > 5 ? list.at(5) : tr(blankString)));
ui->pidLabel->setText(tr("Product Identifier: %1").arg(list.count() > 6 ? list.at(6) : tr(blankString)));
}
void SettingsDialog::apply()
{
updateSettings();
hide();
}
void SettingsDialog::checkCustomBaudRatePolicy(int idx)
{
bool isCustomBaudRate = !ui->baudRateBox->itemData(idx).isValid();
ui->baudRateBox->setEditable(isCustomBaudRate);
if (isCustomBaudRate) {
ui->baudRateBox->clearEditText();
QLineEdit *edit = ui->baudRateBox->lineEdit();
edit->setValidator(intValidator); // 只允许 edit 输入整数 0 到 4000000
}
}
void SettingsDialog::checkCustomDevicePathPolicy(int idx)
{
bool isCustomPath = !ui->serialPortInfoListBox->itemData(idx).isValid();
ui->serialPortInfoListBox->setEditable(isCustomPath);
if (isCustomPath)
ui->serialPortInfoListBox->clearEditText();
}
void SettingsDialog::fillPortsParameters()
{
ui->baudRateBox->addItem(QStringLiteral("9600"), QSerialPort::Baud9600);
ui->baudRateBox->addItem(QStringLiteral("19200"), QSerialPort::Baud19200);
ui->baudRateBox->addItem(QStringLiteral("38400"), QSerialPort::Baud38400);
ui->baudRateBox->addItem(QStringLiteral("115200"), QSerialPort::Baud115200);
ui->baudRateBox->addItem(tr("Custom"));
ui->dataBitsBox->addItem(QStringLiteral("5"), QSerialPort::Data5);
ui->dataBitsBox->addItem(QStringLiteral("6"), QSerialPort::Data6);
ui->dataBitsBox->addItem(QStringLiteral("7"), QSerialPort::Data7);
ui->dataBitsBox->addItem(QStringLiteral("8"), QSerialPort::Data8);
ui->dataBitsBox->setCurrentIndex(3);
ui->parityBox->addItem(tr("None"), QSerialPort::NoParity);
ui->parityBox->addItem(tr("Even"), QSerialPort::EvenParity);
ui->parityBox->addItem(tr("Odd"), QSerialPort::OddParity);
ui->parityBox->addItem(tr("Mark"), QSerialPort::MarkParity);
ui->parityBox->addItem(tr("Space"), QSerialPort::SpaceParity);
ui->stopBitsBox->addItem(QStringLiteral("1"), QSerialPort::OneStop);
#ifdef Q_OS_WIN
ui->stopBitsBox->addItem(tr("1.5"), QSerialPort::OneAndHalfStop);
#endif
ui->stopBitsBox->addItem(QStringLiteral("2"), QSerialPort::TwoStop);
ui->flowControlBox->addItem(tr("None"), QSerialPort::NoFlowControl);
ui->flowControlBox->addItem(tr("RTS/CTS"), QSerialPort::HardwareControl);
ui->flowControlBox->addItem(tr("XON/XOFF"), QSerialPort::SoftwareControl);
}
void SettingsDialog::fillPortsInfo()
{
ui->serialPortInfoListBox->clear();
QString description;
QString manufacturer;
QString serialNumber;
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
QStringList list;
description = info.description();
manufacturer = info.manufacturer();
serialNumber = info.serialNumber();
list << info.portName()
<< (!description.isEmpty() ? description : blankString)
<< (!manufacturer.isEmpty() ? manufacturer : blankString)
<< (!serialNumber.isEmpty() ? serialNumber : blankString)
<< info.systemLocation()
<< (info.vendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : blankString)
<< (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : blankString);
ui->serialPortInfoListBox->addItem(list.first(), list);
}
ui->serialPortInfoListBox->addItem(tr("Custom"));
}
void SettingsDialog::updateSettings()
{
currentSettings.name = ui->serialPortInfoListBox->currentText();
if (ui->baudRateBox->currentIndex() == 4) {
currentSettings.baudRate = ui->baudRateBox->currentText().toInt();
} else {
currentSettings.baudRate = static_cast<QSerialPort::BaudRate>(
ui->baudRateBox->itemData(ui->baudRateBox->currentIndex()).toInt());
}
currentSettings.stringBaudRate = QString::number(currentSettings.baudRate);
currentSettings.dataBits = static_cast<QSerialPort::DataBits>(
ui->dataBitsBox->itemData(ui->dataBitsBox->currentIndex()).toInt());
currentSettings.stringDataBits = ui->dataBitsBox->currentText();
currentSettings.parity = static_
MyCom.rar_QT数据采集_metyu4_qt波形_界面 波形_采集界面
版权申诉
113 浏览量
2022-07-15
18:15:41
上传
评论
收藏 50KB RAR 举报
alvarocfc
- 粉丝: 109
- 资源: 1万+
最新资源
- 基于matlab实现 powell算法 用matlab实现,使用方法内附详细说明.rar
- 基于matlab的手写字体识别程序,并对结果进行保存.rar
- 基于c语言指纹识别demo代码 包括了指纹图像方向图计算、频率计算、gabor滤波器增强,细化,特征点提取,特征点匹配.rar
- 基于c++NSGA-2思想的多目标优化程序,采用进化算法处理多目标实值优化问题.rar
- Linux系统中常用权限管理命令
- Coello Coello等人提出了MOPSO 该程序基于matlab实现针对测试函数matlab程序
- Linux系统中常用权限管理命令
- AIR-AP1815-K9-ME-8-5-182-0.tar For Cisco AP1815
- 实验七.zip
- ESP8266刷固件软件flash-download-tools-v3.6.5,AT固件,机智云固件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0