页面控件替换,新增元数据查询页面(功能未实现)

This commit is contained in:
taocong
2026-05-28 08:57:13 +08:00
parent aa1bb42467
commit 3e05ecd9d2
18 changed files with 502 additions and 163 deletions
+100 -19
View File
@@ -3,7 +3,6 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QGroupBox>
#include <QFile>
#include <QCoreApplication>
@@ -14,11 +13,13 @@
#include <QDialog>
#include <QTextEdit>
#include "src/utils/logmanager.h"
#include "ElaPushButton.h"
BatchConvertPage::BatchConvertPage(QWidget *parent)
: QWidget(parent)
{
initUI();
loadFromCustJson();
}
BatchConvertPage::~BatchConvertPage()
@@ -48,14 +49,11 @@ void BatchConvertPage::initUI()
funcLayout->addWidget(m_funcTable);
QHBoxLayout *tableBtnLayout = new QHBoxLayout;
QPushButton *addBtn = new QPushButton("添加");
addBtn->setStyleSheet("padding: 6px 20px;");
ElaPushButton *addBtn = new ElaPushButton("添加");
connect(addBtn, &QPushButton::clicked, this, &BatchConvertPage::onAddFunction);
QPushButton *removeBtn = new QPushButton("删除选中");
removeBtn->setStyleSheet("padding: 6px 15px;");
ElaPushButton *removeBtn = new ElaPushButton("删除选中");
connect(removeBtn, &QPushButton::clicked, this, &BatchConvertPage::onRemoveFunction);
QPushButton *clearBtn = new QPushButton("清空列表");
clearBtn->setStyleSheet("padding: 6px 15px;");
ElaPushButton *clearBtn = new ElaPushButton("清空列表");
connect(clearBtn, &QPushButton::clicked, this, &BatchConvertPage::onClearTable);
tableBtnLayout->addWidget(addBtn);
tableBtnLayout->addStretch();
@@ -99,8 +97,7 @@ void BatchConvertPage::initUI()
layout->addWidget(progressBox);
QHBoxLayout *btnLayout = new QHBoxLayout;
m_startBtn = new QPushButton("开始转换");
m_startBtn->setStyleSheet("background-color: #1abc9c; color: white; padding: 10px 30px; font-size: 14px; border: none; border-radius: 4px;");
m_startBtn = new ElaPushButton("开始转换");
connect(m_startBtn, &QPushButton::clicked, this, &BatchConvertPage::onStartConvert);
btnLayout->addStretch();
btnLayout->addWidget(m_startBtn);
@@ -323,18 +320,18 @@ void BatchConvertPage::onClearTable()
bool BatchConvertPage::saveToCustJson(const QStringList &funcList)
{
QString jsonPath = QCoreApplication::applicationDirPath() + "/uf2touft3/cust.json";
QFile file(jsonPath);
if (!file.open(QIODevice::ReadOnly)) {
LogManager::instance()->logError(QString("无法打开文件: %1").arg(jsonPath));
return false;
}
QByteArray data = file.readAll();
file.close();
QString content = QString::fromUtf8(data);
int dirStart = content.indexOf("\"dir\":[");
if (dirStart < 0) {
dirStart = content.indexOf("\"dir\" : [");
@@ -343,7 +340,7 @@ bool BatchConvertPage::saveToCustJson(const QStringList &funcList)
LogManager::instance()->logError("未找到 \"dir\" 节点");
return false;
}
int arrayStart = content.indexOf('[', dirStart);
int bracketCount = 1;
int pos = arrayStart + 1;
@@ -353,27 +350,90 @@ bool BatchConvertPage::saveToCustJson(const QStringList &funcList)
pos++;
}
int arrayEnd = pos;
QString newDirArray = "[";
for (int i = 0; i < funcList.size(); ++i) {
if (i > 0) newDirArray += ",";
newDirArray += "\n \"" + funcList[i] + ".service_design\"";
}
newDirArray += "\n ]";
content.replace(arrayStart, arrayEnd - arrayStart, newDirArray);
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
LogManager::instance()->logError(QString("无法写入文件: %1").arg(jsonPath));
return false;
}
file.write(content.toUtf8());
file.close();
return true;
}
void BatchConvertPage::loadFromCustJson()
{
QString jsonPath = QCoreApplication::applicationDirPath() + "/uf2touft3/cust.json";
QFile file(jsonPath);
if (!file.open(QIODevice::ReadOnly)) {
return;
}
QByteArray data = file.readAll();
file.close();
QString content = QString::fromUtf8(data);
int convertStart = content.indexOf("\"convert\":");
if (convertStart < 0) {
convertStart = content.indexOf("\"convert\" :");
}
if (convertStart < 0) {
return;
}
int arrayStart = content.indexOf('[', convertStart);
int bracketCount = 1;
int pos = arrayStart + 1;
while (pos < content.length() && bracketCount > 0) {
if (content[pos] == '[') bracketCount++;
else if (content[pos] == ']') bracketCount--;
pos++;
}
int arrayEnd = pos;
QString arrayContent = content.mid(arrayStart + 1, arrayEnd - arrayStart - 1).trimmed();
if (arrayContent.isEmpty() || arrayContent == "null") {
return;
}
QStringList items;
int itemPos = 0;
while (itemPos < arrayContent.length()) {
int itemStart = arrayContent.indexOf('"', itemPos);
if (itemStart < 0) break;
int itemEnd = arrayContent.indexOf('"', itemStart + 1);
if (itemEnd < 0) break;
QString item = arrayContent.mid(itemStart + 1, itemEnd - itemStart - 1);
items.append(item);
itemPos = itemEnd + 1;
}
for (QString &item : items) {
if (item.endsWith(".service_design")) {
item = item.left(item.length() - static_cast<int>(strlen(".service_design")));
}
}
m_funcList = items;
updateTable();
}
void BatchConvertPage::onStartConvert()
{
if (m_startBtn->text() == "停止转换") {
@@ -427,3 +487,24 @@ void BatchConvertPage::onConvertFinished()
m_startBtn->setText("开始转换");
m_startBtn->setStyleSheet("background-color: #1abc9c; color: white; padding: 10px 30px; font-size: 14px; border: none; border-radius: 4px;");
}
void BatchConvertPage::addFunction(const QString &funcName)
{
if (funcName.isEmpty()) {
return;
}
if (m_funcList.contains(funcName)) {
QMessageBox::information(nullptr, "提示", QString("功能 [%1] 已在列表中").arg(funcName));
return;
}
m_funcList.append(funcName);
updateTable();
if (saveToCustJson(m_funcList)) {
QMessageBox::information(nullptr, "提示", QString("已将功能 [%1] 添加到业务转码").arg(funcName));
} else {
QMessageBox::warning(nullptr, "警告", "添加到业务转码成功,但保存到 cust.json 失败");
}
}