|
|
|
@ -8,8 +8,7 @@
|
|
|
|
|
* @brief CUIConfig::CUIConfig 构造函数
|
|
|
|
|
* @param property 组件的属性
|
|
|
|
|
*/
|
|
|
|
|
CUIConfig::CUIConfig(QMap<QString, QVariant> property)
|
|
|
|
|
{
|
|
|
|
|
CUIConfig::CUIConfig(QMap<QString, QVariant> property) {
|
|
|
|
|
setDefault();
|
|
|
|
|
this->property = property;
|
|
|
|
|
this->m_sigsCenter = CUISigsCenter::getInstance();
|
|
|
|
@ -74,8 +73,7 @@ CUIConfig::CUIConfig(QMap<QString, QVariant> property)
|
|
|
|
|
* @param property 组件的属性
|
|
|
|
|
* @param sub 该组件的子组件配置的列表
|
|
|
|
|
*/
|
|
|
|
|
CUIConfig::CUIConfig(QMap<QString, QVariant> property, QVector<CUIConfig *> sub)
|
|
|
|
|
{
|
|
|
|
|
CUIConfig::CUIConfig(QMap<QString, QVariant> property, QVector<CUIConfig*> sub) {
|
|
|
|
|
setDefault();
|
|
|
|
|
this->property = property;
|
|
|
|
|
this->sub = sub;
|
|
|
|
@ -85,8 +83,7 @@ CUIConfig::CUIConfig(QMap<QString, QVariant> property, QVector<CUIConfig *> sub)
|
|
|
|
|
/**
|
|
|
|
|
* @brief CUIConfig::printConfig 打印当前配置信息
|
|
|
|
|
*/
|
|
|
|
|
void CUIConfig::printConfig()
|
|
|
|
|
{
|
|
|
|
|
void CUIConfig::printConfig() {
|
|
|
|
|
// qDebug() << "{";
|
|
|
|
|
// for(auto it = property.begin(); it != property.end(); it++) {
|
|
|
|
|
// qDebug() << it.key() << ' ' << it.value();
|
|
|
|
@ -97,29 +94,59 @@ void CUIConfig::printConfig()
|
|
|
|
|
// qDebug() << "}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CUIConfig::setValue(QVariant value)
|
|
|
|
|
{
|
|
|
|
|
QString CUIConfig::getOriginValueString() {
|
|
|
|
|
QVariant pValue = property["value_origin"];
|
|
|
|
|
|
|
|
|
|
// 如果没有设置原始值
|
|
|
|
|
if (pValue == QVariant::Invalid) {
|
|
|
|
|
return QString("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (property["value_type"] == CUI_DATA_TYPE_INT) {
|
|
|
|
|
int* ptr = qvariant_cast<int*>(pValue);
|
|
|
|
|
return QString::number(*ptr);
|
|
|
|
|
|
|
|
|
|
} else if (property["value_type"] == CUI_DATA_TYPE_DOUBLE) {
|
|
|
|
|
double* ptr = qvariant_cast<double*>(pValue);
|
|
|
|
|
return QString::number(*ptr);
|
|
|
|
|
|
|
|
|
|
} else if (property["value_type"] == CUI_DATA_TYPE_STRING) {
|
|
|
|
|
QString* ptr = qvariant_cast<QString*>(pValue);
|
|
|
|
|
return *ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QString("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
QString* ptr = qvariant_cast<QString*>(pValue);
|
|
|
|
|
|
|
|
|
|
if (*ptr != value.toString()) {
|
|
|
|
|
*ptr = value.toString();
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果需要通知,则通知参数值发生修改
|
|
|
|
|
if (changed && this->getPropertyOriginValue("semaphore") != QVariant::Invalid) {
|
|
|
|
|
QTimer::singleShot(50, m_sigsCenter, [ = ]() {
|
|
|
|
@ -134,11 +161,11 @@ void CUIConfig::setValue(QVariant value)
|
|
|
|
|
* @param key 属性名
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
QString CUIConfig::getPropertyValue(QString key)
|
|
|
|
|
{
|
|
|
|
|
if(property.contains(key)) {
|
|
|
|
|
QString CUIConfig::getPropertyValue(QString key) {
|
|
|
|
|
if (property.contains(key)) {
|
|
|
|
|
return qvariant_cast<QString>(property[key]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -147,16 +174,15 @@ QString CUIConfig::getPropertyValue(QString key)
|
|
|
|
|
* @param key 属性名
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
QVariant CUIConfig::getPropertyOriginValue(QString key)
|
|
|
|
|
{
|
|
|
|
|
if(property.contains(key)) {
|
|
|
|
|
QVariant CUIConfig::getPropertyOriginValue(QString key) {
|
|
|
|
|
if (property.contains(key)) {
|
|
|
|
|
return property[key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QVariant::Invalid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector<CUIConfig *> CUIConfig::getSub()
|
|
|
|
|
{
|
|
|
|
|
QVector<CUIConfig*> CUIConfig::getSub() {
|
|
|
|
|
return this->sub;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -164,10 +190,10 @@ QVector<CUIConfig *> CUIConfig::getSub()
|
|
|
|
|
/**
|
|
|
|
|
* @brief CUIConfig::setDefault 初始化属性
|
|
|
|
|
*/
|
|
|
|
|
void CUIConfig::setDefault()
|
|
|
|
|
{
|
|
|
|
|
void CUIConfig::setDefault() {
|
|
|
|
|
QString type = qvariant_cast<QString>(property["type"]);
|
|
|
|
|
if(type == "LineEdit") {
|
|
|
|
|
|
|
|
|
|
if (type == "LineEdit") {
|
|
|
|
|
setDefault("name", "");
|
|
|
|
|
setDefault("data_type", "string"); // 数据类型
|
|
|
|
|
setDefault("initial_value_", ""); // 初始值
|
|
|
|
@ -177,16 +203,20 @@ void CUIConfig::setDefault()
|
|
|
|
|
setDefault("inclusive_min", true); // 左范围是否包括
|
|
|
|
|
setDefault("inclusive_max", true); // 右范围是否包括
|
|
|
|
|
setDefault("required_", true); // 是否为必选
|
|
|
|
|
} else if(type == "Widget") {
|
|
|
|
|
|
|
|
|
|
} else if (type == "Widget") {
|
|
|
|
|
setDefault("layout", "QVBoxLayout");
|
|
|
|
|
setDefault("name", "");
|
|
|
|
|
} else if(type == "GroupBox") {
|
|
|
|
|
|
|
|
|
|
} else if (type == "GroupBox") {
|
|
|
|
|
setDefault("name", "");
|
|
|
|
|
setDefault("layout", "QVBoxLayout");
|
|
|
|
|
} else if(type == "TabWidget") {
|
|
|
|
|
} else if(type == "ComboBox") {
|
|
|
|
|
|
|
|
|
|
} else if (type == "TabWidget") {
|
|
|
|
|
} else if (type == "ComboBox") {
|
|
|
|
|
setDefault("name", "");
|
|
|
|
|
} else if(type == "Item") {
|
|
|
|
|
|
|
|
|
|
} else if (type == "Item") {
|
|
|
|
|
setDefault("name", "");
|
|
|
|
|
setDefault("data_type", "string");
|
|
|
|
|
setDefault("data", "");
|
|
|
|
@ -199,9 +229,8 @@ void CUIConfig::setDefault()
|
|
|
|
|
* @param key
|
|
|
|
|
* @param val
|
|
|
|
|
*/
|
|
|
|
|
void CUIConfig::setDefault(QString key, QVariant val)
|
|
|
|
|
{
|
|
|
|
|
if(!property.contains(key)) {
|
|
|
|
|
void CUIConfig::setDefault(QString key, QVariant val) {
|
|
|
|
|
if (!property.contains(key)) {
|
|
|
|
|
property[key] = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|