diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataSolverComputingControlManager.h b/CFDStruct/CFDStructDataManager/CFDStructDataSolverComputingControlManager.h index e8bab8e..d2783b2 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataSolverComputingControlManager.h +++ b/CFDStruct/CFDStructDataManager/CFDStructDataSolverComputingControlManager.h @@ -11,17 +11,17 @@ class CUIConfig; class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverComputingControlManager : public CFDStructDataManagerBase { Q_OBJECT public: - explicit CFDStructDataSolverComputingControlManager(QObject *parent = nullptr); + explicit CFDStructDataSolverComputingControlManager(QObject* parent = nullptr); ~CFDStructDataSolverComputingControlManager(); - CUIConfig *getParamUIConfig(); - void saveDataToDom(rapidjson::Document &dom); + CUIConfig* getParamUIConfig(); + void saveDataToDom(rapidjson::Document& dom); - void readDataFromDom(rapidjson::Document &dom); + void readDataFromDom(rapidjson::Document& dom); private: // 生成界面配置 - CUIConfig *genUIConfig(); + CUIConfig* genUIConfig(); signals: private: diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataSolverInitializationManager.h b/CFDStruct/CFDStructDataManager/CFDStructDataSolverInitializationManager.h index f1c38e8..45e03ee 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataSolverInitializationManager.h +++ b/CFDStruct/CFDStructDataManager/CFDStructDataSolverInitializationManager.h @@ -8,26 +8,25 @@ #include "CFDStructDataManager_global.h" class CUIConfig; -class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverInitializationManager : public CFDStructDataManagerBase -{ +class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverInitializationManager : public CFDStructDataManagerBase { Q_OBJECT -public: - explicit CFDStructDataSolverInitializationManager(QObject *parent = nullptr); + public: + explicit CFDStructDataSolverInitializationManager(QObject* parent = nullptr); ~CFDStructDataSolverInitializationManager(); - CUIConfig *getParamUIConfig(); - void saveDataToDom(rapidjson::Document &dom); - void readDataFromDom(rapidjson::Document &dom); + CUIConfig* getParamUIConfig(); + void saveDataToDom(rapidjson::Document& dom); + void readDataFromDom(rapidjson::Document& dom); -private: + private: // 生成界面配置 柱坐标系 - CUIConfig *genCylindricalUIConfig(); + CUIConfig* genCylindricalUIConfig(); // 生成界面配置 笛卡尔坐标系 - CUIConfig *genCartesianUIConfig(); -signals: + CUIConfig* genCartesianUIConfig(); + signals: -private: + private: // 参考值取自 int m_ReferenceValuesFrom = 0; // Reference Values From diff --git a/CFDStruct/CUIProperty/CUIComponentILineEdit.cpp b/CFDStruct/CUIProperty/CUIComponentILineEdit.cpp index 0885c9c..1676f78 100644 --- a/CFDStruct/CUIProperty/CUIComponentILineEdit.cpp +++ b/CFDStruct/CUIProperty/CUIComponentILineEdit.cpp @@ -14,11 +14,10 @@ * @param conf 配置信息 * @param parent */ -CUIComponentLineEdit::CUIComponentLineEdit(CUIConfig *conf, - QVector &subCUI, - QWidget *parent) - : CUIComponentBaseWidget(parent),CUIComponentBase() -{ +CUIComponentLineEdit::CUIComponentLineEdit(CUIConfig* conf, + 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,16 +35,14 @@ 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); @@ -58,58 +54,65 @@ void CUIComponentLineEdit::initUI(QVector &subCUI) // 设置格式校验 this->setValidator(); this->setInputTips(); + // 显示值 + m_lineEdit->setText(m_conf->getOriginValueString()); connect(m_lineEdit, &QLineEdit::textEdited, this, &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 ? "[" : "("; msg += this->getRangeMinString() + "," + this->getRangeMaxString(); msg += m_inclusiveMax ? "]" : ")"; } + if (m_required) { msg += "\t" + tr("(required)"); } + m_lineEdit->setPlaceholderText(msg); } /** * @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()))) { palette.setColor(QPalette::Text, Qt::black); + } else { palette.setColor(QPalette::Text, Qt::red); } + m_lineEdit->setPalette(palette); } } @@ -122,9 +125,9 @@ 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: { diff --git a/CFDStruct/CUIProperty/CUIConfig.cpp b/CFDStruct/CUIProperty/CUIConfig.cpp index 294e4af..d387dce 100644 --- a/CFDStruct/CUIProperty/CUIConfig.cpp +++ b/CFDStruct/CUIProperty/CUIConfig.cpp @@ -8,8 +8,7 @@ * @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,8 +83,7 @@ CUIConfig::CUIConfig(QMap property, QVector sub) /** * @brief CUIConfig::printConfig 打印当前配置信息 */ -void CUIConfig::printConfig() -{ +void CUIConfig::printConfig() { // qDebug() << "{"; // for(auto it = property.begin(); it != property.end(); it++) { // qDebug() << it.key() << ' ' << it.value(); @@ -97,29 +94,59 @@ void CUIConfig::printConfig() // qDebug() << "}"; } -void CUIConfig::setValue(QVariant value) -{ +QString CUIConfig::getOriginValueString() { + QVariant pValue = property["value_origin"]; + + // 如果没有设置原始值 + if (pValue == QVariant::Invalid) { + return QString(""); + } + + if (property["value_type"] == CUI_DATA_TYPE_INT) { + int* ptr = qvariant_cast(pValue); + return QString::number(*ptr); + + } else if (property["value_type"] == CUI_DATA_TYPE_DOUBLE) { + double* ptr = qvariant_cast(pValue); + return QString::number(*ptr); + + } else if (property["value_type"] == CUI_DATA_TYPE_STRING) { + QString* ptr = qvariant_cast(pValue); + return *ptr; + } + + return QString(""); +} + +void CUIConfig::setValue(QVariant value) { bool changed = false; QVariant pValue = property["value_origin"]; + if (property["value_type"] == CUI_DATA_TYPE_INT) { int* ptr = qvariant_cast(pValue); + if (*ptr != value.toInt()) { *ptr = value.toInt(); 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(); + QString* ptr = qvariant_cast(pValue); + + if (*ptr != value.toString()) { + *ptr = value.toString(); changed = true; } } + // 如果需要通知,则通知参数值发生修改 if (changed && this->getPropertyOriginValue("semaphore") != QVariant::Invalid) { QTimer::singleShot(50, m_sigsCenter, [ = ]() { @@ -134,11 +161,11 @@ void CUIConfig::setValue(QVariant value) * @param key 属性名 * @return */ -QString CUIConfig::getPropertyValue(QString key) -{ - if(property.contains(key)) { +QString CUIConfig::getPropertyValue(QString key) { + if (property.contains(key)) { return qvariant_cast(property[key]); } + return QString(); } @@ -147,16 +174,15 @@ QString CUIConfig::getPropertyValue(QString key) * @param key 属性名 * @return */ -QVariant CUIConfig::getPropertyOriginValue(QString key) -{ - if(property.contains(key)) { +QVariant CUIConfig::getPropertyOriginValue(QString key) { + if (property.contains(key)) { return property[key]; } + return QVariant::Invalid; } -QVector CUIConfig::getSub() -{ +QVector CUIConfig::getSub() { return this->sub; } @@ -164,10 +190,10 @@ QVector CUIConfig::getSub() /** * @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_", ""); // 初始值 @@ -177,16 +203,20 @@ void CUIConfig::setDefault() setDefault("inclusive_min", true); // 左范围是否包括 setDefault("inclusive_max", true); // 右范围是否包括 setDefault("required_", true); // 是否为必选 - } else if(type == "Widget") { + + } else if (type == "Widget") { setDefault("layout", "QVBoxLayout"); setDefault("name", ""); - } else if(type == "GroupBox") { + + } else if (type == "GroupBox") { setDefault("name", ""); setDefault("layout", "QVBoxLayout"); - } else if(type == "TabWidget") { - } else if(type == "ComboBox") { + + } else if (type == "TabWidget") { + } else if (type == "ComboBox") { setDefault("name", ""); - } else if(type == "Item") { + + } else if (type == "Item") { setDefault("name", ""); setDefault("data_type", "string"); setDefault("data", ""); @@ -199,9 +229,8 @@ void CUIConfig::setDefault() * @param key * @param val */ -void CUIConfig::setDefault(QString key, QVariant val) -{ - if(!property.contains(key)) { +void CUIConfig::setDefault(QString key, QVariant val) { + if (!property.contains(key)) { property[key] = val; } } diff --git a/CFDStruct/CUIProperty/CUIConfig.h b/CFDStruct/CUIProperty/CUIConfig.h index 5b551c7..35702fe 100644 --- a/CFDStruct/CUIProperty/CUIConfig.h +++ b/CFDStruct/CUIProperty/CUIConfig.h @@ -8,9 +8,8 @@ class CUISigsCenter; -class CUIPropertyAPI CUIConfig -{ -public: +class CUIPropertyAPI CUIConfig { + public: CUIConfig(QMap temp); CUIConfig(QMap temp, QVector sub); void printConfig(); @@ -19,11 +18,12 @@ public: QString getPropertyValue(QString); QVariant getPropertyOriginValue(QString); QVector getSub(); -private: + QString getOriginValueString(); + private: void setDefault(); void setDefault(QString key, QVariant val); -private: + private: QMap property; QVector sub; static int labelMinWidth;