Merge branch 'feature/struct-menu-20241023' of http://1.92.128.200:3000/YXS/AppFlow into feature/struct-menu-20241023

feature/struct-menu-20241023
mzh 4 days ago
commit 0ccbc96825

@ -8,8 +8,7 @@
#include "CFDStructDataManager_global.h" #include "CFDStructDataManager_global.h"
class CUIConfig; class CUIConfig;
class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverInitializationManager : public CFDStructDataManagerBase class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverInitializationManager : public CFDStructDataManagerBase {
{
Q_OBJECT Q_OBJECT
public: public:
explicit CFDStructDataSolverInitializationManager(QObject* parent = nullptr); explicit CFDStructDataSolverInitializationManager(QObject* parent = nullptr);

@ -54,6 +54,8 @@ void CUIComponentLineEdit::initUI(QVector<CUIPropertyWidget *> &subCUI) {
// 设置格式校验 // 设置格式校验
this->setValidator(); this->setValidator();
this->setInputTips(); this->setInputTips();
// 显示值
m_lineEdit->setText(m_conf->getOriginValueString());
connect(m_lineEdit, &QLineEdit::textEdited, this, connect(m_lineEdit, &QLineEdit::textEdited, this,
&CUIComponentLineEdit::onTextChanged); &CUIComponentLineEdit::onTextChanged);
} }
@ -67,6 +69,7 @@ void CUIComponentLineEdit::setValidator() {
m_rangeMax.toDouble(), 10)); m_rangeMax.toDouble(), 10));
break; break;
} }
case CUI_DATA_TYPE_INT: { case CUI_DATA_TYPE_INT: {
qDebug() << m_rangeMin.toInt() << ' ' << m_rangeMax.toInt(); qDebug() << m_rangeMin.toInt() << ' ' << m_rangeMax.toInt();
m_lineEdit->setValidator( m_lineEdit->setValidator(
@ -81,14 +84,17 @@ void CUIComponentLineEdit::setValidator() {
*/ */
void CUIComponentLineEdit::setInputTips() { void CUIComponentLineEdit::setInputTips() {
QString msg = ""; QString msg = "";
if (m_checkRange) { if (m_checkRange) {
msg += m_inclusiveMin ? "[" : "("; msg += m_inclusiveMin ? "[" : "(";
msg += this->getRangeMinString() + "," + this->getRangeMaxString(); msg += this->getRangeMinString() + "," + this->getRangeMaxString();
msg += m_inclusiveMax ? "]" : ")"; msg += m_inclusiveMax ? "]" : ")";
} }
if (m_required) { if (m_required) {
msg += "\t" + tr("(required)"); msg += "\t" + tr("(required)");
} }
m_lineEdit->setPlaceholderText(msg); m_lineEdit->setPlaceholderText(msg);
} }
@ -98,11 +104,14 @@ void CUIComponentLineEdit::setInputTips() {
void CUIComponentLineEdit::showRangeError() { void CUIComponentLineEdit::showRangeError() {
if (m_checkRange) { if (m_checkRange) {
QPalette palette = m_lineEdit->palette(); QPalette palette = m_lineEdit->palette();
if (this->inRange(this->getQVFrom(m_lineEdit->text()))) { if (this->inRange(this->getQVFrom(m_lineEdit->text()))) {
palette.setColor(QPalette::Text, Qt::black); palette.setColor(QPalette::Text, Qt::black);
} else { } else {
palette.setColor(QPalette::Text, Qt::red); palette.setColor(QPalette::Text, Qt::red);
} }
m_lineEdit->setPalette(palette); m_lineEdit->setPalette(palette);
} }
} }
@ -118,7 +127,6 @@ void CUIComponentLineEdit::showRangeError() {
void CUIComponentLineEdit::onTextChanged(const QString& text) { void CUIComponentLineEdit::onTextChanged(const QString& text) {
this->showRangeError(); this->showRangeError();
// 如果在范围内,
if (this->inRange(m_lineEdit->text())) { if (this->inRange(m_lineEdit->text())) {
// switch (m_dataType) { // switch (m_dataType) {
// case CUI_DATA_TYPE_DOUBLE: { // case CUI_DATA_TYPE_DOUBLE: {

@ -94,28 +94,59 @@ void CUIConfig::printConfig() {
// qDebug() << "}"; // qDebug() << "}";
} }
QString CUIConfig::getOriginValueString() {
QVariant pValue = property["value_origin"];
// 如果没有设置原始值
if (pValue == QVariant::Invalid) {
return QString("");
}
if (property["value_type"] == CUI_DATA_TYPE_INT) {
int* ptr = qvariant_cast<int*>(pValue);
return QString::number(*ptr);
} else if (property["value_type"] == CUI_DATA_TYPE_DOUBLE) {
double* ptr = qvariant_cast<double*>(pValue);
return QString::number(*ptr);
} else if (property["value_type"] == CUI_DATA_TYPE_STRING) {
QString* ptr = qvariant_cast<QString*>(pValue);
return *ptr;
}
return QString("");
}
void CUIConfig::setValue(QVariant value) { void CUIConfig::setValue(QVariant value) {
bool changed = false; bool changed = false;
QVariant pValue = property["value_origin"]; QVariant pValue = property["value_origin"];
if (property["value_type"] == CUI_DATA_TYPE_INT) { if (property["value_type"] == CUI_DATA_TYPE_INT) {
int* ptr = qvariant_cast<int*>(pValue); int* ptr = qvariant_cast<int*>(pValue);
if (*ptr != value.toInt()) { if (*ptr != value.toInt()) {
*ptr = value.toInt(); *ptr = value.toInt();
changed = true; changed = true;
} }
} else if (property["value_type"] == CUI_DATA_TYPE_DOUBLE) { } 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()) { if (*ptr != value.toDouble()) {
*ptr = value.toDouble(); *ptr = value.toDouble();
changed = true; changed = true;
} }
} else if (property["value_type"] == CUI_DATA_TYPE_STRING) { } else if (property["value_type"] == CUI_DATA_TYPE_STRING) {
double *ptr = qvariant_cast<double *>(pValue); QString* ptr = qvariant_cast<QString*>(pValue);
if (*ptr != value.toDouble()) {
*ptr = value.toDouble(); if (*ptr != value.toString()) {
*ptr = value.toString();
changed = true; changed = true;
} }
} }
// 如果需要通知,则通知参数值发生修改 // 如果需要通知,则通知参数值发生修改
if (changed && this->getPropertyOriginValue("semaphore") != QVariant::Invalid) { if (changed && this->getPropertyOriginValue("semaphore") != QVariant::Invalid) {
QTimer::singleShot(50, m_sigsCenter, [=]() { QTimer::singleShot(50, m_sigsCenter, [=]() {
@ -134,6 +165,7 @@ QString CUIConfig::getPropertyValue(QString key) {
if (property.contains(key)) { if (property.contains(key)) {
return qvariant_cast<QString>(property[key]); return qvariant_cast<QString>(property[key]);
} }
return QString(); return QString();
} }
@ -146,6 +178,7 @@ QVariant CUIConfig::getPropertyOriginValue(QString key) {
if (property.contains(key)) { if (property.contains(key)) {
return property[key]; return property[key];
} }
return QVariant::Invalid; return QVariant::Invalid;
} }
@ -158,6 +191,7 @@ QVector<CUIConfig *> CUIConfig::getSub() {
*/ */
void CUIConfig::setDefault() { void CUIConfig::setDefault() {
QString type = qvariant_cast<QString>(property["type"]); QString type = qvariant_cast<QString>(property["type"]);
if (type == "LineEdit") { if (type == "LineEdit") {
setDefault("name", ""); setDefault("name", "");
setDefault("data_type", "string"); // 数据类型 setDefault("data_type", "string"); // 数据类型
@ -168,15 +202,19 @@ void CUIConfig::setDefault() {
setDefault("inclusive_min", true); // 左范围是否包括 setDefault("inclusive_min", true); // 左范围是否包括
setDefault("inclusive_max", true); // 右范围是否包括 setDefault("inclusive_max", true); // 右范围是否包括
setDefault("required_", true); // 是否为必选 setDefault("required_", true); // 是否为必选
} else if (type == "Widget") { } else if (type == "Widget") {
setDefault("layout", "QVBoxLayout"); setDefault("layout", "QVBoxLayout");
setDefault("name", ""); setDefault("name", "");
} else if (type == "GroupBox") { } else if (type == "GroupBox") {
setDefault("name", ""); setDefault("name", "");
setDefault("layout", "QVBoxLayout"); setDefault("layout", "QVBoxLayout");
} else if (type == "TabWidget") { } else if (type == "TabWidget") {
} else if (type == "ComboBox") { } else if (type == "ComboBox") {
setDefault("name", ""); setDefault("name", "");
} else if (type == "Item") { } else if (type == "Item") {
setDefault("name", ""); setDefault("name", "");
setDefault("data_type", "string"); setDefault("data_type", "string");

@ -18,7 +18,7 @@ class CUIPropertyAPI CUIConfig {
QString getPropertyValue(QString); QString getPropertyValue(QString);
QVariant getPropertyOriginValue(QString); QVariant getPropertyOriginValue(QString);
QVector<CUIConfig*> getSub(); QVector<CUIConfig*> getSub();
QString getOriginValueString();
private: private:
void setDefault(); void setDefault();
void setDefault(QString key, QVariant val); void setDefault(QString key, QVariant val);

Loading…
Cancel
Save