1、ui界面上把粘性模型修改成根据时间模式展示

feature/struct-menu-20241023
mzh 3 days ago
parent a4c77fe195
commit f2a804dd35

@ -21,7 +21,8 @@ class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataManagerBase : public QObject {
virtual void saveDataToDom(rapidjson::Document &dom) = 0;
// 将数据从dom中读出
virtual void readDataFromDom(rapidjson::Document &dom) = 0;
signals:
signals:
protected:
CUIConfig *m_uiConfig = nullptr;

@ -1,10 +1,12 @@
#include "CFDStructDataSolverKvislManager.h"
#include "CFDStructDataManager.h"
#include "CFDStructMain/CFDStructDefine.h"
#include "CFDStructSigsCenter.h"
#include "CUIProperty/CUIConfig.h"
CFDStructDataSolverKvislManager::CFDStructDataSolverKvislManager(QObject *parent) : CFDStructDataManagerBase(parent) {
m_uiConfig = nullptr;
connect(m_cuiSigsCenter, &CUISigsCenter::sig_cuiPropertyChanged, this, [=](int semaphore) {
if (semaphore == (int)SolutionAnalysisModuleProperty::Viscosity_Model) {
emit CFDStructSigsCenter::getInstance()->sig_solverKvislDataChanged();
@ -15,40 +17,63 @@ CFDStructDataSolverKvislManager::~CFDStructDataSolverKvislManager() {
}
CUIConfig *CFDStructDataSolverKvislManager::getParamUIConfig() {
if (m_Model == 0) {
return genInviscidUIConfig();
}
if (m_Model == 1) {
return genLaminarUIConfig();
}
if (m_Model == 2) {
if (m_RNSModel == 0)
m_runTime = CFDStructDataManager::getInstance()->getTimeModeRunTime();
qDebug() << m_runTime << "runtime";
if (m_runTime == 1) {
if (m_Model == 0) {
return genInviscidUIConfig();
}
if (m_Model == 1) {
return genLaminarUIConfig();
}
if (m_Model == 2) {
if (m_RNSModel == 0)
return genRANSSAUIConfig();
if (m_RNSModel == 1)
return genRANSUIMentersConfig();
if (m_RNSModel == 2)
return genRANSKEUIConfig();
return genRANSSAUIConfig();
if (m_RNSModel == 1)
return genRANSUIMentersConfig();
if (m_RNSModel == 2)
return genRANSKEUIConfig();
return genRANSSAUIConfig();
}
if (m_Model == 3) {
m_SAType = 0;
if (m_RNSModel == 0)
}
if (m_Model == 3) {
m_SAType = 0;
if (m_RNSModel == 0)
return genDESSAUIConfig();
if (m_RNSModel == 1)
return genDESMentersUIConfig();
if (m_RNSModel == 2)
m_RNSModel = 0;
return genDESSAUIConfig();
if (m_RNSModel == 1)
return genDESMentersUIConfig();
if (m_RNSModel == 2)
m_RNSModel = 0;
return genDESSAUIConfig();
}
if (m_Model == 4) {
m_SAType = 0;
if (m_RNSModel == 0)
}
if (m_Model == 4) {
m_SAType = 0;
if (m_RNSModel == 0)
return genCLESUIConfig();
if (m_RNSModel == 1)
return genCLESMentersUIConfig();
if (m_RNSModel == 2)
m_RNSModel = 0;
return genCLESUIConfig();
if (m_RNSModel == 1)
return genCLESMentersUIConfig();
if (m_RNSModel == 2)
m_RNSModel = 0;
return genCLESUIConfig();
}
} else if (m_runTime == 0) {
if (m_Model == 0) {
return genSteadyInviscidUIConfig();
}
if (m_Model == 1) {
return genSteadyLaminarUIConfig();
}
if (m_Model == 2) {
if (m_RNSModel == 0)
return genSteadyRANSSAUIConfig();
if (m_RNSModel == 1)
return genSteadyRANSUIMentersConfig();
if (m_RNSModel == 2)
return genSteadyRANSKEUIConfig();
return genRANSSAUIConfig();
} else {
m_Model = 0;
return genSteadyInviscidUIConfig();
}
}
return this->genInviscidUIConfig();
}
@ -597,3 +622,196 @@ CUIConfig *CFDStructDataSolverKvislManager::genCLESMentersUIConfig() {
});
return nullptr;
}
CUIConfig *CFDStructDataSolverKvislManager::genSteadyInviscidUIConfig() {
return new CUIConfig(
{{"type", "Widget"}}, {
new CUIConfig({
{"type", "RadioComponent"}, // 组:模型
{"name", tr("Model")},
{"widget", "GroupBox"},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_Model)},
{"semaphore", (int)SolutionAnalysisModuleProperty::Viscosity_Model},
},
{
new CUIConfig({{"type", "RadioButton"}, // 按钮:无粘
{"name", tr("Inviscid")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:层流
{"name", tr("Laminar")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:雷诺平均
{"name", tr("RANS")}}),
}),
});
return nullptr;
}
CUIConfig *CFDStructDataSolverKvislManager::genSteadyLaminarUIConfig() {
return new CUIConfig(
{{"type", "Widget"}}, {new CUIConfig({
{"type", "RadioComponent"}, // 组:模型
{"name", tr("Model")},
{"widget", "GroupBox"},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_Model)},
{"semaphore", (int)SolutionAnalysisModuleProperty::Viscosity_Model},
},
{
new CUIConfig({{"type", "RadioButton"}, // 按钮:无粘
{"name", tr("Inviscid")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:层流
{"name", tr("Laminar")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:雷诺平均
{"name", tr("RANS")}}),
})});
return nullptr;
}
CUIConfig *CFDStructDataSolverKvislManager::genSteadyRANSSAUIConfig() {
return new CUIConfig(
{{"type", "Widget"}}, {
new CUIConfig({
{"type", "RadioComponent"}, // 组:模型
{"name", tr("Model")},
{"widget", "GroupBox"},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_Model)},
{"semaphore", (int)SolutionAnalysisModuleProperty::Viscosity_Model},
},
{
new CUIConfig({{"type", "RadioButton"}, // 按钮:无粘
{"name", tr("Inviscid")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:层流
{"name", tr("Laminar")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:雷诺平均
{"name", tr("RANS")}}),
}),
new CUIConfig({
{"type", "RadioComponent"}, // 组:RANS模型
{"name", tr("RANS Model")},
{"widget", "GroupBox"},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_RNSModel)},
{"semaphore", (int)SolutionAnalysisModuleProperty::Viscosity_Model},
},
{new CUIConfig({{"type", "RadioButton"}, // 按钮:S-A(一方程)
{"name", tr("S-A")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:Menters's κ-ω(两方程)
{"name", tr("Menters's κ-ω")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:κ-ε(两方程)
{"name", tr("κ-ε")}})}),
new CUIConfig({
{"type", "RadioComponent"}, // 组:S-A类型
{"name", tr("S-A Type")},
{"widget", "GroupBox"},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_SAType)},
{"semaphore", (int)SolutionAnalysisModuleProperty::Viscosity_Model},
},
{new CUIConfig({{"type", "RadioButton"}, // 按钮:standard
{"name", tr("standard")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:Edwards
{"name", tr("Edwards")}})}),
});
return nullptr;
}
CUIConfig *CFDStructDataSolverKvislManager::genSteadyRANSUIMentersConfig() {
return new CUIConfig(
{{"type", "Widget"}}, {
new CUIConfig({
{"type", "RadioComponent"}, // 组:模型
{"name", tr("Model")},
{"widget", "GroupBox"},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_Model)},
{"semaphore", (int)SolutionAnalysisModuleProperty::Viscosity_Model},
},
{
new CUIConfig({{"type", "RadioButton"}, // 按钮:无粘
{"name", tr("Inviscid")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:层流
{"name", tr("Laminar")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:雷诺平均
{"name", tr("RANS")}}),
}),
new CUIConfig({
{"type", "RadioComponent"}, // 组:RANS模型
{"name", tr("RANS Model")},
{"widget", "GroupBox"},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_RNSModel)},
{"semaphore", (int)SolutionAnalysisModuleProperty::Viscosity_Model},
},
{new CUIConfig({{"type", "RadioButton"}, // 按钮:S-A(一方程)
{"name", tr("S-A")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:Menters's κ-ω(两方程)
{"name", tr("Menters's κ-ω")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:κ-ε(两方程)
{"name", tr("κ-ε")}})}),
new CUIConfig({
{"type", "RadioComponent"}, // 组:κ-ω类型
{"name", tr("κ-ω Type")},
{"widget", "GroupBox"},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_kwType)},
{"semaphore", (int)SolutionAnalysisModuleProperty::Viscosity_Model},
},
{
new CUIConfig({{"type", "RadioButton"}, // 按钮:standard
{"name", tr("standard")}}),
}),
});
return nullptr;
}
CUIConfig *CFDStructDataSolverKvislManager::genSteadyRANSKEUIConfig() {
return new CUIConfig(
{{"type", "Widget"}}, {
new CUIConfig({
{"type", "RadioComponent"}, // 组:模型
{"name", tr("Model")},
{"widget", "GroupBox"},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_Model)},
{"semaphore", (int)SolutionAnalysisModuleProperty::Viscosity_Model},
},
{
new CUIConfig({{"type", "RadioButton"}, // 按钮:无粘
{"name", tr("Inviscid")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:层流
{"name", tr("Laminar")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:雷诺平均
{"name", tr("RANS")}}),
}),
new CUIConfig({
{"type", "RadioComponent"}, // 组:RANS模型
{"name", tr("RANS Model")},
{"widget", "GroupBox"},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_RNSModel)},
{"semaphore", (int)SolutionAnalysisModuleProperty::Viscosity_Model},
},
{new CUIConfig({{"type", "RadioButton"}, // 按钮:S-A(一方程)
{"name", tr("S-A")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:Menters's κ-ω(两方程)
{"name", tr("Menters's κ-ω")}}),
new CUIConfig({{"type", "RadioButton"}, // 按钮:κ-ε(两方程)
{"name", tr("κ-ε")}})}),
new CUIConfig({
{"type", "RadioComponent"}, // 组:κ-ε类型
{"name", tr("κ-ε Type")},
{"widget", "GroupBox"},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_keType)},
{"semaphore", (int)SolutionAnalysisModuleProperty::Viscosity_Model},
},
{
new CUIConfig({{"type", "RadioButton"}, // 按钮:standard
{"name", tr("standard")}}),
}),
});
return nullptr;
}

@ -5,71 +5,86 @@
#ifndef CFDSTRUCTDATASOLVERKVISLLMANAGER_H
#define CFDSTRUCTDATASOLVERKVISLLMANAGER_H
#include <QObject>
#include "CFDStructDataManager_global.h"
#include "CFDStructDataManagerBase.h"
#include "CFDStructDataManager_global.h"
#include <QObject>
class CUIConfig;
class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverKvislManager : public CFDStructDataManagerBase
{
class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverKvislManager : public CFDStructDataManagerBase {
Q_OBJECT
public:
public:
explicit CFDStructDataSolverKvislManager(QObject *parent = nullptr);
~CFDStructDataSolverKvislManager();
CUIConfig* getParamUIConfig();
CUIConfig *getParamUIConfig();
void saveDataToDom(rapidjson::Document &dom);
void readDataFromDom(rapidjson::Document &dom);
private:
// ----------------------------这里是生成非定常选项的界面---------------------
// 生成无粘界面配置
CUIConfig* genInviscidUIConfig();
CUIConfig *genInviscidUIConfig();
// 生成层流界面配置
CUIConfig* genLaminarUIConfig();
CUIConfig *genLaminarUIConfig();
// 生成雷诺平均_S-A界面配置
CUIConfig* genRANSSAUIConfig();
CUIConfig *genRANSSAUIConfig();
// 生成雷诺平均_Menters's κ-ω界面配置
CUIConfig* genRANSUIMentersConfig();
CUIConfig *genRANSUIMentersConfig();
// 生成雷诺平均_κ-ε界面配置
CUIConfig* genRANSKEUIConfig();
CUIConfig *genRANSKEUIConfig();
// 生成分离涡模拟_S-A界面配置
CUIConfig* genDESSAUIConfig();
CUIConfig *genDESSAUIConfig();
// 生成分离涡模拟_Menters's κ-ω界面配置
CUIConfig* genDESMentersUIConfig();
CUIConfig *genDESMentersUIConfig();
// 生成约束大涡模拟_S-A界面配置
CUIConfig* genCLESUIConfig();
CUIConfig *genCLESUIConfig();
// 生成约束大涡模拟_Menters's κ-ω界面配置
CUIConfig* genCLESMentersUIConfig();
signals:
CUIConfig *genCLESMentersUIConfig();
// ----------------------------这里是生成定常选项的界面---------------------
// 生成无粘界面配置
CUIConfig *genSteadyInviscidUIConfig();
private:
// 生成层流界面配置
CUIConfig *genSteadyLaminarUIConfig();
//模型:0_无粘;1_层流;2_雷诺平均;3_分离涡模拟;4_约束大涡模拟;
// 生成雷诺平均_S-A界面配置
CUIConfig *genSteadyRANSSAUIConfig();
// 生成雷诺平均_Menters's κ-ω界面配置
CUIConfig *genSteadyRANSUIMentersConfig();
// 生成雷诺平均_κ-ε界面配置
CUIConfig *genSteadyRANSKEUIConfig();
signals:
private:
// 时间模式 定常、非定常
int m_runTime = 0;
// 模型:0_无粘;1_层流;2_雷诺平均;3_分离涡模拟;4_约束大涡模拟;
int m_Model = 0;
//RNS模型:0_S-A一方程;1_Menters's κ-ω(两方程);2_κ-ε(两方程);
// RNS模型:0_S-A一方程;1_Menters's κ-ω(两方程);2_κ-ε(两方程);
int m_RNSModel = 0;
//S-A类型:0_standard;1_Edwards
// S-A类型:0_standard;1_Edwards
int m_SAType = 0;
//κ-ω类型:0_standard
// κ-ω类型:0_standard
int m_kwType = 0;
//κ-ε类型:0_standard
// κ-ε类型:0_standard
int m_keType = 0;
//DES模型:0_DES;1_DDES;2_IDDES
// DES模型:0_DES;1_DDES;2_IDDES
int m_DESModel = 0;
CUIConfig* m_uiConfig = nullptr;
CUIConfig *m_uiConfig = nullptr;
};
#endif // CFDSTRUCTDATASOLVERKvislLMANAGER_H

@ -12,6 +12,7 @@
CFDStructDataSolverTimeModeManager::CFDStructDataSolverTimeModeManager(QObject *parent) : CFDStructDataManagerBase(parent) {
m_uiConfig = nullptr;
// qDebug() << "build timemode manager";
connect(m_cuiSigsCenter, &CUISigsCenter::sig_cuiPropertyChanged, this, [=](int semaphore) {
emit CFDStructSigsCenter::getInstance() -> sig_solverModuleProperty((SolutionAnalysisModuleProperty)semaphore);
});
@ -148,5 +149,4 @@ CUIConfig *CFDStructDataSolverTimeModeManager::genUnsteadyModeUIConfig() {
int CFDStructDataSolverTimeModeManager::getRunType() {
return m_runtype;
return 0;
}

@ -42,7 +42,7 @@ class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverTimeModeManager : public CF
// 时均统计量数据采样0 | 1
int m_timeaverage = 0;
public:
public:
int getRunType();
};

@ -1,57 +1,55 @@
#include "CUIComponentBase.h"
CUIComponentBase::CUIComponentBase()
{
CUIComponentBase::CUIComponentBase() {
this->initSetting();
}
void CUIComponentBase::initSetting()
{
void CUIComponentBase::initSetting() {
if (!m_conf) {
return;
}
m_dataType = (CUI_DATA_TYPE)m_conf->getPropertyOriginValue("value_type").toInt();
qDebug()<<"------";
qDebug()<<m_dataType;
qDebug()<<static_cast<CUI_DATA_TYPE>(m_conf->getPropertyOriginValue("value_type").toInt());
qDebug()<<"++++++";
if(m_conf->getPropertyOriginValue("initial_value") != QVariant::Invalid) {
qDebug() << "------";
qDebug() << m_dataType;
qDebug() << static_cast<CUI_DATA_TYPE>(m_conf->getPropertyOriginValue("value_type").toInt());
qDebug() << "++++++";
if (m_conf->getPropertyOriginValue("initial_value") != QVariant::Invalid) {
m_value = m_conf->getPropertyOriginValue("initial_value");
}
// 初始化是否必填
if(m_conf->getPropertyOriginValue("required") != QVariant::Invalid) {
if (m_conf->getPropertyOriginValue("required") != QVariant::Invalid) {
m_required = m_conf->getPropertyOriginValue("required").toBool();
}
if(m_dataType == CUI_DATA_TYPE_STRING) {
if (m_dataType == CUI_DATA_TYPE_STRING) {
m_checkRange = false;
return;
}
// 是否检查范围
if(m_conf->getPropertyOriginValue("check_range") != QVariant::Invalid) {
if (m_conf->getPropertyOriginValue("check_range") != QVariant::Invalid) {
m_checkRange = m_conf->getPropertyOriginValue("check_range").toBool();
}
// 左值和右值是否包含
if(m_conf->getPropertyOriginValue("inclusive_min") != QVariant::Invalid) {
if (m_conf->getPropertyOriginValue("inclusive_min") != QVariant::Invalid) {
m_inclusiveMin = m_conf->getPropertyOriginValue("inclusive_min").toBool();
}
if(m_conf->getPropertyOriginValue("inclusive_max") != QVariant::Invalid) {
if (m_conf->getPropertyOriginValue("inclusive_max") != QVariant::Invalid) {
m_inclusiveMax = m_conf->getPropertyOriginValue("inclusive_max").toBool();
}
// 初始化左值和右值
if (m_checkRange) {
if(m_conf->getPropertyOriginValue("range_min") != QVariant::Invalid) {
if (m_conf->getPropertyOriginValue("range_min") != QVariant::Invalid) {
m_rangeMin = m_conf->getPropertyOriginValue("range_min");
} else {
if (m_dataType == CUI_DATA_TYPE_INT) {
m_rangeMin = INT_MIN;
} else if (m_dataType == CUI_DATA_TYPE_DOUBLE) {
m_rangeMin = -1*DBL_MAX;
m_rangeMin = -1 * DBL_MAX;
}
}
if(m_conf->getPropertyOriginValue("range_max") != QVariant::Invalid) {
if (m_conf->getPropertyOriginValue("range_max") != QVariant::Invalid) {
m_rangeMax = m_conf->getPropertyOriginValue("range_max");
} else {
qDebug()<<"Base init min";
qDebug() << "Base init min";
if (m_dataType == CUI_DATA_TYPE_INT) {
m_rangeMax = INT_MAX;
} else if (m_dataType == CUI_DATA_TYPE_DOUBLE) {
@ -61,106 +59,97 @@ void CUIComponentBase::initSetting()
}
}
bool CUIComponentBase::inRange(QVariant v)
{
if(m_checkRange) {
bool CUIComponentBase::inRange(QVariant v) {
if (m_checkRange) {
// 如果包含最小值,但是修改后的值小于最小值,则不在范围内
if (m_inclusiveMin && v < m_rangeMin ) {
if (m_inclusiveMin && v < m_rangeMin) {
return false;
}
// 如果不包含最小值,但是修改后的值小于等于最小值,则不在范围内
if (!m_inclusiveMin && v <= m_rangeMin ) {
if (!m_inclusiveMin && v <= m_rangeMin) {
return false;
}
// 如果包含最大值,但是修改后的值大于最大值,则不在范围内
if (m_inclusiveMax && v > m_rangeMax ) {
if (m_inclusiveMax && v > m_rangeMax) {
return false;
}
// 如果不包含最大值,但是修改后的值大于等于最大值,则不在范围内
if (!m_inclusiveMax && v >= m_rangeMax ) {
if (!m_inclusiveMax && v >= m_rangeMax) {
return false;
}
}
return true;
}
QVariant CUIComponentBase::getQVFrom(QString str)
{
QVariant CUIComponentBase::getQVFrom(QString str) {
QVariant v;
switch (m_dataType) {
case CUI_DATA_TYPE_DOUBLE: {
case CUI_DATA_TYPE_DOUBLE: {
v = qvariant_cast<double>(str.toDouble());
break;
}
case CUI_DATA_TYPE_INT: {
// qDebug()<< qvariant_cast<int>(m_lineEdit->text().toInt());
v = qvariant_cast<int>(str.toInt());
break;
}
case CUI_DATA_TYPE_STRING: {
v = str;
break;
}
break;
}
case CUI_DATA_TYPE_INT: {
// qDebug()<< qvariant_cast<int>(m_lineEdit->text().toInt());
v = qvariant_cast<int>(str.toInt());
break;
}
case CUI_DATA_TYPE_STRING: {
v = str;
break;
}
}
return v;
}
void CUIComponentBase::initUI()
{
void CUIComponentBase::initUI() {
}
void CUIComponentBase::initValidator()
{
void CUIComponentBase::initValidator() {
}
QString CUIComponentBase::getValueString()
{
if(m_dataType == CUI_DATA_TYPE_STRING) {
QString CUIComponentBase::getValueString() {
if (m_dataType == CUI_DATA_TYPE_STRING) {
return m_value.toString();
}
if(m_dataType == CUI_DATA_TYPE_INT) {
if (m_dataType == CUI_DATA_TYPE_INT) {
return QString::number(m_value.toInt());
}
if(m_dataType == CUI_DATA_TYPE_DOUBLE) {
if (m_dataType == CUI_DATA_TYPE_DOUBLE) {
return QString::number(m_value.toDouble());
}
return QString("");
}
QString CUIComponentBase::getRangeMinString()
{
if(m_dataType == CUI_DATA_TYPE_STRING) {
QString CUIComponentBase::getRangeMinString() {
if (m_dataType == CUI_DATA_TYPE_STRING) {
return m_rangeMin.toString();
}
if(m_dataType == CUI_DATA_TYPE_INT) {
if (m_dataType == CUI_DATA_TYPE_INT) {
return QString::number(m_rangeMin.toInt());
}
if(m_dataType == CUI_DATA_TYPE_DOUBLE) {
if (m_dataType == CUI_DATA_TYPE_DOUBLE) {
return QString::number(m_rangeMin.toDouble());
}
return QString("");
}
QString CUIComponentBase::getRangeMaxString()
{
if(m_dataType == CUI_DATA_TYPE_STRING) {
QString CUIComponentBase::getRangeMaxString() {
if (m_dataType == CUI_DATA_TYPE_STRING) {
return m_rangeMax.toString();
}
if(m_dataType == CUI_DATA_TYPE_INT) {
if (m_dataType == CUI_DATA_TYPE_INT) {
return QString::number(m_rangeMax.toInt());
}
if(m_dataType == CUI_DATA_TYPE_DOUBLE) {
if (m_dataType == CUI_DATA_TYPE_DOUBLE) {
return QString::number(m_rangeMax.toDouble());
}
return QString("");
}
void CUIComponentBase::setValueToOrigin()
{
void CUIComponentBase::setValueToOrigin() {
if (m_conf) {
qDebug() << "conf setValue" << m_value;
m_conf->setValue(m_value);
}
}

@ -14,10 +14,9 @@
* @param parent
*/
CUIComponentComboBox::CUIComponentComboBox(CUIConfig *conf,
QVector<CUIPropertyWidget *> &subCUI,
QWidget *parent)
: CUIComponentBaseWidget(parent)
{
QVector<CUIPropertyWidget *> &subCUI,
QWidget *parent)
: CUIComponentBaseWidget(parent) {
this->m_conf = conf;
initUI(subCUI);
}
@ -26,8 +25,7 @@ CUIComponentComboBox::CUIComponentComboBox(CUIConfig *conf,
* @brief CUIComponentComboBox::getLabelWidth comboboxlabel
* @return label
*/
qint32 CUIComponentComboBox::getLabelWidth()
{
qint32 CUIComponentComboBox::getLabelWidth() {
return m_label->minimumSizeHint().width();
}
@ -35,16 +33,14 @@ qint32 CUIComponentComboBox::getLabelWidth()
* @brief CUIComponentComboBox::setLabelWidth label
* @param width
*/
void CUIComponentComboBox::setLabelWidth(qint32 width)
{
void CUIComponentComboBox::setLabelWidth(qint32 width) {
m_label->setMinimumWidth(width);
}
/**
* @brief CUIComponentComboBox::initUI widget,labelcomboBox
*/
void CUIComponentComboBox::initUI(QVector<CUIPropertyWidget *> &subCUI)
{
void CUIComponentComboBox::initUI(QVector<CUIPropertyWidget *> &subCUI) {
m_label = new QLabel(m_conf->getPropertyValue("name"));
m_label->setFixedWidth(m_labelLength);
m_comboBox = new QComboBox;
@ -55,16 +51,15 @@ void CUIComponentComboBox::initUI(QVector<CUIPropertyWidget *> &subCUI)
((QHBoxLayout *)m_layout)->setStretchFactor(m_comboBox, 1);
iniComoboBox();
connect(m_comboBox, QOverload<int>::of(&QComboBox::activated),
[ = ](int idx) {
this->m_conf->setValue(idx);
});
[=](int idx) {
this->m_conf->setValue(idx);
});
}
/**
* @brief CUIComponentComboBox::iniComoboBox ComboBox
*/
void CUIComponentComboBox::iniComoboBox()
{
void CUIComponentComboBox::iniComoboBox() {
for (auto cui : m_conf->getSub()) {
QString type = cui->getPropertyValue("type");
if (type != "Item") {

@ -15,10 +15,9 @@
* @param parent
*/
CUIComponentLineEdit::CUIComponentLineEdit(CUIConfig *conf,
QVector<CUIPropertyWidget *> &subCUI,
QWidget *parent)
: CUIComponentBaseWidget(parent),CUIComponentBase()
{
QVector<CUIPropertyWidget *> &subCUI,
QWidget *parent)
: CUIComponentBaseWidget(parent), CUIComponentBase() {
this->m_conf = conf;
this->initSetting();
this->initUI(subCUI);
@ -28,8 +27,7 @@ CUIComponentLineEdit::CUIComponentLineEdit(CUIConfig *conf,
* @brief CUIComponentLineEdit::getLabelWidth label
* @return label
*/
qint32 CUIComponentLineEdit::getLabelWidth()
{
qint32 CUIComponentLineEdit::getLabelWidth() {
return m_label->minimumSizeHint().width();
}
@ -37,23 +35,21 @@ qint32 CUIComponentLineEdit::getLabelWidth()
* @brief CUIComponentLineEdit::setLabelWidth label
* @param width
*/
void CUIComponentLineEdit::setLabelWidth(qint32 width)
{
void CUIComponentLineEdit::setLabelWidth(qint32 width) {
m_label->setMinimumWidth(width);
}
/**
* @brief CUIComponentLineEdit::initUI
*/
void CUIComponentLineEdit::initUI(QVector<CUIPropertyWidget *> &subCUI)
{
void CUIComponentLineEdit::initUI(QVector<CUIPropertyWidget *> &subCUI) {
m_layout = new QHBoxLayout();
m_label = new QLabel(m_conf->getPropertyValue("name"));
m_label->setFixedWidth(m_labelLength);
m_lineEdit = new QLineEdit(this->getValueString());
m_layout->addWidget(m_label);
m_layout->addWidget(m_lineEdit);
// m_dataType = static_cast<CUI_DATA_TYPE>(this->m_conf->getPropertyOriginValue("data_type").toInt());
// m_dataType = static_cast<CUI_DATA_TYPE>(this->m_conf->getPropertyOriginValue("data_type").toInt());
this->setLayout(m_layout);
// 设置格式校验
this->setValidator();
@ -62,30 +58,28 @@ void CUIComponentLineEdit::initUI(QVector<CUIPropertyWidget *> &subCUI)
&CUIComponentLineEdit::onTextChanged);
}
void CUIComponentLineEdit::setValidator()
{
qDebug()<<m_dataType;
void CUIComponentLineEdit::setValidator() {
qDebug() << m_dataType;
switch ((int)m_dataType) {
case CUI_DATA_TYPE_DOUBLE: {
qDebug()<<m_rangeMin.toInt()<<' '<< m_rangeMax.toInt();
m_lineEdit->setValidator(new QDoubleValidator(m_rangeMin.toDouble(),
m_rangeMax.toDouble(), 10));
break;
}
case CUI_DATA_TYPE_INT: {
qDebug()<<m_rangeMin.toInt()<<' '<< m_rangeMax.toInt();
m_lineEdit->setValidator(
new QIntValidator(m_rangeMin.toInt(), m_rangeMax.toInt()));
break;
}
case CUI_DATA_TYPE_DOUBLE: {
qDebug() << m_rangeMin.toInt() << ' ' << m_rangeMax.toInt();
m_lineEdit->setValidator(new QDoubleValidator(m_rangeMin.toDouble(),
m_rangeMax.toDouble(), 10));
break;
}
case CUI_DATA_TYPE_INT: {
qDebug() << m_rangeMin.toInt() << ' ' << m_rangeMax.toInt();
m_lineEdit->setValidator(
new QIntValidator(m_rangeMin.toInt(), m_rangeMax.toInt()));
break;
}
}
}
/**
* @brief CUIComponentLineEdit::showMsg
*/
void CUIComponentLineEdit::setInputTips()
{
void CUIComponentLineEdit::setInputTips() {
QString msg = "";
if (m_checkRange) {
msg += m_inclusiveMin ? "[" : "(";
@ -101,8 +95,7 @@ void CUIComponentLineEdit::setInputTips()
/**
* @brief CUIComponentLineEdit::checkRange
*/
void CUIComponentLineEdit::showRangeError()
{
void CUIComponentLineEdit::showRangeError() {
if (m_checkRange) {
QPalette palette = m_lineEdit->palette();
if (this->inRange(this->getQVFrom(m_lineEdit->text()))) {
@ -122,26 +115,28 @@ void CUIComponentLineEdit::showRangeError()
*
* @param text
*/
void CUIComponentLineEdit::onTextChanged(const QString &text)
{
void CUIComponentLineEdit::onTextChanged(const QString &text) {
this->showRangeError();
// 如果在范围内,
if (this->inRange(m_lineEdit->text())) {
// switch (m_dataType) {
// case CUI_DATA_TYPE_DOUBLE: {
// m_value = qvariant_cast<double>(m_lineEdit->text().toDouble());
// break;
// }
// case CUI_DATA_TYPE_INT: {
//// qDebug()<< qvariant_cast<int>(m_lineEdit->text().toInt());
// m_value = qvariant_cast<int>(m_lineEdit->text().toInt());
// break;
// }
// case CUI_DATA_TYPE_STRING: {
// m_value = m_lineEdit->text();
// break;
// }
// }
// switch (m_dataType) {
// case CUI_DATA_TYPE_DOUBLE: {
// m_value = qvariant_cast<double>(m_lineEdit->text().toDouble());
// break;
// }
// case CUI_DATA_TYPE_INT: {
// // qDebug()<< qvariant_cast<int>(m_lineEdit->text().toInt());
// m_value = qvariant_cast<int>(m_lineEdit->text().toInt());
// break;
// }
// case CUI_DATA_TYPE_STRING: {
// m_value = m_lineEdit->text();
// break;
// }
// }
m_value = this->getQVFrom(m_lineEdit->text());
this->setValueToOrigin();
qDebug() << "setValueToOrigin LineEidt" << m_value;
}
}

@ -1,15 +1,14 @@
#include "CUIConfig.h"
#include "CUIDefine.h"
#include "CUISigsCenter.h"
#include <QDebug>
#include <QTimer>
#include "CUIDefine.h"
/**
* @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();
@ -70,12 +69,11 @@ CUIConfig::CUIConfig(QMap<QString, QVariant> property)
*
* @subsection RadioButton
* - "name" :
*
*
* @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,36 +83,34 @@ CUIConfig::CUIConfig(QMap<QString, QVariant> property, QVector<CUIConfig *> 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::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)
{
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);
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);
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);
double *ptr = qvariant_cast<double *>(pValue);
if (*ptr != value.toDouble()) {
*ptr = value.toDouble();
changed = true;
@ -122,7 +118,7 @@ void CUIConfig::setValue(QVariant value)
}
// 如果需要通知,则通知参数值发生修改
if (changed && this->getPropertyOriginValue("semaphore") != QVariant::Invalid) {
QTimer::singleShot(50, m_sigsCenter, [ = ]() {
QTimer::singleShot(50, m_sigsCenter, [=]() {
int semaphore = this->getPropertyOriginValue("semaphore").toInt();
emit m_sigsCenter->sig_cuiPropertyChanged(semaphore);
});
@ -134,9 +130,8 @@ 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,62 +142,55 @@ 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;
}
/**
* @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_", ""); // 初始值
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("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") {
} 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", "");
}
}
/**
* @brief 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;
}
}

@ -1,34 +1,34 @@
#ifndef CUICONFIG_H
#define CUICONFIG_H
#include <QString>
#include "CUIPropertyAPI.h"
#include <QMap>
#include <QString>
#include <QVariant>
#include "CUIPropertyAPI.h"
class CUISigsCenter;
class CUIPropertyAPI CUIConfig
{
public:
class CUIPropertyAPI CUIConfig {
public:
CUIConfig(QMap<QString, QVariant> temp);
CUIConfig(QMap<QString, QVariant> temp, QVector<CUIConfig*> sub);
CUIConfig(QMap<QString, QVariant> temp, QVector<CUIConfig *> sub);
void printConfig();
void setValue(QVariant);
QString getPropertyValue(QString);
QVariant getPropertyOriginValue(QString);
QVector<CUIConfig*> getSub();
private:
QVector<CUIConfig *> getSub();
private:
void setDefault();
void setDefault(QString key, QVariant val);
private:
private:
QMap<QString, QVariant> property;
QVector<CUIConfig*> sub;
QVector<CUIConfig *> sub;
static int labelMinWidth;
CUISigsCenter* m_sigsCenter = nullptr;
CUISigsCenter *m_sigsCenter = nullptr;
};
#endif // CUICONFIG_H

Loading…
Cancel
Save