|
|
|
|
#include "CUIConfig.h"
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief CUIConfig::CUIConfig 构造函数
|
|
|
|
|
* @param property 组件的属性
|
|
|
|
|
*/
|
|
|
|
|
CUIConfig::CUIConfig(QMap<QString, QString> property)
|
|
|
|
|
{
|
|
|
|
|
this->property = property;
|
|
|
|
|
|
|
|
|
|
setDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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, QString> property, QVector<CUIConfig *> sub)
|
|
|
|
|
{
|
|
|
|
|
this->property = property;
|
|
|
|
|
this->sub = sub;
|
|
|
|
|
|
|
|
|
|
setDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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()<<"}";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief CUIConfig::setDefault 初始化属性
|
|
|
|
|
*/
|
|
|
|
|
void CUIConfig::setDefault()
|
|
|
|
|
{
|
|
|
|
|
if(property["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");//是否为必选
|
|
|
|
|
}
|
|
|
|
|
if(property["type"] == "Widget"){
|
|
|
|
|
setDefault("layout","QVBoxLayout");
|
|
|
|
|
setDefault("name","");
|
|
|
|
|
}
|
|
|
|
|
if(property["type"] == "GroupBox"){
|
|
|
|
|
setDefault("name","");
|
|
|
|
|
setDefault("layout","QVBoxLayout");
|
|
|
|
|
}
|
|
|
|
|
if(property["type"] == "TabWidget"){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if(property["type"] == "ComboBox"){
|
|
|
|
|
setDefault("name","");
|
|
|
|
|
}
|
|
|
|
|
if(property["type"] == "Item"){
|
|
|
|
|
setDefault("name","");
|
|
|
|
|
setDefault("data_type","string");
|
|
|
|
|
setDefault("data","");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief CUIConfig::setDefault 设置某项属性
|
|
|
|
|
* @param key
|
|
|
|
|
* @param val
|
|
|
|
|
*/
|
|
|
|
|
void CUIConfig::setDefault(QString key, QString val)
|
|
|
|
|
{
|
|
|
|
|
if(!property.contains(key))
|
|
|
|
|
property[key] = val;
|
|
|
|
|
}
|
|
|
|
|
|