mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 08:55:43 +08:00
Ref T297, allow "null" values as value
This commit is contained in:
@@ -29,7 +29,6 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
namespace PhysicalQuantities
|
namespace PhysicalQuantities
|
||||||
{
|
{
|
||||||
|
|
||||||
QString CPqString::convertToQString(bool /** i18n **/) const
|
QString CPqString::convertToQString(bool /** i18n **/) const
|
||||||
{
|
{
|
||||||
return this->m_string;
|
return this->m_string;
|
||||||
@@ -40,7 +39,7 @@ namespace BlackMisc
|
|||||||
CVariant v;
|
CVariant v;
|
||||||
|
|
||||||
// fine tuning of the string
|
// fine tuning of the string
|
||||||
QString vs = value.trimmed().simplified();
|
const QString vs = value.trimmed().simplified();
|
||||||
|
|
||||||
// check
|
// check
|
||||||
if (vs.isEmpty()) { return v; }
|
if (vs.isEmpty()) { return v; }
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
namespace PhysicalQuantities
|
namespace PhysicalQuantities
|
||||||
{
|
{
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Represents a physical quantity by a string
|
* Represents a physical quantity by a string
|
||||||
* \details Used to parse strings into physical quantities, validate strings
|
* \details Used to parse strings into physical quantities, validate strings
|
||||||
@@ -63,15 +62,16 @@ namespace BlackMisc
|
|||||||
//! Parse into concrete type
|
//! Parse into concrete type
|
||||||
template <class PQ> static PQ parse(const QString &value, SeparatorMode mode = SeparatorsCLocale)
|
template <class PQ> static PQ parse(const QString &value, SeparatorMode mode = SeparatorsCLocale)
|
||||||
{
|
{
|
||||||
PQ invalid;
|
PQ null;
|
||||||
invalid.setNull();
|
null.setNull();
|
||||||
if (value.isEmpty()) return invalid;
|
if (value.isEmpty()) {return null; }
|
||||||
CVariant qv = parseToVariant(value, mode);
|
if (value.contains("null", Qt::CaseInsensitive)) { return null; }
|
||||||
|
const CVariant qv = parseToVariant(value, mode);
|
||||||
if (!qv.isNull() && qv.canConvert<PQ>())
|
if (!qv.isNull() && qv.canConvert<PQ>())
|
||||||
{
|
{
|
||||||
return qv.value<PQ>();
|
return qv.value<PQ>();
|
||||||
}
|
}
|
||||||
return invalid;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Locale aware parsing
|
//! Locale aware parsing
|
||||||
@@ -85,9 +85,8 @@ namespace BlackMisc
|
|||||||
BLACK_METAMEMBER(string)
|
BLACK_METAMEMBER(string)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
} // ns
|
||||||
}
|
} // ns
|
||||||
}
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CPqString)
|
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CPqString)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user