Ref T297, allow "null" values as value

This commit is contained in:
Klaus Basan
2018-08-04 23:46:23 +02:00
parent b671c2a0a5
commit 1f17b49e6a
2 changed files with 9 additions and 11 deletions

View File

@@ -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; }

View File

@@ -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)