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

209 lines
6.0 KiB
C++

3 weeks ago
#include "CUIConfig.h"
#include "CUISigsCenter.h"
3 weeks ago
#include <QDebug>
#include <QTimer>
#include "CUIDefine.h"
3 weeks ago
/**
* @brief CUIConfig::CUIConfig
* @param property
*/
CUIConfig::CUIConfig(QMap<QString, QVariant> property)
3 weeks ago
{
setDefault();
this->property = property;
this->m_sigsCenter = CUISigsCenter::getInstance();
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 :
*
* @subsection RadioButton
* - "name" :
*
3 weeks ago
* @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;
this->m_sigsCenter = CUISigsCenter::getInstance();
3 weeks ago
}
/**
* @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)
{
bool changed = false;
QVariant pValue = property["value_origin"];
if (property["value_type"] == CUI_DATA_TYPE_INT) {
int* ptr = qvariant_cast<int*>(pValue);
if (*ptr != value.toInt()) {
*ptr = value.toInt();
changed = true;
}
} else if (property["value_type"] == CUI_DATA_TYPE_DOUBLE) {
double* ptr = qvariant_cast<double*>(pValue);
if (*ptr != value.toDouble()) {
*ptr = value.toDouble();
changed = true;
}
} else if (property["value_type"] == CUI_DATA_TYPE_STRING) {
double* ptr = qvariant_cast<double*>(pValue);
if (*ptr != value.toDouble()) {
*ptr = value.toDouble();
changed = true;
}
}
// 如果需要通知,则通知参数值发生修改
if (changed && this->getPropertyOriginValue("semaphore") != QVariant::Invalid) {
QTimer::singleShot(50, m_sigsCenter, [ = ]() {
int semaphore = this->getPropertyOriginValue("semaphore").toInt();
emit m_sigsCenter->sig_cuiPropertyChanged(semaphore);
});
}
}
/**
* @brief CUIConfig::getPropertyValue
* @param key
* @return
*/
QString CUIConfig::getPropertyValue(QString key)
{
if(property.contains(key)) {
return qvariant_cast<QString>(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 = qvariant_cast<QString>(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_min", true); // 左范围是否包括
setDefault("inclusive_max", true); // 右范围是否包括
setDefault("required_", true); // 是否为必选
} 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
}