refs #466 Resolved TODO item in GUI.

This commit is contained in:
Mathew Sutcliffe
2015-09-14 22:58:04 +01:00
parent b1a3793c2f
commit f03b24022e
3 changed files with 25 additions and 3 deletions

View File

@@ -186,10 +186,9 @@ namespace BlackGui
QTime t = dateTime.value<QTime>(); QTime t = dateTime.value<QTime>();
return t.toString(m_formatString); return t.toString(m_formatString);
} }
else if (static_cast<QMetaType::Type>(dateTime.type()) == QMetaType::Int) else if (dateTime.isIntegral())
{ {
//! \todo potential risk if int is not qint64 QDateTime t = QDateTime::fromMSecsSinceEpoch(dateTime.value<qint64>());
QDateTime t = QDateTime::fromMSecsSinceEpoch(dateTime.toInt());
return t.toString(m_formatString); return t.toString(m_formatString);
} }
else else

View File

@@ -37,6 +37,23 @@ namespace BlackMisc
return m_v.toString(); return m_v.toString();
} }
bool CVariant::isIntegral() const
{
switch (type())
{
case QMetaType::Bool: case QMetaType::Char: case QMetaType::UChar: case QMetaType::SChar: case QMetaType::Short: case QMetaType::UShort:
case QMetaType::Int: case QMetaType::UInt: case QMetaType::Long: case QMetaType::ULong: case QMetaType::LongLong: case QMetaType::ULongLong:
return true;
default:
return false;
}
}
bool CVariant::isArithmetic() const
{
return isIntegral() || type() == QMetaType::Float || type() == QMetaType::Double;
}
int CVariant::compareImpl(const CVariant &a, const CVariant &b) int CVariant::compareImpl(const CVariant &a, const CVariant &b)
{ {
if (a.userType() < b.userType()) { return -1; } if (a.userType() < b.userType()) { return -1; }

View File

@@ -231,6 +231,12 @@ namespace BlackMisc
//! \copydoc CValueObject::convertToQString //! \copydoc CValueObject::convertToQString
QString convertToQString(bool i18n = false) const; QString convertToQString(bool i18n = false) const;
//! True if this variant's type is an integral type.
bool isIntegral() const;
//! True if this variant's type is an integral or floating-point type.
bool isArithmetic() const;
//! Convert this variant to a bool. //! Convert this variant to a bool.
bool toBool() const { return m_v.toBool(); } bool toBool() const { return m_v.toBool(); }