133 lines
3.9 KiB
C++
133 lines
3.9 KiB
C++
#include "QWBFZAlgComponetXmlParamsDialog.h"
|
||
#include "ui_QWBFZAlgComponetXmlParamsDialog.h"
|
||
#include <QFileDialog>
|
||
#include <QMessageBox>
|
||
#include "WBFZAlgComponetXmlParaseOperator.h"
|
||
#include "FileOperator.h"
|
||
QWBFZAlgComponetXmlParamsDialog::QWBFZAlgComponetXmlParamsDialog(QWidget *parent)
|
||
: QDialog(parent),
|
||
ui(new Ui::QWBFZAlgComponetXmlParamsDialogClass)
|
||
{
|
||
ui->setupUi(this);
|
||
|
||
// 绑定信号-槽
|
||
QObject::connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(OnacceptButton_Clicked()));
|
||
QObject::connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(OncancelButton_Clicked()));
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
QWBFZAlgComponetXmlParamsDialog::~QWBFZAlgComponetXmlParamsDialog()
|
||
{
|
||
delete ui;
|
||
delete xmlParseOperator;
|
||
}
|
||
|
||
void QWBFZAlgComponetXmlParamsDialog::OnacceptButton_Clicked()
|
||
{
|
||
// 获取参数值
|
||
QString workspacePath = workspacePathWidget->getValue();
|
||
qDebug() << "workspacePath:" << workspacePath;
|
||
QMap<QString, QString> parameterMap;
|
||
for (long i = 0; i < parameterWidgetList.size(); i++)
|
||
{
|
||
AbstractComponentWidget* parameterWidget = parameterWidgetList.at(i);
|
||
QString parameterValue = parameterWidget->getValue();
|
||
qDebug() << "parameterValue:" << parameterValue;
|
||
parameterMap.insert(parameterWidget->getParaName(), parameterValue);
|
||
}
|
||
|
||
// 1. 获取xml文件模板路径
|
||
QString formatxmlpath = this->formatxmlString;
|
||
// 2. 获取xml文件输出路径
|
||
QString filepath = QFileDialog::getSaveFileName(this, u8"保存xml文件", "", u8"xml文件(*.xml)");
|
||
if (filepath.isEmpty())
|
||
{
|
||
QMessageBox::warning(this, u8"警告", u8"请选择xml文件");
|
||
return;
|
||
}
|
||
else {
|
||
qDebug() << "filepath:" << filepath;
|
||
}
|
||
xmlParseOperator = new WBFZAlgComponetXmlParaseOperator(this);
|
||
xmlParseOperator->writeXmlFile(formatxmlString, filepath, workspacePath,parameterMap);
|
||
// 3. 关闭窗口
|
||
QMessageBox::information(nullptr, u8"提示", u8"写入完成");
|
||
}
|
||
|
||
void QWBFZAlgComponetXmlParamsDialog::OncancelButton_Clicked()
|
||
{
|
||
this->close();
|
||
}
|
||
|
||
void QWBFZAlgComponetXmlParamsDialog::loadXmlFile(const QString& fileName)
|
||
{
|
||
if (nullptr != xmlParseOperator)
|
||
{
|
||
delete xmlParseOperator;
|
||
xmlParseOperator = nullptr;
|
||
}
|
||
else {}
|
||
this->formatxmlString = fileName;
|
||
// 创建xml解析类
|
||
xmlParseOperator = new WBFZAlgComponetXmlParaseOperator(this);
|
||
xmlParseOperator->loadXmlFile(fileName);
|
||
|
||
// 根据解析结果创建界面ui
|
||
// 1. workspace路径
|
||
workspacePathWidget = new FileSelectWidget(this);
|
||
workspacePathWidget->setParaName("WorkSpace");
|
||
workspacePathWidget->setParaChsName(u8"工作空间路径");
|
||
workspacePathWidget->setDescription(u8"工作空间路径");
|
||
workspacePathWidget->setDatatype(u8"string");
|
||
workspacePathWidget->setComponentType(ComponentType::FolderSelect);
|
||
workspacePathWidget->initUI();
|
||
|
||
ui->verticalLayout_param->addWidget(workspacePathWidget);
|
||
// 2. 参数列表
|
||
QList < WBFZAlgComponetXmlParamenterItem*> parameterList = xmlParseOperator->getParameterList();
|
||
for (long i = 0; i < parameterList.size(); i++)
|
||
{
|
||
WBFZAlgComponetXmlParamenterItem* item = parameterList.at(i);
|
||
qDebug() << "item->getParaName():" << item->getParaName();
|
||
// 创建参数组件
|
||
AbstractComponentWidget* parameterWidget = createComponentWidgetFactory(
|
||
item->getParaName(),
|
||
item->getParaChsName(),
|
||
item->getDatatype(),
|
||
item->getParaType(),
|
||
item->getDescription(),
|
||
this);
|
||
//parameterWidget->initUI();
|
||
|
||
ui->verticalLayout_param->addWidget(parameterWidget);
|
||
|
||
this->parameterWidgetList.append(parameterWidget);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
void WBFZAlgComponetLoadXmlParamsProcess()
|
||
{
|
||
QString xmlFileName = QFileDialog::getOpenFileName(nullptr, u8"选择算法组件xml参数文件", "", u8"xml文件(*.xml)");
|
||
if (xmlFileName.isEmpty())
|
||
{
|
||
QMessageBox::warning(nullptr, u8"警告", u8"请选择算法组件xml参数文件");
|
||
return;
|
||
}
|
||
else {
|
||
// TODO: 解析xml文件,加载参数
|
||
qDebug() << "xmlFileName:" << xmlFileName;
|
||
|
||
QWBFZAlgComponetXmlParamsDialog* dialog = new QWBFZAlgComponetXmlParamsDialog();
|
||
dialog->setWindowTitle(QString(u8"算法组件xml参数文件-%1").arg(getFileNameFromPath(xmlFileName)));
|
||
dialog->loadXmlFile(xmlFileName);
|
||
dialog->show();
|
||
return;
|
||
}
|
||
return;
|
||
}
|