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

186 lines
5.0 KiB
C++

3 weeks ago
#include "CUIConfig.h"
#include <QDebug>
#include "CFDStructDataManager/CFDStructDataDefine.h"
#include "CFDStructDataManager/CFDStructSigsCenter.h"
#include <QTimer>
3 weeks ago
/**
* @brief CUIConfig::CUIConfig
* @param property
*/
CUIConfig::CUIConfig(QMap<QString, QVariant> property)
3 weeks ago
{
setDefault();
this->property = property;
3 weeks ago
}
/**
* @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):,TabWidgetTab
*
* @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
* groupboxbuttongroup
* - "name" :
* - sub :
*
*
* @param property
* @param sub
*/
CUIConfig::CUIConfig(QMap<QString, QVariant> property, QVector<CUIConfig *> sub)
3 weeks ago
{
setDefault();
3 weeks ago
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) {
3 weeks ago
it->printConfig();
}
qDebug() << "}";
}
3 weeks ago
void CUIConfig::setValue(QVariant value)
{
// TODO
QVariant pValue = property["valueOrigin"];
if (property["valueType"] == "Int") {
int* ptr = qvariant_cast<int*>(pValue);
// if (*ptr != value.toInt()) {
*ptr = value.toInt();
// TODO通知参数值发生修改
QTimer::singleShot(200, CFDStructSigsCenter::getInstance(), &CFDStructSigsCenter::sig_solverTimeModeDataChanged);
// }
}
}
/**
* @brief CUIConfig::getPropertyValue
* @param key
* @return
*/
QString CUIConfig::getPropertyValue(QString key)
{
if(property.contains(key)) {
return QVA_FROM_QS(property[key]);
}
return QString();
}
/**
* @brief CUIConfig::getPropertyOriginValue
* @param key
* @return
*/
QVariant CUIConfig::getPropertyOriginValue(QString key)
{
if(property.contains(key)) {
return property[key];
}
return QVariant::Invalid;
3 weeks ago
}
QVector<CUIConfig *> CUIConfig::getSub()
{
return this->sub;
}
3 weeks ago
/**
* @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", "");
3 weeks ago
}
}
/**
* @brief CUIConfig::setDefault
* @param key
* @param val
*/
void CUIConfig::setDefault(QString key, QVariant val)
3 weeks ago
{
if(!property.contains(key)) {
3 weeks ago
property[key] = val;
}
3 weeks ago
}