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

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

@ -16,7 +16,9 @@ protected:
// 初始化配置
void initSetting();
// 判断是否在范围内
bool inRange();
bool inRange(QVariant v);
// 将当前的值修改为QVarivat变量
QVariant getQVFrom(QString str);
// 初始化UI
virtual void initUI();
// 初始化值校验器
@ -36,11 +38,11 @@ protected:
// 具体值
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;
// 是否包含右值

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

Loading…
Cancel
Save