空二界面工具包V0.1创建完成
parent
88421d6a25
commit
5706d61ec6
|
@ -137,8 +137,21 @@ QString FileSelectWidget::getValue() const
|
||||||
{
|
{
|
||||||
if (nullptr != filePathEdit)
|
if (nullptr != filePathEdit)
|
||||||
{
|
{
|
||||||
|
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();
|
return filePathEdit->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
QMessageBox::warning(nullptr, u8"警告", u8"请先选择文件");
|
QMessageBox::warning(nullptr, u8"警告", u8"请先选择文件");
|
||||||
return QString();
|
return QString();
|
||||||
|
|
|
@ -9,6 +9,14 @@ QWBFZAlgComponetXmlParamsDialog::QWBFZAlgComponetXmlParamsDialog(QWidget *parent
|
||||||
ui(new Ui::QWBFZAlgComponetXmlParamsDialogClass)
|
ui(new Ui::QWBFZAlgComponetXmlParamsDialogClass)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
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()
|
QWBFZAlgComponetXmlParamsDialog::~QWBFZAlgComponetXmlParamsDialog()
|
||||||
|
@ -17,6 +25,43 @@ QWBFZAlgComponetXmlParamsDialog::~QWBFZAlgComponetXmlParamsDialog()
|
||||||
delete xmlParseOperator;
|
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)
|
void QWBFZAlgComponetXmlParamsDialog::loadXmlFile(const QString& fileName)
|
||||||
{
|
{
|
||||||
if (nullptr != xmlParseOperator)
|
if (nullptr != xmlParseOperator)
|
||||||
|
@ -25,7 +70,7 @@ void QWBFZAlgComponetXmlParamsDialog::loadXmlFile(const QString& fileName)
|
||||||
xmlParseOperator = nullptr;
|
xmlParseOperator = nullptr;
|
||||||
}
|
}
|
||||||
else {}
|
else {}
|
||||||
|
this->formatxmlString = fileName;
|
||||||
// ´´½¨xml½âÎöÀà
|
// ´´½¨xml½âÎöÀà
|
||||||
xmlParseOperator = new WBFZAlgComponetXmlParaseOperator(this);
|
xmlParseOperator = new WBFZAlgComponetXmlParaseOperator(this);
|
||||||
xmlParseOperator->loadXmlFile(fileName);
|
xmlParseOperator->loadXmlFile(fileName);
|
||||||
|
@ -37,6 +82,7 @@ void QWBFZAlgComponetXmlParamsDialog::loadXmlFile(const QString& fileName)
|
||||||
workspacePathWidget->setParaChsName(u8"¹¤×÷¿Õ¼ä·¾¶");
|
workspacePathWidget->setParaChsName(u8"¹¤×÷¿Õ¼ä·¾¶");
|
||||||
workspacePathWidget->setDescription(u8"¹¤×÷¿Õ¼ä·¾¶");
|
workspacePathWidget->setDescription(u8"¹¤×÷¿Õ¼ä·¾¶");
|
||||||
workspacePathWidget->setDatatype(u8"string");
|
workspacePathWidget->setDatatype(u8"string");
|
||||||
|
workspacePathWidget->setComponentType(ComponentType::FolderSelect);
|
||||||
workspacePathWidget->initUI();
|
workspacePathWidget->initUI();
|
||||||
|
|
||||||
ui->verticalLayout_param->addWidget(workspacePathWidget);
|
ui->verticalLayout_param->addWidget(workspacePathWidget);
|
||||||
|
|
|
@ -21,6 +21,11 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::QWBFZAlgComponetXmlParamsDialogClass* ui;
|
Ui::QWBFZAlgComponetXmlParamsDialogClass* ui;
|
||||||
|
QString formatxmlString; // 格式化字符串
|
||||||
|
public slots:
|
||||||
|
void OnacceptButton_Clicked(); // 确定按钮点击事件
|
||||||
|
void OncancelButton_Clicked(); // 取消按钮点击事件
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WBFZAlgComponetXmlParaseOperator* xmlParseOperator = nullptr; // 算法组件xml参数解析类
|
WBFZAlgComponetXmlParaseOperator* xmlParseOperator = nullptr; // 算法组件xml参数解析类
|
||||||
|
|
|
@ -33,6 +33,75 @@ void WBFZAlgComponetXmlParaseOperator::loadXmlFile(const QString& fileName)
|
||||||
this->parseXmlFile();
|
this->parseXmlFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WBFZAlgComponetXmlParaseOperator::writeXmlFile(const QString& formatfilepath, QString outfilepath, QString workspace, QMap<QString, QString> 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()
|
void WBFZAlgComponetXmlParaseOperator::parseXmlFile()
|
||||||
{
|
{
|
||||||
// 1. Load the XML file
|
// 1. Load the XML file
|
||||||
|
|
|
@ -64,6 +64,10 @@ public:
|
||||||
~WBFZAlgComponetXmlParaseOperator();
|
~WBFZAlgComponetXmlParaseOperator();
|
||||||
void loadXmlFile(const QString& fileName);
|
void loadXmlFile(const QString& fileName);
|
||||||
|
|
||||||
|
void writeXmlFile(const QString& formatfilepath, QString outfilepath,QString workspace, QMap<QString, QString> inputParamslist);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parseXmlFile();
|
void parseXmlFile();
|
||||||
void displayParsedData();
|
void displayParsedData();
|
||||||
|
|
Loading…
Reference in New Issue