From f03b24022ecbecb2780036e72d7cfdd21f472272 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 14 Sep 2015 22:58:04 +0100 Subject: [PATCH] refs #466 Resolved TODO item in GUI. --- src/blackgui/models/columnformatters.cpp | 5 ++--- src/blackmisc/variant.cpp | 17 +++++++++++++++++ src/blackmisc/variant.h | 6 ++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/blackgui/models/columnformatters.cpp b/src/blackgui/models/columnformatters.cpp index e074333e6..c2323b30b 100644 --- a/src/blackgui/models/columnformatters.cpp +++ b/src/blackgui/models/columnformatters.cpp @@ -186,10 +186,9 @@ namespace BlackGui QTime t = dateTime.value(); return t.toString(m_formatString); } - else if (static_cast(dateTime.type()) == QMetaType::Int) + else if (dateTime.isIntegral()) { - //! \todo potential risk if int is not qint64 - QDateTime t = QDateTime::fromMSecsSinceEpoch(dateTime.toInt()); + QDateTime t = QDateTime::fromMSecsSinceEpoch(dateTime.value()); return t.toString(m_formatString); } else diff --git a/src/blackmisc/variant.cpp b/src/blackmisc/variant.cpp index 8844d2c6c..5ccfc8196 100644 --- a/src/blackmisc/variant.cpp +++ b/src/blackmisc/variant.cpp @@ -37,6 +37,23 @@ namespace BlackMisc 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) { if (a.userType() < b.userType()) { return -1; } diff --git a/src/blackmisc/variant.h b/src/blackmisc/variant.h index 741eeb2d3..fed2ebc56 100644 --- a/src/blackmisc/variant.h +++ b/src/blackmisc/variant.h @@ -231,6 +231,12 @@ namespace BlackMisc //! \copydoc CValueObject::convertToQString 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. bool toBool() const { return m_v.toBool(); }