1、LineEdit的bug

feature/struct-menu-20241023
mzh 2 weeks ago
parent e96e425651
commit b8235ee635

@ -24,6 +24,8 @@ CUIConfig *CFDStructDataSolverTimeModeManager::getParamUIConfig()
delete m_uiConfig; delete m_uiConfig;
m_uiConfig = nullptr; m_uiConfig = nullptr;
} }
// qDebug()<<m_mcyc;
// 如果是定常 // 如果是定常
if (m_runtype == 0) { if (m_runtype == 0) {
m_uiConfig = this->genSteadyModeUIConfig(); m_uiConfig = this->genSteadyModeUIConfig();
@ -58,7 +60,7 @@ CUIConfig *CFDStructDataSolverTimeModeManager::genSteadyModeUIConfig()
new CUIConfig({ new CUIConfig({
{"type", "LineEdit"}, {"type", "LineEdit"},
{"name", "iteration count"}, {"name", "iteration count"},
{"value_type", "Int"}, {"value_type", CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_mcyc)}, {"value_origin", QVA_GLOBAL(&m_mcyc)},
}) })
}); });
@ -87,31 +89,31 @@ CUIConfig *CFDStructDataSolverTimeModeManager::genUnsteadyModeUIConfig()
new CUIConfig({ new CUIConfig({
{"type", "LineEdit"}, {"type", "LineEdit"},
{"name", "alf0"}, {"name", "alf0"},
{"value_type", "Double"}, {"value_type", CUI_DATA_TYPE_DOUBLE},
{"value_origin", QVA_GLOBAL(&m_alf0)}, {"value_origin", QVA_GLOBAL(&m_alf0)},
}), }),
new CUIConfig({ new CUIConfig({
{"type", "LineEdit"}, {"type", "LineEdit"},
{"name", "realdt"}, {"name", "realdt"},
{"value_type", "Double"}, {"value_type", CUI_DATA_TYPE_DOUBLE},
{"value_origin", QVA_GLOBAL(&m_realdt)}, {"value_origin", QVA_GLOBAL(&m_realdt)},
}), }),
new CUIConfig({ new CUIConfig({
{"type", "LineEdit"}, {"type", "LineEdit"},
{"name", "nstep"}, {"name", "nstep"},
{"value_type", "Int"}, {"value_type", CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_nstep)}, {"value_origin", QVA_GLOBAL(&m_nstep)},
}), }),
new CUIConfig({ new CUIConfig({
{"type", "LineEdit"}, {"type", "LineEdit"},
{"name", "mcyc"}, {"name", "mcyc"},
{"value_type", "Int"}, {"value_type", CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_mcyc)}, {"value_origin", QVA_GLOBAL(&m_mcyc)},
}), }),
new CUIConfig({ new CUIConfig({
{"type", "CheckBox"}, {"type", "CheckBox"},
{"name", "Time Average"}, {"name", "Time Average"},
{"value_type", "Int"}, {"value_type", CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_timeaverage)}, {"value_origin", QVA_GLOBAL(&m_timeaverage)},
}) })
}); });

@ -10,12 +10,16 @@ void CUIComponentBase::initSetting()
if (!m_conf) { if (!m_conf) {
return; return;
} }
m_dataType = (CUI_DATA_TYPE)m_conf->getPropertyOriginValue("m_dataType").toInt(); m_dataType = (CUI_DATA_TYPE)m_conf->getPropertyOriginValue("value_type").toInt();
if(m_conf->getPropertyValue("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"); m_value = m_conf->getPropertyOriginValue("initial_value");
} }
// 初始化是否必填 // 初始化是否必填
if(m_conf->getPropertyValue("required") != QVariant::Invalid) { if(m_conf->getPropertyOriginValue("required") != QVariant::Invalid) {
m_required = m_conf->getPropertyOriginValue("required").toBool(); m_required = m_conf->getPropertyOriginValue("required").toBool();
} }
if(m_dataType == CUI_DATA_TYPE_STRING) { if(m_dataType == CUI_DATA_TYPE_STRING) {
@ -23,7 +27,7 @@ void CUIComponentBase::initSetting()
return; return;
} }
// 是否检查范围 // 是否检查范围
if(m_conf->getPropertyValue("check_range") != QVariant::Invalid) { if(m_conf->getPropertyOriginValue("check_range") != QVariant::Invalid) {
m_checkRange = m_conf->getPropertyOriginValue("check_range").toBool(); m_checkRange = m_conf->getPropertyOriginValue("check_range").toBool();
} }
// 左值和右值是否包含 // 左值和右值是否包含
@ -36,49 +40,72 @@ void CUIComponentBase::initSetting()
// 初始化左值和右值 // 初始化左值和右值
if (m_checkRange) { if (m_checkRange) {
if(m_conf->getPropertyOriginValue("range_min") != QVariant::Invalid) { if(m_conf->getPropertyOriginValue("range_min") != QVariant::Invalid) {
m_rangeMin = m_conf->getPropertyValue("range_min"); m_rangeMin = m_conf->getPropertyOriginValue("range_min");
} else { } else {
if (m_dataType == CUI_DATA_TYPE_INT) { if (m_dataType == CUI_DATA_TYPE_INT) {
m_rangeMin = INT_MIN; m_rangeMin = INT_MIN;
} else if (m_dataType == CUI_DATA_TYPE_DOUBLE) { } else if (m_dataType == CUI_DATA_TYPE_DOUBLE) {
m_rangeMin = DBL_MIN; 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->getPropertyValue("range_max"); m_rangeMax = m_conf->getPropertyOriginValue("range_max");
} else { } else {
qDebug()<<"Base init min";
if (m_dataType == CUI_DATA_TYPE_INT) { if (m_dataType == CUI_DATA_TYPE_INT) {
m_rangeMin = INT_MAX; m_rangeMax = INT_MAX;
} else if (m_dataType == CUI_DATA_TYPE_DOUBLE) { } else if (m_dataType == CUI_DATA_TYPE_DOUBLE) {
m_rangeMin = DBL_MAX; m_rangeMax = DBL_MAX;
} }
} }
} }
} }
bool CUIComponentBase::inRange() bool CUIComponentBase::inRange(QVariant v)
{ {
if(m_checkRange) { if(m_checkRange) {
// 如果包含最小值,但是修改后的值小于最小值,则不在范围内 // 如果包含最小值,但是修改后的值小于最小值,则不在范围内
if (m_inclusiveMin && m_value < m_rangeMin ) { if (m_inclusiveMin && v < m_rangeMin ) {
return false; return false;
} }
// 如果不包含最小值,但是修改后的值小于等于最小值,则不在范围内 // 如果不包含最小值,但是修改后的值小于等于最小值,则不在范围内
if (!m_inclusiveMin && m_value <= m_rangeMin ) { if (!m_inclusiveMin && v <= m_rangeMin ) {
return false; return false;
} }
// 如果包含最大值,但是修改后的值大于最大值,则不在范围内 // 如果包含最大值,但是修改后的值大于最大值,则不在范围内
if (m_inclusiveMax && m_value > m_rangeMax ) { if (m_inclusiveMax && v > m_rangeMax ) {
return false; return false;
} }
// 如果不包含最大值,但是修改后的值大于等于最大值,则不在范围内 // 如果不包含最大值,但是修改后的值大于等于最大值,则不在范围内
if (!m_inclusiveMax && m_value >= m_rangeMax ) { if (!m_inclusiveMax && v >= m_rangeMax ) {
return false; return false;
} }
} }
return true; return true;
} }
QVariant CUIComponentBase::getQVFrom(QString str)
{
QVariant v;
switch (m_dataType) {
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;
}
}
return v;
}
void CUIComponentBase::initUI() void CUIComponentBase::initUI()
{ {
} }
@ -89,16 +116,13 @@ void CUIComponentBase::initValidator()
QString CUIComponentBase::getValueString() QString CUIComponentBase::getValueString()
{ {
if (m_value == QVariant::Invalid) {
return QString("");
}
if(m_dataType == CUI_DATA_TYPE_STRING) { if(m_dataType == CUI_DATA_TYPE_STRING) {
return m_value.toString(); return m_value.toString();
} }
if(m_dataType == CUI_DATA_TYPE_INT) { if(m_dataType == CUI_DATA_TYPE_INT) {
return QString::number(m_value.toInt()); return QString::number(m_value.toInt());
} }
if(m_dataType == CUI_DATA_TYPE_STRING) { if(m_dataType == CUI_DATA_TYPE_DOUBLE) {
return QString::number(m_value.toDouble()); return QString::number(m_value.toDouble());
} }
return QString(""); return QString("");
@ -106,16 +130,13 @@ QString CUIComponentBase::getValueString()
QString CUIComponentBase::getRangeMinString() QString CUIComponentBase::getRangeMinString()
{ {
if (m_rangeMin == QVariant::Invalid) {
return QString("");
}
if(m_dataType == CUI_DATA_TYPE_STRING) { if(m_dataType == CUI_DATA_TYPE_STRING) {
return m_rangeMin.toString(); return m_rangeMin.toString();
} }
if(m_dataType == CUI_DATA_TYPE_INT) { if(m_dataType == CUI_DATA_TYPE_INT) {
return QString::number(m_rangeMin.toInt()); return QString::number(m_rangeMin.toInt());
} }
if(m_dataType == CUI_DATA_TYPE_STRING) { if(m_dataType == CUI_DATA_TYPE_DOUBLE) {
return QString::number(m_rangeMin.toDouble()); return QString::number(m_rangeMin.toDouble());
} }
return QString(""); return QString("");
@ -123,16 +144,13 @@ QString CUIComponentBase::getRangeMinString()
QString CUIComponentBase::getRangeMaxString() QString CUIComponentBase::getRangeMaxString()
{ {
if (m_rangeMax == QVariant::Invalid) {
return QString("");
}
if(m_dataType == CUI_DATA_TYPE_STRING) { if(m_dataType == CUI_DATA_TYPE_STRING) {
return m_rangeMax.toString(); return m_rangeMax.toString();
} }
if(m_dataType == CUI_DATA_TYPE_INT) { if(m_dataType == CUI_DATA_TYPE_INT) {
return QString::number(m_rangeMax.toInt()); return QString::number(m_rangeMax.toInt());
} }
if(m_dataType == CUI_DATA_TYPE_STRING) { if(m_dataType == CUI_DATA_TYPE_DOUBLE) {
return QString::number(m_rangeMax.toDouble()); return QString::number(m_rangeMax.toDouble());
} }
return QString(""); return QString("");

@ -16,7 +16,9 @@ protected:
// 初始化配置 // 初始化配置
void initSetting(); void initSetting();
// 判断是否在范围内 // 判断是否在范围内
bool inRange(); bool inRange(QVariant v);
// 将当前的值修改为QVarivat变量
QVariant getQVFrom(QString str);
// 初始化UI // 初始化UI
virtual void initUI(); virtual void initUI();
// 初始化值校验器 // 初始化值校验器
@ -36,11 +38,11 @@ protected:
// 具体值 // 具体值
QVariant m_value = QVariant::Invalid; QVariant m_value = QVariant::Invalid;
// 是否检查范围 // 是否检查范围
bool m_checkRange = false; bool m_checkRange = true;
// 左值 // 左值
QVariant m_rangeMin; QVariant m_rangeMin = INT_MIN;
// 右值 // 右值
QVariant m_rangeMax; QVariant m_rangeMax = INT_MAX;
// 是否包含左值 // 是否包含左值
bool m_inclusiveMin = false; bool m_inclusiveMin = false;
// 是否包含右值 // 是否包含右值

@ -17,9 +17,10 @@
CUIComponentLineEdit::CUIComponentLineEdit(CUIConfig *conf, CUIComponentLineEdit::CUIComponentLineEdit(CUIConfig *conf,
QVector<CUIPropertyWidget *> &subCUI, QVector<CUIPropertyWidget *> &subCUI,
QWidget *parent) QWidget *parent)
: CUIComponentBaseWidget(parent) : CUIComponentBaseWidget(parent),CUIComponentBase()
{ {
this->m_conf = conf; this->m_conf = conf;
this->initSetting();
this->initUI(subCUI); this->initUI(subCUI);
} }
@ -52,6 +53,7 @@ void CUIComponentLineEdit::initUI(QVector<CUIPropertyWidget *> &subCUI)
m_lineEdit = new QLineEdit(this->getValueString()); m_lineEdit = new QLineEdit(this->getValueString());
m_layout->addWidget(m_label); m_layout->addWidget(m_label);
m_layout->addWidget(m_lineEdit); m_layout->addWidget(m_lineEdit);
// m_dataType = static_cast<CUI_DATA_TYPE>(this->m_conf->getPropertyOriginValue("data_type").toInt());
this->setLayout(m_layout); this->setLayout(m_layout);
// 设置格式校验 // 设置格式校验
this->setValidator(); this->setValidator();
@ -62,13 +64,16 @@ void CUIComponentLineEdit::initUI(QVector<CUIPropertyWidget *> &subCUI)
void CUIComponentLineEdit::setValidator() void CUIComponentLineEdit::setValidator()
{ {
switch (m_dataType) { qDebug()<<m_dataType;
switch ((int)m_dataType) {
case CUI_DATA_TYPE_DOUBLE: { case CUI_DATA_TYPE_DOUBLE: {
qDebug()<<m_rangeMin.toInt()<<' '<< m_rangeMax.toInt();
m_lineEdit->setValidator(new QDoubleValidator(m_rangeMin.toDouble(), m_lineEdit->setValidator(new QDoubleValidator(m_rangeMin.toDouble(),
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();
m_lineEdit->setValidator( m_lineEdit->setValidator(
new QIntValidator(m_rangeMin.toInt(), m_rangeMax.toInt())); new QIntValidator(m_rangeMin.toInt(), m_rangeMax.toInt()));
break; break;
@ -100,7 +105,7 @@ void CUIComponentLineEdit::showRangeError()
{ {
if (m_checkRange) { if (m_checkRange) {
QPalette palette = m_lineEdit->palette(); QPalette palette = m_lineEdit->palette();
if (this->inRange()) { 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);
@ -120,21 +125,23 @@ void CUIComponentLineEdit::showRangeError()
void CUIComponentLineEdit::onTextChanged(const QString &text) void CUIComponentLineEdit::onTextChanged(const QString &text)
{ {
this->showRangeError(); this->showRangeError();
if (this->inRange()) { if (this->inRange(m_lineEdit->text())) {
switch (m_dataType) { // switch (m_dataType) {
case CUI_DATA_TYPE_DOUBLE: { // case CUI_DATA_TYPE_DOUBLE: {
m_value = qvariant_cast<double>(m_lineEdit->text().toDouble()); // m_value = qvariant_cast<double>(m_lineEdit->text().toDouble());
break; // break;
} // }
case CUI_DATA_TYPE_INT: { // case CUI_DATA_TYPE_INT: {
m_value = qvariant_cast<int>(m_lineEdit->text().toInt()); //// qDebug()<< qvariant_cast<int>(m_lineEdit->text().toInt());
break; // m_value = qvariant_cast<int>(m_lineEdit->text().toInt());
} // break;
case CUI_DATA_TYPE_STRING: { // }
m_value = m_lineEdit->text(); // case CUI_DATA_TYPE_STRING: {
break; // m_value = m_lineEdit->text();
} // break;
} // }
// }
m_value = this->getQVFrom(m_lineEdit->text());
this->setValueToOrigin(); this->setValueToOrigin();
} }
} }

Loading…
Cancel
Save