|
|
|
@ -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("");
|
|
|
|
|