|
|
@ -19,61 +19,128 @@ CUIConfig *CFDStructDataManagerBase::getParamUIConfig()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 写入json
|
|
|
|
// 写入json
|
|
|
|
void jsonAdd(rapidjson::Document& document, QVariant value, QVector<QVariant> path) {
|
|
|
|
void jsonAdd(rapidjson::Document &document, QVariant value, QVector<QVariant> path)
|
|
|
|
|
|
|
|
{
|
|
|
|
using namespace rapidjson;
|
|
|
|
using namespace rapidjson;
|
|
|
|
|
|
|
|
|
|
|
|
// 获取分配器
|
|
|
|
// 获取分配器
|
|
|
|
Document::AllocatorType& allocator = document.GetAllocator();
|
|
|
|
Document::AllocatorType &allocator = document.GetAllocator();
|
|
|
|
|
|
|
|
|
|
|
|
// 递归地创建路径中的对象
|
|
|
|
// 递归地创建路径中的对象
|
|
|
|
Value* current = &document;
|
|
|
|
Value *current = &document;
|
|
|
|
for (int i = 0; i < path.size(); ++i) {
|
|
|
|
for (int i = 0; i < path.size(); ++i)
|
|
|
|
// const std::string& key = path[i];
|
|
|
|
{
|
|
|
|
|
|
|
|
// const std::string& key = path[i];
|
|
|
|
QVariant key = path.at(i);
|
|
|
|
QVariant key = path.at(i);
|
|
|
|
|
|
|
|
|
|
|
|
// 如果到了最后一层路径,设置值
|
|
|
|
// 如果到了最后一层路径,设置值
|
|
|
|
if (i == path.size() - 1) {
|
|
|
|
if (i == path.size() - 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (key.type() == QVariant::String)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if(key.type() == QVariant::String)
|
|
|
|
// 如果是路径
|
|
|
|
|
|
|
|
// 检查路径末尾是否存在
|
|
|
|
|
|
|
|
if(!current->IsObject())
|
|
|
|
|
|
|
|
current->SetObject();
|
|
|
|
|
|
|
|
if (current->HasMember(key.toString().toStdString().c_str()))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (value.type() == QVariant::Int)
|
|
|
|
|
|
|
|
(*current)[key.toString().toStdString().c_str()].SetInt(value.toInt()); // 如果存在则替换
|
|
|
|
|
|
|
|
if (value.type() == QVariant::Double)
|
|
|
|
|
|
|
|
(*current)[key.toString().toStdString().c_str()].SetDouble(value.toDouble()); // 如果存在则替换
|
|
|
|
|
|
|
|
if (value.type() == QVariant::String)
|
|
|
|
|
|
|
|
(*current)[key.toString().toStdString().c_str()].SetString(value.toString().toStdString().c_str(), allocator); // 如果存在则替换
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (value.type() == QVariant::Int)
|
|
|
|
|
|
|
|
(*current).AddMember(Value().SetString(key.toString().toStdString().c_str(), allocator), Value().SetInt(value.toInt()), allocator); // 不存在则添加
|
|
|
|
|
|
|
|
if (value.type() == QVariant::Double)
|
|
|
|
|
|
|
|
(*current).AddMember(Value().SetString(key.toString().toStdString().c_str(), allocator), Value().SetDouble(value.toDouble()), allocator); // 不存在则添加
|
|
|
|
|
|
|
|
if (value.type() == QVariant::String)
|
|
|
|
|
|
|
|
(*current).AddMember(Value().SetString(key.toString().toStdString().c_str(), allocator), Value().SetString(value.toString().toStdString().c_str(), allocator), allocator); // 不存在则添加
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (key.type() == QVariant::Int)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//如果是路径
|
|
|
|
// 如果是数组idx
|
|
|
|
// 检查路径末尾是否存在
|
|
|
|
int index = key.toInt();
|
|
|
|
if (current->HasMember(key.toString().toStdString().c_str())) {
|
|
|
|
if (!current->IsArray())
|
|
|
|
if(value.type() == QVariant::Int)
|
|
|
|
{
|
|
|
|
(*current)[key.toString().toStdString().c_str()].SetInt(value.toInt()); // 如果存在则替换
|
|
|
|
current->SetArray();
|
|
|
|
if(value.type() == QVariant::Double)
|
|
|
|
}
|
|
|
|
(*current)[key.toString().toStdString().c_str()].SetDouble(value.toDouble()); // 如果存在则替换
|
|
|
|
|
|
|
|
if(value.type() == QVariant::String)
|
|
|
|
|
|
|
|
(*current)[key.toString().toStdString().c_str()].SetString(value.toString().toStdString().c_str(),allocator); // 如果存在则替换
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(value.type() == QVariant::Int)
|
|
|
|
// 扩展数组以适应指定索引
|
|
|
|
current->AddMember(Value().SetString(key.toString().toStdString().c_str(), allocator), Value().SetInt(value.toInt()), allocator); // 不存在则添加
|
|
|
|
while (current->Size() <= index)
|
|
|
|
if(value.type() == QVariant::Double)
|
|
|
|
{
|
|
|
|
current->AddMember(Value().SetString(key.toString().toStdString().c_str(), allocator), Value().SetDouble(value.toDouble()), allocator); // 不存在则添加
|
|
|
|
rapidjson::Value object(rapidjson::kObjectType);
|
|
|
|
if(value.type() == QVariant::String)
|
|
|
|
current->PushBack(object, allocator);
|
|
|
|
current->AddMember(Value().SetString(key.toString().toStdString().c_str(), allocator), Value().SetString(value.toString().toStdString().c_str(),allocator), allocator); // 不存在则添加
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else if(key.type() == QVariant::Int){
|
|
|
|
|
|
|
|
//如果是数组idx
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置值
|
|
|
|
|
|
|
|
if (value.type() == QVariant::Int)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
(*current)[index].SetInt(value.toInt());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (value.type() == QVariant::Double)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
(*current)[index].SetDouble(value.toDouble());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (value.type() == QVariant::String)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
(*current)[index].SetString(value.toString().toStdString().c_str(), allocator);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (value.type() == QVariant::Bool)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
(*current)[index].SetBool(value.toBool());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (value.type() == QVariant::StringList)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Value jsonArray(kArrayType);
|
|
|
|
|
|
|
|
for (const QString &str : value.toStringList())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Value strVal;
|
|
|
|
|
|
|
|
strVal.SetString(str.toStdString().c_str(), allocator);
|
|
|
|
|
|
|
|
jsonArray.PushBack(strVal, allocator);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
(*current)[index] = jsonArray;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
if(key.type() == QVariant::String)
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (key.type() == QVariant::String)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//如果是路径
|
|
|
|
// 如果是路径
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否存在该路径,不存在则创建
|
|
|
|
// 检查是否存在该路径,不存在则创建
|
|
|
|
if (!current->HasMember(key.toString().toStdString().c_str())) {
|
|
|
|
if(!current->IsObject())
|
|
|
|
Value newObject(kObjectType); // 创建一个新的对象
|
|
|
|
current->SetObject();
|
|
|
|
|
|
|
|
if (!current->HasMember(key.toString().toStdString().c_str()))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Value newObject(kObjectType); // 创建一个新的对象
|
|
|
|
current->AddMember(Value().SetString(key.toString().toStdString().c_str(), allocator), newObject, allocator);
|
|
|
|
current->AddMember(Value().SetString(key.toString().toStdString().c_str(), allocator), newObject, allocator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 将 current 指向下一级
|
|
|
|
// 将 current 指向下一级
|
|
|
|
current = &(*current)[key.toString().toStdString().c_str()];
|
|
|
|
current = &(*current)[key.toString().toStdString().c_str()];
|
|
|
|
}else if(key.type() == QVariant::Int){
|
|
|
|
}
|
|
|
|
//如果是数组idx
|
|
|
|
else if (key.type() == QVariant::Int)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 如果是数组idx
|
|
|
|
|
|
|
|
int index = key.toInt();
|
|
|
|
|
|
|
|
if (!current->IsArray())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
current->SetArray();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while (current->Size() <= index)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
rapidjson::Value object(rapidjson::kObjectType);
|
|
|
|
|
|
|
|
(*current).PushBack(object, allocator);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
current = &(*current)[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|