367 lines
7.9 KiB
C++
367 lines
7.9 KiB
C++
#include "KJ135WBJYAlgWidgetComponet.h"
|
|
#include <QHBoxLayout>
|
|
#include <QMessageBox>
|
|
|
|
AbstractComponentWidget::AbstractComponentWidget(QWidget* parent) :QWidget(parent)
|
|
{
|
|
this->componentType = ComponentType::UNKNOW; // 默认未知类型
|
|
this->ParaName = QString(); // 参数名称
|
|
this->ParaChsName = QString(); // 参数中文名称
|
|
this->Description = QString(); // 参数描述
|
|
this->Datatype = QString(); // 数据类型
|
|
this->ParaType = QString(); // 参数类型
|
|
}
|
|
|
|
AbstractComponentWidget::~AbstractComponentWidget()
|
|
{
|
|
}
|
|
|
|
QString AbstractComponentWidget::getParaName() const
|
|
{
|
|
return this->ParaName;
|
|
}
|
|
|
|
void AbstractComponentWidget::setParaName(const QString& name)
|
|
{
|
|
this->ParaName = name;
|
|
}
|
|
|
|
QString AbstractComponentWidget::getParaChsName() const
|
|
{
|
|
return this->ParaChsName;
|
|
}
|
|
|
|
void AbstractComponentWidget::setParaChsName(const QString& name)
|
|
{
|
|
this->ParaChsName = name;
|
|
}
|
|
|
|
QString AbstractComponentWidget::getDescription() const
|
|
{
|
|
|
|
return this->Description;
|
|
}
|
|
|
|
void AbstractComponentWidget::setDescription(const QString& description)
|
|
{
|
|
this->setToolTip(description);// 绑定提示
|
|
this->Description = description;
|
|
}
|
|
|
|
QString AbstractComponentWidget::getDatatype() const
|
|
{
|
|
return this->Datatype;
|
|
}
|
|
|
|
void AbstractComponentWidget::setDatatype(const QString& datatype)
|
|
{
|
|
this->Datatype = datatype;
|
|
}
|
|
|
|
QString AbstractComponentWidget::getParaType() const
|
|
{
|
|
return this->ParaType;
|
|
}
|
|
|
|
void AbstractComponentWidget::setParaType(const QString& type)
|
|
{
|
|
this->ParaType = type;
|
|
}
|
|
|
|
void AbstractComponentWidget::setComponentType(ComponentType type)
|
|
{
|
|
this->componentType = type;
|
|
}
|
|
|
|
ComponentType AbstractComponentWidget::getComponentType() const
|
|
{
|
|
return this->componentType;
|
|
}
|
|
|
|
// File 文件选择
|
|
|
|
FileSelectWidget::FileSelectWidget(QWidget* parent) :AbstractComponentWidget(parent)
|
|
{
|
|
}
|
|
|
|
FileSelectWidget::~FileSelectWidget()
|
|
{
|
|
}
|
|
|
|
void FileSelectWidget::initUI()
|
|
{
|
|
// 初始化控件
|
|
// fileNameLabel
|
|
fileNameLabel = new QLabel(this);
|
|
fileNameLabel->setText(this->getParaName());
|
|
|
|
//filePathEdit
|
|
filePathEdit = new QLineEdit(this);
|
|
|
|
// fileSelectButton
|
|
fileSelectButton = new QToolButton(this);
|
|
fileSelectButton->setText(u8"选择文件");
|
|
|
|
|
|
|
|
// 设置文件最小控件高度
|
|
fileNameLabel->setMinimumHeight(30);
|
|
filePathEdit->setMinimumHeight(30);
|
|
fileSelectButton->setMinimumHeight(30);
|
|
|
|
// 绑定信号-槽
|
|
QObject::connect(fileSelectButton, SIGNAL(clicked()) , this, SLOT(onFileSelectButtonClicked()));
|
|
|
|
// 水平布局
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
layout->addWidget(fileNameLabel);
|
|
layout->addWidget(filePathEdit);
|
|
layout->addWidget(fileSelectButton);
|
|
this->setLayout(layout);
|
|
|
|
|
|
}
|
|
|
|
QString FileSelectWidget::getValue() const
|
|
{
|
|
if (nullptr != filePathEdit)
|
|
{
|
|
return filePathEdit->text();
|
|
}
|
|
else {
|
|
QMessageBox::warning(nullptr, u8"警告", u8"请先选择文件");
|
|
return QString();
|
|
}
|
|
}
|
|
|
|
void FileSelectWidget::onFileSelectButtonClicked()
|
|
{
|
|
if (this->componentType == ComponentType::FileSelect)
|
|
{
|
|
QString fileName = QFileDialog::getOpenFileName(this, u8"选择文件", "", u8"所有文件(*.*);;文本文件(*.txt);;图像文件(*.png *.jpg *.bmp)");
|
|
if (!fileName.isEmpty())
|
|
{
|
|
filePathEdit->setText(fileName);
|
|
}
|
|
else {
|
|
QMessageBox::warning(this, u8"警告", u8"请选择文件");
|
|
}
|
|
}
|
|
else if (this->componentType == ComponentType::FolderSelect)
|
|
{
|
|
QString fileName = QFileDialog::getOpenFileName(this,
|
|
QString(u8"选择%1").arg(this->getParaChsName()),
|
|
"",
|
|
QString(u8"所有文件(*.*);;%1文件(*.%2);;").arg(this->getDatatype()).arg(this->getDatatype()));
|
|
if (!fileName.isEmpty())
|
|
{
|
|
filePathEdit->setText(fileName);
|
|
}
|
|
else {
|
|
QMessageBox::warning(this, u8"警告", u8"请选择文件");
|
|
}
|
|
}
|
|
else {
|
|
QString fileName = QFileDialog::getExistingDirectory(this,
|
|
QString(u8"选择文件夹:%1").arg(this->getParaChsName()),
|
|
"");
|
|
if (!fileName.isEmpty())
|
|
{
|
|
filePathEdit->setText(fileName);
|
|
}
|
|
else {
|
|
QMessageBox::warning(this, u8"警告", u8"请选择文件夹");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 整数输入组件
|
|
IntInputWidget::IntInputWidget(QWidget* parent) :AbstractComponentWidget(parent)
|
|
{
|
|
|
|
}
|
|
IntInputWidget::~IntInputWidget()
|
|
{
|
|
}
|
|
|
|
void IntInputWidget::initUI()
|
|
{
|
|
fileNameLabel = new QLabel(this);
|
|
fileNameLabel->setText(this->getParaName());
|
|
|
|
|
|
intInput = new QSpinBox(this);
|
|
intInput->setRange(-1000000, 1000000);
|
|
intInput->setSingleStep(1);
|
|
|
|
// 设置文件最小控件高度
|
|
fileNameLabel->setMinimumHeight(30);
|
|
intInput->setMinimumHeight(30);
|
|
// 水平布局
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
layout->addWidget(fileNameLabel);
|
|
layout->addWidget(intInput);
|
|
this->setLayout(layout);
|
|
}
|
|
|
|
QString IntInputWidget::getValue() const
|
|
{
|
|
if (nullptr == this->intInput)
|
|
{
|
|
return QString();
|
|
}
|
|
else {
|
|
return QString::number(this->intInput->value());
|
|
}
|
|
}
|
|
|
|
// 浮点数输入组件
|
|
|
|
DoubleInputWidget::DoubleInputWidget(QWidget* parent) :AbstractComponentWidget(parent)
|
|
{
|
|
}
|
|
|
|
DoubleInputWidget::~DoubleInputWidget()
|
|
{
|
|
}
|
|
|
|
void DoubleInputWidget::initUI()
|
|
{
|
|
fileNameLabel = new QLabel(this);
|
|
fileNameLabel->setText(this->getParaName());
|
|
|
|
|
|
doubleInput = new QDoubleSpinBox(this);
|
|
doubleInput->setRange(-1000000, 1000000);
|
|
doubleInput->setSingleStep(1e-6);
|
|
|
|
// 设置文件最小控件高度
|
|
fileNameLabel->setMinimumHeight(30);
|
|
doubleInput->setMinimumHeight(30);
|
|
// 水平布局
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
layout->addWidget(fileNameLabel);
|
|
layout->addWidget(doubleInput);
|
|
this->setLayout(layout);
|
|
}
|
|
|
|
QString DoubleInputWidget::getValue() const
|
|
{
|
|
if (nullptr != this->doubleInput)
|
|
{
|
|
return QString::number(this->doubleInput->value(),'e',14);
|
|
}
|
|
else {
|
|
return QString();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 整数输入组件
|
|
ScopeIntInputWidget::ScopeIntInputWidget(QWidget* parent) :AbstractComponentWidget(parent)
|
|
{
|
|
|
|
}
|
|
|
|
ScopeIntInputWidget::~ScopeIntInputWidget()
|
|
{
|
|
}
|
|
|
|
void ScopeIntInputWidget::initUI()
|
|
{
|
|
fileNameLabel = new QLabel(this);
|
|
fileNameLabel->setText(this->getParaName());
|
|
intInputMin = new QSpinBox(this);
|
|
intInputMin->setRange(-1000000, 1000000);
|
|
intInputMin->setSingleStep(1);
|
|
|
|
scopeConnectStr = new QLabel(this);
|
|
scopeConnectStr->setText(u8" - ");
|
|
|
|
intInputMax = new QSpinBox(this);
|
|
intInputMax->setRange(-1000000, 1000000);
|
|
intInputMax->setSingleStep(1);
|
|
|
|
// 设置文件最小控件高度
|
|
fileNameLabel->setMinimumHeight(30);
|
|
intInputMin->setMinimumHeight(30);
|
|
intInputMax->setMinimumHeight(30);
|
|
// 水平布局
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
layout->addWidget(fileNameLabel);
|
|
layout->addWidget(intInputMin);
|
|
layout->addWidget(scopeConnectStr);
|
|
layout->addWidget(intInputMax);
|
|
this->setLayout(layout);
|
|
}
|
|
|
|
QString ScopeIntInputWidget::getValue() const
|
|
{
|
|
if (nullptr != intInputMin && nullptr != intInputMax)
|
|
{
|
|
return QString("%1;%2")
|
|
.arg(QString::number(intInputMin->value()))
|
|
.arg(QString::number(intInputMax->value()));
|
|
}
|
|
else {
|
|
QMessageBox::warning(nullptr, u8"警告", u8"请先输入");
|
|
}
|
|
return QString();
|
|
}
|
|
|
|
|
|
|
|
// 浮点数输入组件
|
|
ScopeDoubleInputWidget::ScopeDoubleInputWidget(QWidget* parent) :AbstractComponentWidget(parent)
|
|
{
|
|
}
|
|
|
|
ScopeDoubleInputWidget::~ScopeDoubleInputWidget()
|
|
{
|
|
}
|
|
|
|
void ScopeDoubleInputWidget::initUI()
|
|
{
|
|
fileNameLabel = new QLabel(this);
|
|
fileNameLabel->setText(this->getParaName());
|
|
doubleInputMin = new QDoubleSpinBox(this);
|
|
doubleInputMax->setRange(-1000000, 1000000);
|
|
doubleInputMin->setSingleStep(1);
|
|
|
|
scopeConnectStr = new QLabel(this);
|
|
scopeConnectStr->setText(u8" - ");
|
|
|
|
doubleInputMax = new QDoubleSpinBox(this);
|
|
doubleInputMax->setRange(-1000000, 1000000);
|
|
doubleInputMax->setSingleStep(1);
|
|
|
|
// 设置文件最小控件高度
|
|
fileNameLabel->setMinimumHeight(30);
|
|
doubleInputMin->setMinimumHeight(30);
|
|
doubleInputMax->setMinimumHeight(30);
|
|
// 水平布局
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
layout->addWidget(fileNameLabel);
|
|
layout->addWidget(doubleInputMin);
|
|
layout->addWidget(scopeConnectStr);
|
|
layout->addWidget(doubleInputMax);
|
|
this->setLayout(layout);
|
|
}
|
|
|
|
QString ScopeDoubleInputWidget::getValue() const
|
|
{
|
|
if (nullptr != doubleInputMin && nullptr != doubleInputMax)
|
|
{
|
|
return QString("%1;%2")
|
|
.arg(QString::number(doubleInputMin->value(),'e',14))
|
|
.arg(QString::number(doubleInputMax->value(), 'e', 14));
|
|
}
|
|
else {
|
|
QMessageBox::warning(nullptr, u8"警告", u8"请先输入");
|
|
}
|
|
return QString();
|
|
}
|