From f2a804dd35bf20f854b0a47eb34d0e19ee1f6847 Mon Sep 17 00:00:00 2001 From: mzh Date: Tue, 12 Nov 2024 10:34:39 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81ui=E7=95=8C=E9=9D=A2=E4=B8=8A?= =?UTF-8?q?=E6=8A=8A=E7=B2=98=E6=80=A7=E6=A8=A1=E5=9E=8B=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=88=90=E6=A0=B9=E6=8D=AE=E6=97=B6=E9=97=B4=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CFDStructDataManagerBase.h | 3 +- .../CFDStructDataSolverKvislManager.cpp | 280 ++++++++++++++++-- .../CFDStructDataSolverKvislManager.h | 67 +++-- .../CFDStructDataSolverTimeModeManager.cpp | 2 +- .../CFDStructDataSolverTimeModeManager.h | 2 +- CFDStruct/CUIProperty/CUIComponentBase.cpp | 113 ++++--- .../CUIProperty/CUIComponentComboBox.cpp | 25 +- .../CUIProperty/CUIComponentILineEdit.cpp | 89 +++--- CFDStruct/CUIProperty/CUIConfig.cpp | 92 +++--- CFDStruct/CUIProperty/CUIConfig.h | 22 +- 10 files changed, 448 insertions(+), 247 deletions(-) diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataManagerBase.h b/CFDStruct/CFDStructDataManager/CFDStructDataManagerBase.h index f713c41..9b21113 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataManagerBase.h +++ b/CFDStruct/CFDStructDataManager/CFDStructDataManagerBase.h @@ -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; diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataSolverKvislManager.cpp b/CFDStruct/CFDStructDataManager/CFDStructDataSolverKvislManager.cpp index 22f3955..1cb4226 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataSolverKvislManager.cpp +++ b/CFDStruct/CFDStructDataManager/CFDStructDataSolverKvislManager.cpp @@ -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; +} \ No newline at end of file diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataSolverKvislManager.h b/CFDStruct/CFDStructDataManager/CFDStructDataSolverKvislManager.h index 6bbfba6..a2316fe 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataSolverKvislManager.h +++ b/CFDStruct/CFDStructDataManager/CFDStructDataSolverKvislManager.h @@ -5,71 +5,86 @@ #ifndef CFDSTRUCTDATASOLVERKVISLLMANAGER_H #define CFDSTRUCTDATASOLVERKVISLLMANAGER_H -#include -#include "CFDStructDataManager_global.h" #include "CFDStructDataManagerBase.h" +#include "CFDStructDataManager_global.h" +#include 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 diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.cpp b/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.cpp index 848583f..0232e95 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.cpp +++ b/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.cpp @@ -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; } diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.h b/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.h index b18c0c3..a98813a 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.h +++ b/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.h @@ -42,7 +42,7 @@ class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverTimeModeManager : public CF // 时均统计量数据采样:0 | 1 int m_timeaverage = 0; - public: + public: int getRunType(); }; diff --git a/CFDStruct/CUIProperty/CUIComponentBase.cpp b/CFDStruct/CUIProperty/CUIComponentBase.cpp index 8186b8f..a7eea78 100644 --- a/CFDStruct/CUIProperty/CUIComponentBase.cpp +++ b/CFDStruct/CUIProperty/CUIComponentBase.cpp @@ -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_conf->getPropertyOriginValue("value_type").toInt()); - qDebug()<<"++++++"; - if(m_conf->getPropertyOriginValue("initial_value") != QVariant::Invalid) { + qDebug() << "------"; + qDebug() << m_dataType; + qDebug() << static_cast(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(str.toDouble()); - break; - } - case CUI_DATA_TYPE_INT: { -// qDebug()<< qvariant_cast(m_lineEdit->text().toInt()); - v = qvariant_cast(str.toInt()); - break; - } - case CUI_DATA_TYPE_STRING: { - v = str; - break; - } + break; + } + case CUI_DATA_TYPE_INT: { + // qDebug()<< qvariant_cast(m_lineEdit->text().toInt()); + v = qvariant_cast(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); } } - - diff --git a/CFDStruct/CUIProperty/CUIComponentComboBox.cpp b/CFDStruct/CUIProperty/CUIComponentComboBox.cpp index 072e505..4218a75 100644 --- a/CFDStruct/CUIProperty/CUIComponentComboBox.cpp +++ b/CFDStruct/CUIProperty/CUIComponentComboBox.cpp @@ -14,10 +14,9 @@ * @param parent */ CUIComponentComboBox::CUIComponentComboBox(CUIConfig *conf, - QVector &subCUI, - QWidget *parent) - : CUIComponentBaseWidget(parent) -{ + QVector &subCUI, + QWidget *parent) + : CUIComponentBaseWidget(parent) { this->m_conf = conf; initUI(subCUI); } @@ -26,8 +25,7 @@ CUIComponentComboBox::CUIComponentComboBox(CUIConfig *conf, * @brief CUIComponentComboBox::getLabelWidth 获取combobox的label的最小宽度 * @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,添加label和comboBox */ -void CUIComponentComboBox::initUI(QVector &subCUI) -{ +void CUIComponentComboBox::initUI(QVector &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 &subCUI) ((QHBoxLayout *)m_layout)->setStretchFactor(m_comboBox, 1); iniComoboBox(); connect(m_comboBox, QOverload::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") { diff --git a/CFDStruct/CUIProperty/CUIComponentILineEdit.cpp b/CFDStruct/CUIProperty/CUIComponentILineEdit.cpp index 0885c9c..02860e6 100644 --- a/CFDStruct/CUIProperty/CUIComponentILineEdit.cpp +++ b/CFDStruct/CUIProperty/CUIComponentILineEdit.cpp @@ -15,10 +15,9 @@ * @param parent */ CUIComponentLineEdit::CUIComponentLineEdit(CUIConfig *conf, - QVector &subCUI, - QWidget *parent) - : CUIComponentBaseWidget(parent),CUIComponentBase() -{ + QVector &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 &subCUI) -{ +void CUIComponentLineEdit::initUI(QVector &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(this->m_conf->getPropertyOriginValue("data_type").toInt()); + // m_dataType = static_cast(this->m_conf->getPropertyOriginValue("data_type").toInt()); this->setLayout(m_layout); // 设置格式校验 this->setValidator(); @@ -62,30 +58,28 @@ void CUIComponentLineEdit::initUI(QVector &subCUI) &CUIComponentLineEdit::onTextChanged); } -void CUIComponentLineEdit::setValidator() -{ - qDebug()<setValidator(new QDoubleValidator(m_rangeMin.toDouble(), - m_rangeMax.toDouble(), 10)); - break; - } - case CUI_DATA_TYPE_INT: { - qDebug()<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(m_lineEdit->text().toDouble()); -// break; -// } -// case CUI_DATA_TYPE_INT: { -//// qDebug()<< qvariant_cast(m_lineEdit->text().toInt()); -// m_value = qvariant_cast(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(m_lineEdit->text().toDouble()); + // break; + // } + // case CUI_DATA_TYPE_INT: { + // // qDebug()<< qvariant_cast(m_lineEdit->text().toInt()); + // m_value = qvariant_cast(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; } } diff --git a/CFDStruct/CUIProperty/CUIConfig.cpp b/CFDStruct/CUIProperty/CUIConfig.cpp index 294e4af..5c923e9 100644 --- a/CFDStruct/CUIProperty/CUIConfig.cpp +++ b/CFDStruct/CUIProperty/CUIConfig.cpp @@ -1,15 +1,14 @@ #include "CUIConfig.h" +#include "CUIDefine.h" #include "CUISigsCenter.h" #include #include -#include "CUIDefine.h" /** * @brief CUIConfig::CUIConfig 构造函数 * @param property 组件的属性 */ -CUIConfig::CUIConfig(QMap property) -{ +CUIConfig::CUIConfig(QMap property) { setDefault(); this->property = property; this->m_sigsCenter = CUISigsCenter::getInstance(); @@ -70,12 +69,11 @@ CUIConfig::CUIConfig(QMap property) * * @subsection RadioButton 圆形选择按钮 * - "name" : 组件名 - * + * * @param property 组件的属性 * @param sub 该组件的子组件配置的列表 */ -CUIConfig::CUIConfig(QMap property, QVector sub) -{ +CUIConfig::CUIConfig(QMap property, QVector sub) { setDefault(); this->property = property; this->sub = sub; @@ -85,36 +83,34 @@ CUIConfig::CUIConfig(QMap property, QVector 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(pValue); + int *ptr = qvariant_cast(pValue); if (*ptr != value.toInt()) { *ptr = value.toInt(); changed = true; } } else if (property["value_type"] == CUI_DATA_TYPE_DOUBLE) { - double* ptr = qvariant_cast(pValue); + double *ptr = qvariant_cast(pValue); if (*ptr != value.toDouble()) { *ptr = value.toDouble(); changed = true; } } else if (property["value_type"] == CUI_DATA_TYPE_STRING) { - double* ptr = qvariant_cast(pValue); + double *ptr = qvariant_cast(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(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::getSub() -{ +QVector CUIConfig::getSub() { return this->sub; } - /** * @brief CUIConfig::setDefault 初始化属性 */ -void CUIConfig::setDefault() -{ +void CUIConfig::setDefault() { QString type = qvariant_cast(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; } } - diff --git a/CFDStruct/CUIProperty/CUIConfig.h b/CFDStruct/CUIProperty/CUIConfig.h index 5b551c7..1273846 100644 --- a/CFDStruct/CUIProperty/CUIConfig.h +++ b/CFDStruct/CUIProperty/CUIConfig.h @@ -1,34 +1,34 @@ #ifndef CUICONFIG_H #define CUICONFIG_H -#include +#include "CUIPropertyAPI.h" #include +#include #include -#include "CUIPropertyAPI.h" class CUISigsCenter; -class CUIPropertyAPI CUIConfig -{ -public: +class CUIPropertyAPI CUIConfig { + public: CUIConfig(QMap temp); - CUIConfig(QMap temp, QVector sub); + CUIConfig(QMap temp, QVector sub); void printConfig(); void setValue(QVariant); QString getPropertyValue(QString); QVariant getPropertyOriginValue(QString); - QVector getSub(); -private: + QVector getSub(); + + private: void setDefault(); void setDefault(QString key, QVariant val); -private: + private: QMap property; - QVector sub; + QVector sub; static int labelMinWidth; - CUISigsCenter* m_sigsCenter = nullptr; + CUISigsCenter *m_sigsCenter = nullptr; }; #endif // CUICONFIG_H