diff --git a/Toolbox/KJ135WBJYAlgInterfaceToolbox/KJ135WBJYAlgWidgetComponet.cpp b/Toolbox/KJ135WBJYAlgInterfaceToolbox/KJ135WBJYAlgWidgetComponet.cpp index 96dd4b6..9fdb6bf 100644 --- a/Toolbox/KJ135WBJYAlgInterfaceToolbox/KJ135WBJYAlgWidgetComponet.cpp +++ b/Toolbox/KJ135WBJYAlgInterfaceToolbox/KJ135WBJYAlgWidgetComponet.cpp @@ -137,7 +137,20 @@ QString FileSelectWidget::getValue() const { if (nullptr != filePathEdit) { - return filePathEdit->text(); + if (this->componentType == ComponentType::FolderSelect) { + //检测最后一个字符是否为分隔符 + QString filePath = filePathEdit->text(); + if (filePath.endsWith(QDir::separator())) { + return filePath; + } + else { + return QString(u8"%1%2").arg(filePath).arg(QDir::separator()); + } + } + else{ + return filePathEdit->text(); + } + } else { QMessageBox::warning(nullptr, u8"警告", u8"请先选择文件"); diff --git a/Toolbox/KJ135WBJYAlgInterfaceToolbox/QWBFZAlgComponetXmlParamsDialog.cpp b/Toolbox/KJ135WBJYAlgInterfaceToolbox/QWBFZAlgComponetXmlParamsDialog.cpp index ac0ad2b..8f77424 100644 --- a/Toolbox/KJ135WBJYAlgInterfaceToolbox/QWBFZAlgComponetXmlParamsDialog.cpp +++ b/Toolbox/KJ135WBJYAlgInterfaceToolbox/QWBFZAlgComponetXmlParamsDialog.cpp @@ -9,6 +9,14 @@ QWBFZAlgComponetXmlParamsDialog::QWBFZAlgComponetXmlParamsDialog(QWidget *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() @@ -17,6 +25,43 @@ QWBFZAlgComponetXmlParamsDialog::~QWBFZAlgComponetXmlParamsDialog() delete xmlParseOperator; } +void QWBFZAlgComponetXmlParamsDialog::OnacceptButton_Clicked() +{ + // ȡֵ + QString workspacePath = workspacePathWidget->getValue(); + qDebug() << "workspacePath:" << workspacePath; + QMap 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) @@ -25,7 +70,7 @@ void QWBFZAlgComponetXmlParamsDialog::loadXmlFile(const QString& fileName) xmlParseOperator = nullptr; } else {} - + this->formatxmlString = fileName; // xml xmlParseOperator = new WBFZAlgComponetXmlParaseOperator(this); xmlParseOperator->loadXmlFile(fileName); @@ -37,6 +82,7 @@ void QWBFZAlgComponetXmlParamsDialog::loadXmlFile(const QString& fileName) workspacePathWidget->setParaChsName(u8"ռ·"); workspacePathWidget->setDescription(u8"ռ·"); workspacePathWidget->setDatatype(u8"string"); + workspacePathWidget->setComponentType(ComponentType::FolderSelect); workspacePathWidget->initUI(); ui->verticalLayout_param->addWidget(workspacePathWidget); diff --git a/Toolbox/KJ135WBJYAlgInterfaceToolbox/QWBFZAlgComponetXmlParamsDialog.h b/Toolbox/KJ135WBJYAlgInterfaceToolbox/QWBFZAlgComponetXmlParamsDialog.h index 6cf1f61..15e1485 100644 --- a/Toolbox/KJ135WBJYAlgInterfaceToolbox/QWBFZAlgComponetXmlParamsDialog.h +++ b/Toolbox/KJ135WBJYAlgInterfaceToolbox/QWBFZAlgComponetXmlParamsDialog.h @@ -21,6 +21,11 @@ public: private: Ui::QWBFZAlgComponetXmlParamsDialogClass* ui; + QString formatxmlString; // ʽַ +public slots: + void OnacceptButton_Clicked(); // ȷť¼ + void OncancelButton_Clicked(); // ȡť¼ + private: WBFZAlgComponetXmlParaseOperator* xmlParseOperator = nullptr; // 㷨xml diff --git a/Toolbox/KJ135WBJYAlgInterfaceToolbox/WBFZAlgComponetXmlParaseOperator.cpp b/Toolbox/KJ135WBJYAlgInterfaceToolbox/WBFZAlgComponetXmlParaseOperator.cpp index 7abf2ac..ebb28e4 100644 --- a/Toolbox/KJ135WBJYAlgInterfaceToolbox/WBFZAlgComponetXmlParaseOperator.cpp +++ b/Toolbox/KJ135WBJYAlgInterfaceToolbox/WBFZAlgComponetXmlParaseOperator.cpp @@ -33,6 +33,75 @@ void WBFZAlgComponetXmlParaseOperator::loadXmlFile(const QString& fileName) this->parseXmlFile(); } +void WBFZAlgComponetXmlParaseOperator::writeXmlFile(const QString& formatfilepath, QString outfilepath, QString workspace, QMap inputParamslist) +{ + // ģxmlļ + QFile inputFile(formatfilepath); + if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug() << "Failed to open input XML file."; + return; + } + // QDomDocument + QDomDocument doc; + if (!doc.setContent(&inputFile)) { + qDebug() << "Failed to parse input XML file."; + inputFile.close(); + return; + } + // رļ + inputFile.close(); + + // ޸Ĺռ· + QDomElement root = doc.documentElement(); + QDomNodeList workspacePathNodes = root.elementsByTagName("WorkSpace"); + if (workspacePathNodes.count() > 0) { + QDomElement workspacePathElement = workspacePathNodes.at(0).toElement(); + workspacePathElement.firstChild().setNodeValue(workspace); + } + else { + qDebug() << "WorkspacePath not found."; + return; + } + + // ޸InputǩµParamǩµParaValueǩ + QDomNodeList InputsNodes = root.elementsByTagName("Inputs"); + if (InputsNodes.count() > 0) { + QDomElement InputsElement = InputsNodes.at(0).toElement(); + QDomNodeList parameterNodes = InputsElement.elementsByTagName("Parameter"); + for (int i = 0; i < parameterNodes.count(); ++i) { + QDomElement parameterElement = parameterNodes.at(i).toElement(); + QString paraName = parameterElement.firstChildElement("ParaName").text(); + if (inputParamslist.contains(paraName)) { + QDomNodeList valueNodes = parameterElement.elementsByTagName("ParaValue"); + if (valueNodes.count() > 0) { + valueNodes.at(0).firstChild().setNodeValue(inputParamslist.value(paraName)); + } + } + } + } + else { + qDebug() << "Inputs not found."; + return; + } + // 7. ޸ĺXMLļ + QFile outputFile(outfilepath); + if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text)) { + qDebug() << "Failed to open output XML file."; + return; + } + // ޸ĺдļ + QTextStream out(&outputFile); + out.setCodec("UTF-8"); + doc.save(out, 4); // 4ʾ + outputFile.close(); + qDebug() << "XML file written successfully."; + + + + +} + + void WBFZAlgComponetXmlParaseOperator::parseXmlFile() { // 1. Load the XML file diff --git a/Toolbox/KJ135WBJYAlgInterfaceToolbox/WBFZAlgComponetXmlParaseOperator.h b/Toolbox/KJ135WBJYAlgInterfaceToolbox/WBFZAlgComponetXmlParaseOperator.h index 9270f65..52fc953 100644 --- a/Toolbox/KJ135WBJYAlgInterfaceToolbox/WBFZAlgComponetXmlParaseOperator.h +++ b/Toolbox/KJ135WBJYAlgInterfaceToolbox/WBFZAlgComponetXmlParaseOperator.h @@ -64,6 +64,10 @@ public: ~WBFZAlgComponetXmlParaseOperator(); void loadXmlFile(const QString& fileName); + void writeXmlFile(const QString& formatfilepath, QString outfilepath,QString workspace, QMap inputParamslist); + + + private: void parseXmlFile(); void displayParsedData();