You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AppFlow/CFDStruct/CUIProperty/CUIConfig.cpp

165 lines
4.4 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "CUIConfig.h"
#include <QDebug>
#include "CFDStructDataManager/CFDStructDataDefine.h"
/**
* @brief CUIConfig::CUIConfig 构造函数
* @param property 组件的属性
*/
CUIConfig::CUIConfig(QMap<QString, QVariant> property)
{
setDefault();
this->property = property;
}
/**
* @brief CUIConfig::CUIConfig 构造函数
*
* @details {key:val},{CUIConfig*}
*
* map : 存当前组件的配置信息
*
* vector : 存当前组件的子组件的配置信息
*
* {"type",""}:类型选择可选Widget, GroupBox, LineEdit, TabWidget, ComboBox, Item, PushButton
*
* @subsection LineEdit 单行输入框
* - "name" (string) : 组件名称,显示与对应的label
* - "data_type" (string) : 组件处理的数据类型,可选"string" "int" "double"
* - "initial_value_" (string) : 初始值
* - "check_range_" ("true"/"false") : 是否有检查范围
* - "range_min_" (int/double) : 范围最小值,存储格式为string,自动转换为对应类型的值
* - "range_max_" (int/double) : 范围最大值,存储格式为string,自动转换为对应类型的值
* - "inclusive_" ("true"/"false") : 是否包含最大最小值
* - "required_" ("true"/"false") : 该组件信息是否必填
*
* @subsection Widget 小组件
* - "layout" (string):布局类型
* - "name" (string):组件名称,用于TabWidget对单个Tab进行命名
*
* @subsection GroupBox 组件组
* - "name" : 组名
* - "layout" : 布局名
* - sub : 子组件组
*
* @subsection TabWidget 标签页
* - sub : 子组件组,需有"name"属性作为标签名
*
* @subsection ComboBox 下拉框
* - "name" : 组件名称,与label中显示
* - sub : 子项目组,其"type"只能是"Item"
*
* @subsubsection Item 下拉框的项目
* - "name" : 项目名
* - "data_type" : 项目携带数据类型 "string"(default) "int" "double"
* - "data" : 项目携带数据
*
* @subsection PushButton 按钮
* - "name" : 按钮名
*
* @subsection CheckBox 正方形选择按钮
* - "name" : 组件名
*
* @subsection ButtonBox 单选组
* 继承groupbox配置buttongroup多选一
* - "name" : 组名
* - sub : 按钮
*
*
* @param property 组件的属性
* @param sub 该组件的子组件配置的列表
*/
CUIConfig::CUIConfig(QMap<QString, QVariant> property, QVector<CUIConfig *> sub)
{
setDefault();
this->property = property;
this->sub = sub;
}
/**
* @brief CUIConfig::printConfig 打印当前配置信息
*/
void CUIConfig::printConfig()
{
qDebug() << "{";
for(auto it = property.begin(); it != property.end(); it++) {
qDebug() << it.key() << ' ' << it.value();
}
for(auto it : sub) {
it->printConfig();
}
qDebug() << "}";
}
void CUIConfig::setValue(QVariant value)
{
// TODO
QVariant pValue = property["valueOrigin"];
if (property["valueType"] == "int") {
int* ptr = qvariant_cast<int*>(pValue);
*ptr = value.toInt();
}
}
QString CUIConfig::getPropertyValue(QString key)
{
if(property.contains(key)) {
return QVA_FROM_QS(property[key]);
}
return QString();
}
QVariant CUIConfig::getPropertyOriginValue(QString key)
{
if(property.contains(key)) {
return property[key];
}
return QVariant::Invalid;
}
/**
* @brief CUIConfig::setDefault 初始化属性
*/
void CUIConfig::setDefault()
{
QString type = QVA_FROM_QS(property["type"]);
if(type == "LineEdit") {
setDefault("name", "");
setDefault("data_type", "string"); //数据类型
setDefault("initial_value_", ""); //初始值
setDefault("check_range_", "false"); //是否检查范围
setDefault("range_min_", ""); //最小值
setDefault("range_max_", ""); //最大值
setDefault("inclusive_", "true"); //范围是否包括
setDefault("required_", "false"); //是否为必选
} else if(type == "Widget") {
setDefault("layout", "QVBoxLayout");
setDefault("name", "");
} else if(type == "GroupBox") {
setDefault("name", "");
setDefault("layout", "QVBoxLayout");
} else if(type == "TabWidget") {
} else if(type == "ComboBox") {
setDefault("name", "");
} else if(type == "Item") {
setDefault("name", "");
setDefault("data_type", "string");
setDefault("data", "");
}
}
/**
* @brief CUIConfig::setDefault 设置某项属性
* @param key
* @param val
*/
void CUIConfig::setDefault(QString key, QVariant val)
{
if(!property.contains(key)) {
property[key] = val;
}
}