From 00fe61fd2d47be91ee4f7be2ba5b82b2bb61d518 Mon Sep 17 00:00:00 2001 From: simonyan <315082291@qq.com> Date: Wed, 30 Oct 2024 16:00:08 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=AE=8C=E6=88=90CUIProperty?= =?UTF-8?q?=E7=9A=84=E5=9F=BA=E7=B1=BB=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CFDStructDataManager.pri | 2 + .../CFDStructDataManagerBase.cpp | 19 ++ .../CFDStructDataManagerBase.h | 25 +++ .../CFDStructDataSolverTimeModeManager.cpp | 39 ++-- .../CFDStructDataSolverTimeModeManager.h | 21 +- CFDStruct/CFDStructMain/CFDTreeWidget.cpp | 2 - .../CFDStructOperatorsBasicModelManager.cpp | 97 --------- .../CFDStructOperatorsBasicModelManager.h | 40 ---- .../CFDStructOperatorsModel.pri | 2 - CFDStruct/CUIProperty/CUIComponentBase.cpp | 148 +++++++++++++ CFDStruct/CUIProperty/CUIComponentBase.h | 55 +++++ CFDStruct/CUIProperty/CUIConfig.cpp | 48 ++-- CFDStruct/CUIProperty/CUIDefine.h | 11 + CFDStruct/CUIProperty/CUILineEdit.cpp | 206 +++++------------- CFDStruct/CUIProperty/CUILineEdit.h | 35 +-- CFDStruct/CUIProperty/CUIProperty.pri | 3 + 16 files changed, 398 insertions(+), 355 deletions(-) create mode 100644 CFDStruct/CFDStructDataManager/CFDStructDataManagerBase.cpp create mode 100644 CFDStruct/CFDStructDataManager/CFDStructDataManagerBase.h delete mode 100644 CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsBasicModelManager.cpp delete mode 100644 CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsBasicModelManager.h create mode 100644 CFDStruct/CUIProperty/CUIComponentBase.cpp create mode 100644 CFDStruct/CUIProperty/CUIComponentBase.h create mode 100644 CFDStruct/CUIProperty/CUIDefine.h diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataManager.pri b/CFDStruct/CFDStructDataManager/CFDStructDataManager.pri index 655cca8..a4013d6 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataManager.pri +++ b/CFDStruct/CFDStructDataManager/CFDStructDataManager.pri @@ -1,9 +1,11 @@ SOURCES += \ + $$PWD/CFDStructDataManagerBase.cpp \ $$PWD/CFDStructDataSolverTimeModeManager.cpp \ $$PWD/CFDStructSigsCenter.cpp \ $$PWD/CFDStructDataManager.cpp \ HEADERS += \ + $$PWD/CFDStructDataManagerBase.h \ $$PWD/CFDStructDataSolverTimeModeManager.h \ $$PWD/CFDStructSigsCenter.h \ $$PWD/CFDStructDataManager_global.h \ diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataManagerBase.cpp b/CFDStruct/CFDStructDataManager/CFDStructDataManagerBase.cpp new file mode 100644 index 0000000..ef78d7e --- /dev/null +++ b/CFDStruct/CFDStructDataManager/CFDStructDataManagerBase.cpp @@ -0,0 +1,19 @@ +#include "CFDStructDataManagerBase.h" + +CFDStructDataManagerBase::CFDStructDataManagerBase(QObject *parent) : QObject(parent) +{ + m_cuiSigsCenter = CUISigsCenter::getInstance(); +} + +CFDStructDataManagerBase::~CFDStructDataManagerBase() +{ + if (m_uiConfig != nullptr) { + delete m_uiConfig; + m_uiConfig = nullptr; + } +} + +CUIConfig *CFDStructDataManagerBase::getParamUIConfig() +{ + return nullptr; +} diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataManagerBase.h b/CFDStruct/CFDStructDataManager/CFDStructDataManagerBase.h new file mode 100644 index 0000000..72a020d --- /dev/null +++ b/CFDStruct/CFDStructDataManager/CFDStructDataManagerBase.h @@ -0,0 +1,25 @@ +#ifndef CFDSTRUCTDATAMANAGERBASE_H +#define CFDSTRUCTDATAMANAGERBASE_H + +#include +#include "CFDStructDataManager_global.h" +#include "CUIProperty/CUISigsCenter.h" +#include "CUIProperty/CUIConfig.h" +#include "CUIProperty/CUIDefine.h" + +class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataManagerBase : public QObject +{ + Q_OBJECT +public: + explicit CFDStructDataManagerBase(QObject *parent = nullptr); + ~CFDStructDataManagerBase(); + // 获取参数界面的配置 + virtual CUIConfig* getParamUIConfig(); +signals: + +protected: + CUIConfig* m_uiConfig = nullptr; + CUISigsCenter* m_cuiSigsCenter = nullptr; +}; + +#endif // CFDSTRUCTDATAMANAGERBASE_H diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.cpp b/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.cpp index 7ae05df..8855384 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.cpp +++ b/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.cpp @@ -5,10 +5,10 @@ #include "CUIProperty/CUISigsCenter.h" #include -CFDStructDataSolverTimeModeManager::CFDStructDataSolverTimeModeManager(QObject *parent) : QObject(parent) +CFDStructDataSolverTimeModeManager::CFDStructDataSolverTimeModeManager(QObject *parent) : CFDStructDataManagerBase(parent) { m_uiConfig = nullptr; - connect(CUISigsCenter::getInstance(), &CUISigsCenter::sig_cuiPropertyChanged, this, [ = ](int semaphore) { + connect(m_cuiSigsCenter, &CUISigsCenter::sig_cuiPropertyChanged, this, [ = ](int semaphore) { qDebug() << semaphore << " ========================"; emit CFDStructSigsCenter::getInstance()->sig_solverTimeModeDataChanged(); }); @@ -16,10 +16,7 @@ CFDStructDataSolverTimeModeManager::CFDStructDataSolverTimeModeManager(QObject * CFDStructDataSolverTimeModeManager::~CFDStructDataSolverTimeModeManager() { - if (m_uiConfig != nullptr) { - delete m_uiConfig; - m_uiConfig = nullptr; - } +// CFDStructDataManagerBase::~CFDStructDataManagerBase(); } CUIConfig *CFDStructDataSolverTimeModeManager::getParamUIConfig() @@ -48,24 +45,24 @@ CUIConfig *CFDStructDataSolverTimeModeManager::genSteadyModeUIConfig() new CUIConfig({ {"type", "ComboBox"}, {"name", "Time Mode"}, - {"valueType", "Int"}, - {"valueOrigin", QVA_GLOBAL(&m_runtype)}, + {"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT}, + {"value_origin", QVA_GLOBAL(&m_runtype)}, {"semaphore", 1}, }, { new CUIConfig({ {"type", "Item"}, {"name", "steady"}, - {"data", "0"}, }), new CUIConfig({ {"type", "Item"}, {"name", "unsteady"}, - {"data", "1"}, }) }), new CUIConfig({ {"type", "LineEdit"}, - {"name", "iteration count"} + {"name", "iteration count"}, + {"value_type", "Int"}, + {"value_origin", QVA_GLOBAL(&m_mcyc)}, }) }); } @@ -77,8 +74,8 @@ CUIConfig *CFDStructDataSolverTimeModeManager::genUnsteadyModeUIConfig() new CUIConfig({ {"type", "ComboBox"}, {"name", "Time Mode"}, - {"valueType", "Int"}, - {"valueOrigin", QVA_GLOBAL(&m_runtype)}, + {"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT}, + {"value_origin", QVA_GLOBAL(&m_runtype)}, {"semaphore", 1}, }, { new CUIConfig({ @@ -92,19 +89,27 @@ CUIConfig *CFDStructDataSolverTimeModeManager::genUnsteadyModeUIConfig() }), new CUIConfig({ {"type", "LineEdit"}, - {"name", "alf0"} + {"name", "alf0"}, + {"value_type", "Double"}, + {"value_origin", QVA_GLOBAL(&m_alf0)}, }), new CUIConfig({ {"type", "LineEdit"}, - {"name", "realdt"} + {"name", "realdt"}, + {"value_type", "Double"}, + {"value_origin", QVA_GLOBAL(&m_realdt)}, }), new CUIConfig({ {"type", "LineEdit"}, - {"name", "nstep"} + {"name", "nstep"}, + {"value_type", "Int"}, + {"value_origin", QVA_GLOBAL(&m_nstep)}, }), new CUIConfig({ {"type", "LineEdit"}, - {"name", "mcyc"} + {"name", "mcyc"}, + {"value_type", "Int"}, + {"value_origin", QVA_GLOBAL(&m_mcyc)}, }) }); } diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.h b/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.h index 028d62b..fc2884b 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.h +++ b/CFDStruct/CFDStructDataManager/CFDStructDataSolverTimeModeManager.h @@ -1,11 +1,11 @@ #ifndef CFDSTRUCTDATASOLVERTIMEMODEMANAGER_H #define CFDSTRUCTDATASOLVERTIMEMODEMANAGER_H -#include +#include #include "CFDStructDataManager_global.h" class CUIConfig; -class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverTimeModeManager : public QObject +class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverTimeModeManager : public CFDStructDataManagerBase { Q_OBJECT public: @@ -22,19 +22,18 @@ private: signals: private: - // 鏃堕棿妯″紡 + // 时间模式:定常0,非定常1 int m_runtype = 0; - // 杩唬姝ユ暟锛>=1锛屽畾甯告椂锛氳凯浠f鏁帮紝闈炲畾甯革細鍐呰凯浠f鏁 int m_mcyc = 1000; - // 姝ラ暱妯″紡锛屽浐瀹氾紝涓嶅彲淇敼 + // 时间模式:定常0,则是迭代步数;时间模式:非定常1,则是内迭代步数 + int m_mcyc = 1000; + // 步长模式 >=1 double m_alf0 = 1.0; - // 鏃堕棿姝ラ暱锛0 + // 时间步长 >0 double m_realdt = 1.0; - // 鏃堕棿姝ユ暟锛=1 - double m_nstep = 10; - // 鏃跺潎缁熻閲忔暟鎹噰鏍0,1 + // 时间步数 >=1 + int m_nstep = 10; + // 时均统计量数据采样:0 | 1 int m_timeaverage = 0; - - CUIConfig* m_uiConfig = nullptr; }; #endif // CFDSTRUCTDATASOLVERTIMEMODEMANAGER_H diff --git a/CFDStruct/CFDStructMain/CFDTreeWidget.cpp b/CFDStruct/CFDStructMain/CFDTreeWidget.cpp index a5220d6..373e5ce 100644 --- a/CFDStruct/CFDStructMain/CFDTreeWidget.cpp +++ b/CFDStruct/CFDStructMain/CFDTreeWidget.cpp @@ -5,8 +5,6 @@ #include "GUIFrame/MainTreeWidget.h" #include "OperatorsInterface/GraphEventOperator.h" #include "OperatorsInterface/TreeEventOperator.h" -#include "CFDOperatorsModel/CFDOperatorsTimeModeManager.h" - #include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h" #include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h" diff --git a/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsBasicModelManager.cpp b/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsBasicModelManager.cpp deleted file mode 100644 index 3277f0a..0000000 --- a/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsBasicModelManager.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "CFDStructOperatorsBasicModelManager.h" - -#include "GUIFrame/MainWindow.h" -#include "GUIFrame/PropertyWidget.h" - -#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h" -#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h" -#include "CFDStruct/CUIProperty/CUI.h" -#include "CUIProperty/CUIConfig.h" - -#include -#include - -namespace ModelOper -{ - CFDStructOperatorsBasicModelManager::CFDStructOperatorsBasicModelManager() - { - qDebug() << "build Time Mode Manager"; - } - - CFDStructOperatorsBasicModelManager::~CFDStructOperatorsBasicModelManager() - { - } - - bool CFDStructOperatorsBasicModelManager::execGUI() - { - QWidget* widget = nullptr; - GUI::MainWindow* mainWindow = dynamic_cast(FITKAPP->getGlobalData()->getMainWindow()); - if (mainWindow == nullptr) { - return false; - } - GUI::PropertyWidget* propertyWidget = mainWindow->getPropertyWidget(); - if (propertyWidget == nullptr) { - return false; - } -// switch (_operType){ -// case ModelOper::OperManagerBase::Edit: -// { -// widget = new GUI::BasicModelWidget(this); -// break; -// } -// } - qDebug() << "Time Mode Manager11111111111"; - widget = new QLabel("Time Mode Manager11111"); -// CUI* cui = new CUI(new CUIConfig({ -// {"type","Widget"} -// },{ -// new CUIConfig({ -// {"type","LineEidt"}, -// {"name","Solver type"} -// }), -// new CUIConfig({ -// {"type","ComboBox"}, -// {"name","flow model"} -// },{}), -// new CUIConfig({ -// {"type","PushButton"}, -// {"name","flow model"} -// }), -// new CUIConfig({ -// {"type","GroupBox"}, -// {"name","Fluid properties"} -// },{ -// new CUIConfig({ -// {"type","LineEdit"}, -// {"name","Gas composition"} -// }), -// new CUIConfig({ -// {"type","LineEdit"}, -// {"name","Gas constant (R)"} -// }), -// new CUIConfig({ -// {"type","LineEdit"}, -// {"name","Heat ratio"} -// }), -// new CUIConfig({ -// {"type","LineEdit"}, -// {"name","Laminar Prandtl number"} -// }), -// new CUIConfig({ -// {"type","LineEdit"}, -// {"name","Turbulent Prandtl number"} -// }), -// }) -// })); -// widget = cui->getUI(); -// if (mainWindow->getPropertyWidget() && widget) { - propertyWidget->setWidget(widget); -// } - return false; - } - - bool CFDStructOperatorsBasicModelManager::execProfession() - { - return true; - } -} diff --git a/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsBasicModelManager.h b/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsBasicModelManager.h deleted file mode 100644 index 042e4c2..0000000 --- a/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsBasicModelManager.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _CFDStructOperatorsBasicModelManager_H -#define _CFDStructOperatorsBasicModelManager_H - -#include "CFDStructOperatorsModelAPI.h" -#include "OperatorsModel/OperManagerBase.h" - -namespace ModelOper -{ - - class CFDStructOperatorsModelAPI CFDStructOperatorsBasicModelManager : public OperManagerBase - { - Q_OBJECT; - public: - /** - * @brief Construct a new Operators Mesh Base Manager object - */ - CFDStructOperatorsBasicModelManager(); - /** - * @brief Destroy the Operators Mesh Base Manager object - */ - ~CFDStructOperatorsBasicModelManager(); - /** - * @brief 执行 - * @return true 成功 - * @return false 失败 - */ - virtual bool execGUI(); - /** - * @brief 执行结果处理 - * @return true 成功 - * @return false 失败 - */ - virtual bool execProfession(); - }; - - // 按钮注册相关操作 - Register2FITKOPeratorRepo(actionBasicModelEdit, CFDStructOperatorsBasicModelManager); -} - -#endif diff --git a/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsModel.pri b/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsModel.pri index 70aa64b..f4a22ac 100644 --- a/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsModel.pri +++ b/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsModel.pri @@ -1,9 +1,7 @@ HEADERS += \ $$PWD/CFDStructOperatorsModelAPI.h \ - $$PWD/CFDStructOperatorsBasicModelManager.h \ $$PWD/CFDStructOperatorsTimeModeManager.h SOURCES += \ - $$PWD/CFDStructOperatorsBasicModelManager.cpp \ $$PWD/CFDStructOperatorsTimeModeManager.cpp diff --git a/CFDStruct/CUIProperty/CUIComponentBase.cpp b/CFDStruct/CUIProperty/CUIComponentBase.cpp new file mode 100644 index 0000000..c5a186a --- /dev/null +++ b/CFDStruct/CUIProperty/CUIComponentBase.cpp @@ -0,0 +1,148 @@ +#include "CUIComponentBase.h" + +CUIComponentBase::CUIComponentBase(QWidget *parent) : QWidget(parent) +{ + this->initSetting(); +} + +void CUIComponentBase::initSetting() +{ + if (!m_conf) { + return; + } + m_dataType = (CUI_DATA_TYPE)m_conf->getPropertyOriginValue("m_dataType").toInt(); + if(m_conf->getPropertyValue("initial_value") != QVariant::Invalid) { + m_value = m_conf->getPropertyOriginValue("initial_value"); + } + // 初始化是否必填 + if(m_conf->getPropertyValue("required") != QVariant::Invalid) { + m_required = m_conf->getPropertyOriginValue("required").toBool(); + } + if(m_dataType == CUI_DATA_TYPE_STRING) { + m_checkRange = false; + return; + } + // 是否检查范围 + if(m_conf->getPropertyValue("check_range") != QVariant::Invalid) { + m_checkRange = m_conf->getPropertyOriginValue("check_range").toBool(); + } + // 左值和右值是否包含 + if(m_conf->getPropertyOriginValue("inclusive_min") != QVariant::Invalid) { + m_inclusiveMin = m_conf->getPropertyOriginValue("inclusive_min").toBool(); + } + 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) { + m_rangeMin = m_conf->getPropertyValue("range_min"); + } else { + if (m_dataType == CUI_DATA_TYPE_INT) { + m_rangeMin = INT_MIN; + } else if (m_dataType == CUI_DATA_TYPE_DOUBLE) { + m_rangeMin = DBL_MIN; + } + } + if(m_conf->getPropertyOriginValue("range_max") != QVariant::Invalid) { + m_rangeMax = m_conf->getPropertyValue("range_max"); + } else { + if (m_dataType == CUI_DATA_TYPE_INT) { + m_rangeMin = INT_MAX; + } else if (m_dataType == CUI_DATA_TYPE_DOUBLE) { + m_rangeMin = DBL_MAX; + } + } + } +} + +bool CUIComponentBase::inRange() +{ + if(m_checkRange) { + // 如果包含最小值,但是修改后的值小于最小值,则不在范围内 + if (m_inclusiveMin && m_value < m_rangeMin ) { + return false; + } + // 如果不包含最小值,但是修改后的值小于等于最小值,则不在范围内 + if (!m_inclusiveMin && m_value <= m_rangeMin ) { + return false; + } + // 如果包含最大值,但是修改后的值大于最大值,则不在范围内 + if (m_inclusiveMax && m_value > m_rangeMax ) { + return false; + } + // 如果不包含最大值,但是修改后的值大于等于最大值,则不在范围内 + if (!m_inclusiveMax && m_value >= m_rangeMax ) { + return false; + } + } + return true; +} + +void CUIComponentBase::initUI() +{ +} + +void CUIComponentBase::initValidator() +{ +} + +QString CUIComponentBase::getValueString() +{ + if (m_value == QVariant::Invalid) { + return QString(""); + } + if(m_dataType == CUI_DATA_TYPE_STRING) { + return m_value.toString(); + } + if(m_dataType == CUI_DATA_TYPE_INT) { + return QString::number(m_value.toInt()); + } + if(m_dataType == CUI_DATA_TYPE_STRING) { + return QString::number(m_value.toDouble()); + } + return QString(""); +} + +QString CUIComponentBase::getRangeMinString() +{ + if (m_rangeMin == QVariant::Invalid) { + return QString(""); + } + if(m_dataType == CUI_DATA_TYPE_STRING) { + return m_rangeMin.toString(); + } + if(m_dataType == CUI_DATA_TYPE_INT) { + return QString::number(m_rangeMin.toInt()); + } + if(m_dataType == CUI_DATA_TYPE_STRING) { + return QString::number(m_rangeMin.toDouble()); + } + return QString(""); +} + +QString CUIComponentBase::getRangeMaxString() +{ + if (m_rangeMax == QVariant::Invalid) { + return QString(""); + } + if(m_dataType == CUI_DATA_TYPE_STRING) { + return m_rangeMax.toString(); + } + if(m_dataType == CUI_DATA_TYPE_INT) { + return QString::number(m_rangeMax.toInt()); + } + if(m_dataType == CUI_DATA_TYPE_STRING) { + return QString::number(m_rangeMax.toDouble()); + } + return QString(""); +} + +void CUIComponentBase::setValueToOrigin() +{ + if (m_conf) { + m_conf->setValue(m_value); + } +} + + diff --git a/CFDStruct/CUIProperty/CUIComponentBase.h b/CFDStruct/CUIProperty/CUIComponentBase.h new file mode 100644 index 0000000..6c1f7a7 --- /dev/null +++ b/CFDStruct/CUIProperty/CUIComponentBase.h @@ -0,0 +1,55 @@ +#ifndef CUICOMPONENTBASE_H +#define CUICOMPONENTBASE_H + +#include +#include +#include "CUIPropertyAPI.h" +#include "CUIConfig.h" +#include "CUIDefine.h" + +class CUIPropertyAPI CUIComponentBase : public QWidget +{ + Q_OBJECT +public: + explicit CUIComponentBase(QWidget *parent = nullptr); + +protected: + // 初始化配置 + void initSetting(); + // 判断是否在范围内 + bool inRange(); + // 初始化UI + virtual void initUI(); + // 初始化值校验器 + virtual void initValidator(); + // 获取值的字符串形式 + QString getValueString(); + // 获取最小值的字符串形式 + QString getRangeMinString(); + // 获取最大值的字符串形式 + QString getRangeMaxString(); + // 同步到数据来源 + void setValueToOrigin(); +protected: + CUIConfig* m_conf = nullptr; + // 值类型 + CUI_DATA_TYPE m_dataType = CUI_DATA_TYPE::CUI_DATA_TYPE_UNKNOW; + // 具体值 + QVariant m_value = QVariant::Invalid; + // 是否检查范围 + bool m_checkRange = false; + // 左值 + QVariant m_rangeMin; + // 右值 + QVariant m_rangeMax; + // 是否包含左值 + bool m_inclusiveMin = false; + // 是否包含右值 + bool m_inclusiveMax = false; + // 是否是必填 + bool m_required = true; +signals: + +}; + +#endif // CUICOMPONENTBASE_H diff --git a/CFDStruct/CUIProperty/CUIConfig.cpp b/CFDStruct/CUIProperty/CUIConfig.cpp index a25f119..8eea19f 100644 --- a/CFDStruct/CUIProperty/CUIConfig.cpp +++ b/CFDStruct/CUIProperty/CUIConfig.cpp @@ -2,6 +2,7 @@ #include "CUISigsCenter.h" #include #include +#include "CUIDefine.h" /** * @brief CUIConfig::CUIConfig 构造函数 @@ -96,19 +97,33 @@ void CUIConfig::printConfig() void CUIConfig::setValue(QVariant value) { - QVariant pValue = property["valueOrigin"]; - if (property["valueType"] == "Int") { + bool changed = false; + QVariant pValue = property["value_origin"]; + if (property["value_type"] == CUI_DATA_TYPE_INT) { int* ptr = qvariant_cast(pValue); if (*ptr != value.toInt()) { *ptr = value.toInt(); - // 如果需要通知,则通知参数值发生修改 - if (this->getPropertyOriginValue("semaphore") != QVariant::Invalid) { - QTimer::singleShot(50, m_sigsCenter, [ = ]() { - int semaphore = this->getPropertyOriginValue("semaphore").toInt(); - emit m_sigsCenter->sig_cuiPropertyChanged(semaphore); - }); - } + changed = true; } + } else if (property["value_type"] == CUI_DATA_TYPE_DOUBLE) { + 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); + 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); + }); } } @@ -152,13 +167,14 @@ void CUIConfig::setDefault() QString type = qvariant_cast(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"); //是否为必选 + 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", ""); diff --git a/CFDStruct/CUIProperty/CUIDefine.h b/CFDStruct/CUIProperty/CUIDefine.h new file mode 100644 index 0000000..5438bf9 --- /dev/null +++ b/CFDStruct/CUIProperty/CUIDefine.h @@ -0,0 +1,11 @@ +#ifndef CUIDEFINE_H +#define CUIDEFINE_H + +enum CUI_DATA_TYPE { + CUI_DATA_TYPE_INT, + CUI_DATA_TYPE_DOUBLE, + CUI_DATA_TYPE_STRING, + CUI_DATA_TYPE_UNKNOW, +}; + +#endif // CUIDEFINE_H diff --git a/CFDStruct/CUIProperty/CUILineEdit.cpp b/CFDStruct/CUIProperty/CUILineEdit.cpp index ec66048..283dbde 100644 --- a/CFDStruct/CUIProperty/CUILineEdit.cpp +++ b/CFDStruct/CUIProperty/CUILineEdit.cpp @@ -1,56 +1,24 @@ #include "CUILineEdit.h" #include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include /** * @brief CUILineEdit::CUILineEdit 构造函数 * @param conf 配置信息 * @param parent */ -CUILineEdit::CUILineEdit(CUIConfig* conf, QVector &subCUI,QWidget *parent) : QWidget(parent) +CUILineEdit::CUILineEdit(CUIConfig* conf, QVector &subCUI, QWidget *parent) : CUIComponentBase(parent) { - this->conf = conf; - appSetting(); - iniUI(subCUI); - showMsg(); - checkRange(); + this->m_conf = conf; + this->iniUI(subCUI); } -/** - * @brief CUILineEdit::isInRange 判断是否在设置范围内,根据不同的类型进行相应的判断 - * @return true\false 是否在范围内 - */ -bool CUILineEdit::isInRange() const -{ - bool res = false; - if(check_range_){ - if(data_type == "int") - { - if(inclusive_){ - res = range_min_.toInt() <= lineedit->text().toInt() && - lineedit->text().toInt() <= range_max_.toInt(); - }else{ - res = range_min_.toInt() < lineedit->text().toInt() && - lineedit->text().toInt() < range_max_.toInt(); - } - } - if(data_type == "double") - { - if(inclusive_){ - res = range_min_.toDouble() <= lineedit->text().toDouble() && - lineedit->text().toDouble() <= range_max_.toDouble(); - }else{ - res = range_min_.toDouble() < lineedit->text().toDouble() && - lineedit->text().toDouble() < range_max_.toDouble(); - } - } - } - return res; -} /** * @brief CUILineEdit::getLabelWidth 获取当前组件的label的最小宽度 @@ -58,7 +26,7 @@ bool CUILineEdit::isInRange() const */ qint32 CUILineEdit::getLabelWidth() { - return label->minimumSizeHint().width(); + return m_label->minimumSizeHint().width(); } /** @@ -67,7 +35,7 @@ qint32 CUILineEdit::getLabelWidth() */ void CUILineEdit::setLabelWidth(qint32 width) { - label->setMinimumWidth(width); + m_label->setMinimumWidth(width); } @@ -76,89 +44,28 @@ void CUILineEdit::setLabelWidth(qint32 width) */ void CUILineEdit::iniUI(QVector &subCUI) { - layout = new QHBoxLayout(); - label = new QLabel(conf->getPropertyValue("name")); - lineedit = new QLineEdit(initial_value_); - layout->addWidget(label); - layout->addWidget(lineedit); - this->setLayout(layout); - connect(lineedit, &QLineEdit::textEdited, this, &CUILineEdit::onTextChanged); -} - - -/** - * @brief CUILineEdit::appSetting 读取配置信息,并将配置信息存储到定义变量中 - */ -void CUILineEdit::appSetting() -{ - data_type = conf->getPropertyValue("data_type"); - initial_value_ = conf->getPropertyValue("initial_value_"); - qDebug()<< initial_value_; - if(data_type == "string"){ - check_range_ = 0; - } - if(data_type == "int"){ - if(conf->getPropertyValue("check_range_") == "true") - { - check_range_ = true; - range_min_ = conf->getPropertyValue("range_min_").toInt(); - range_max_ = conf->getPropertyValue("range_max_").toInt(); - - if(conf->getPropertyValue("inclusive_") == "true") - inclusive_ = true; - else - inclusive_ = false; - }else{ - check_range_ = false; - } - } - if(data_type == "double"){ - if(conf->getPropertyValue("check_range_") == "true"){ - check_range_ = true; - range_min_ = conf->getPropertyValue("range_min_").toDouble(); - range_max_ = conf->getPropertyValue("range_max_").toDouble(); - - if(conf->getPropertyValue("inclusive_") == "true") - inclusive_ = true; - else - inclusive_ = false; - }else{ - check_range_ = false; - } - } - if(conf->getPropertyValue("required_") == "false") - required_ = false; - else - required_ = true; + m_layout = new QHBoxLayout(); + m_label = new QLabel(m_conf->getPropertyValue("name")); + m_lineEdit = new QLineEdit(this->getValueString()); + m_layout->addWidget(m_label); + m_layout->addWidget(m_lineEdit); + this->setLayout(m_layout); + // 设置格式校验 + this->setValidator(); + this->setInputTips(); + connect(m_lineEdit, &QLineEdit::textEdited, this, &CUILineEdit::onTextChanged); } -/** - * @brief CUILineEdit::checkType 检查类型,并修改 - */ -void CUILineEdit::checkType(const QString &text) +void CUILineEdit::setValidator() { - qint32 cursorPosition = lineedit->cursorPosition(); - if(data_type == "int"){ - bool ok; - text.toInt(&ok); - if(ok || text == "" || text == "-") - lastEdited = text; - else - { - lineedit->setText(lastEdited); - lineedit->setCursorPosition(cursorPosition-1); + switch (m_dataType) { + case CUI_DATA_TYPE_DOUBLE: { + m_lineEdit->setValidator(new QDoubleValidator(m_rangeMin.toDouble(), m_rangeMax.toDouble(), 10)); + break; } - } - - if(data_type == "double"){ - bool ok; - text.toDouble(&ok); - if(ok || text == "" || text == "-") - lastEdited = text; - else - { - lineedit->setText(lastEdited); - lineedit->setCursorPosition(cursorPosition-1); + case CUI_DATA_TYPE_INT: { + m_lineEdit->setValidator(new QIntValidator(m_rangeMin.toInt(), m_rangeMax.toInt())); + break; } } } @@ -166,43 +73,34 @@ void CUILineEdit::checkType(const QString &text) /** * @brief CUILineEdit::showMsg 显示提示信息 */ -void CUILineEdit::showMsg() +void CUILineEdit::setInputTips() { QString msg = ""; - - if(check_range_){ - if(inclusive_){ - msg += "["+range_min_.toString()+","+range_max_.toString()+"] "; - }else{ - msg += "("+range_min_.toString()+","+range_max_.toString()+") "; - } + if(m_checkRange) { + msg += m_inclusiveMin ? "[" : "("; + msg += this->getRangeMinString() + "," + this->getRangeMaxString(); + msg += m_inclusiveMax ? "]" : ")"; } - - if(required_){ + if(m_required) { msg += "\t(必填)"; } - - lineedit->setPlaceholderText(msg); + m_lineEdit->setPlaceholderText(msg); } /** * @brief CUILineEdit::checkRange 检查范围,并给出提示 */ -bool CUILineEdit::checkRange() +void CUILineEdit::showRangeError() { - bool res = true; - if(check_range_){ - QPalette palette = lineedit->palette(); - res = isInRange(); - if(res){ + if(m_checkRange) { + QPalette palette = m_lineEdit->palette(); + if(this->inRange()) { palette.setColor(QPalette::Text, Qt::black); - }else{ + } else { palette.setColor(QPalette::Text, Qt::red); } - lineedit->setPalette(palette); + m_lineEdit->setPalette(palette); } - - return res; } @@ -216,6 +114,22 @@ bool CUILineEdit::checkRange() */ void CUILineEdit::onTextChanged(const QString &text) { - checkType(text); - checkRange(); + this->showRangeError(); + if (this->inRange()) { + switch (m_dataType) { + case CUI_DATA_TYPE_DOUBLE: { + m_value = qvariant_cast(m_lineEdit->text().toDouble()); + break; + } + case CUI_DATA_TYPE_INT: { + m_value = qvariant_cast(m_lineEdit->text().toInt()); + break; + } + case CUI_DATA_TYPE_STRING: { + m_value = m_lineEdit->text(); + break; + } + } + this->setValueToOrigin(); + } } diff --git a/CFDStruct/CUIProperty/CUILineEdit.h b/CFDStruct/CUIProperty/CUILineEdit.h index d97fe5b..d179ad2 100644 --- a/CFDStruct/CUIProperty/CUILineEdit.h +++ b/CFDStruct/CUIProperty/CUILineEdit.h @@ -3,50 +3,37 @@ #include #include "CUIPropertyAPI.h" +#include "CUIComponentBase.h" class CUIConfig; class QLabel; class QHBoxLayout; class CUI; -class CUIPropertyAPI CUILineEdit : public QWidget +class CUIPropertyAPI CUILineEdit : public CUIComponentBase { Q_OBJECT public: explicit CUILineEdit(CUIConfig* config, QVector &subCUI, QWidget *parent = nullptr); - bool isInRange() const; qint32 getLabelWidth(); void setLabelWidth(qint32 width); private: void iniUI(QVector &subCUI); - void appSetting(); - void checkType(const QString &text); - void showMsg(); - bool checkRange(); - - CUIConfig* conf; - QLabel* label; - QLineEdit* lineedit; -// QLayout* layout; - QHBoxLayout* layout; - - QString lastEdited; - - QString data_type; - QString initial_value_; - bool check_range_; - QVariant range_min_; - QVariant range_max_; - bool inclusive_; - bool required_; + // 设置格式校验器 + void setValidator(); + // 设置输入提示 + void setInputTips(); + void showRangeError(); + QLabel* m_label; + QLineEdit* m_lineEdit; + QHBoxLayout* m_layout; +// QString lastEdited; signals: - private slots: void onTextChanged(const QString &text); - }; #endif // CUILINEEDIT_H diff --git a/CFDStruct/CUIProperty/CUIProperty.pri b/CFDStruct/CUIProperty/CUIProperty.pri index 3463af4..8c19c26 100644 --- a/CFDStruct/CUIProperty/CUIProperty.pri +++ b/CFDStruct/CUIProperty/CUIProperty.pri @@ -1,4 +1,6 @@ HEADERS += \ + $$PWD/CUIComponentBase.h \ + $$PWD/CUIDefine.h \ CUI.h \ CUIButtonBox.h \ CUICheckBox.h \ @@ -15,6 +17,7 @@ HEADERS += \ CUIConfig.h SOURCES += \ + $$PWD/CUIComponentBase.cpp \ CUI.cpp \ CUIButtonBox.cpp \ CUICheckBox.cpp \