diff --git a/src/blackgui/models/columnformatters.cpp b/src/blackgui/models/columnformatters.cpp index aaa9b6a07..60fe88d01 100644 --- a/src/blackgui/models/columnformatters.cpp +++ b/src/blackgui/models/columnformatters.cpp @@ -406,7 +406,28 @@ namespace BlackGui CVariant CIntegerFormatter::displayRole(const CVariant &expectedInteger) const { - return QString::number(expectedInteger.toInt()); + bool ok = false; + switch (expectedInteger.type()) + { + case QMetaType::LongLong: + { + const qlonglong ll = expectedInteger.toLongLong(&ok); + if (ok) { return QString::number(ll); } + break; + } + case QMetaType::ULongLong: + { + const qulonglong ll = expectedInteger.toULongLong(&ok); + if (ok) { return QString::number(ll); } + break; + } + default: + break; + } + + const int i = expectedInteger.toInt(&ok); + if (ok) { return QString::number(i); } + return CVariant(); } } // namespace } // namespace diff --git a/src/blackmisc/timestampbased.cpp b/src/blackmisc/timestampbased.cpp index 5d3270dc3..ccd7bcfdf 100644 --- a/src/blackmisc/timestampbased.cpp +++ b/src/blackmisc/timestampbased.cpp @@ -242,7 +242,7 @@ namespace BlackMisc switch (i) { case IndexUtcTimestamp: this->setUtcTimestamp(variant.toDateTime()); return; - case IndexMSecsSinceEpoch: this->setMSecsSinceEpoch(variant.toInt()); return; + case IndexMSecsSinceEpoch: this->setMSecsSinceEpoch(variant.toQInt64()); return; case IndexUtcTimestampFormattedYmdhms: case IndexUtcTimestampFormattedYmdhmsz: case IndexUtcTimestampFormattedHm: diff --git a/src/blackmisc/variant.cpp b/src/blackmisc/variant.cpp index 193c7c7bd..8991ff9fb 100644 --- a/src/blackmisc/variant.cpp +++ b/src/blackmisc/variant.cpp @@ -69,6 +69,12 @@ namespace BlackMisc return isIntegral() || type() == QMetaType::Float || type() == QMetaType::Double; } + qint64 CVariant::toQInt64(bool *ok) const + { + if (this->type() == QMetaType::LongLong) { return this->toLongLong(ok); } + return this->toInt(ok); + } + 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 2ac8e01a3..1bf2fdf22 100644 --- a/src/blackmisc/variant.h +++ b/src/blackmisc/variant.h @@ -83,6 +83,7 @@ namespace BlackMisc static bool baseIsA(const void *, int) { return false; } }; + // *INDENT-OFF* /*! * When a derived class and a base class both inherit from Mixin::MetaType, * the derived class uses this macro to disambiguate the inherited members. @@ -92,6 +93,7 @@ namespace BlackMisc using ::BlackMisc::Mixin::MetaType::getMetaTypeId; \ using ::BlackMisc::Mixin::MetaType::getClassName; \ using ::BlackMisc::Mixin::MetaType::isA; + // *INDENT-ON* } // Mixin @@ -244,14 +246,26 @@ namespace BlackMisc bool toBool() const { return m_v.toBool(); } //! Convert this variant to an integer. - int toInt() const { return m_v.toInt(); } + int toInt(bool *ok = nullptr) const { return m_v.toInt(ok); } + + //! Convert this variant to a longlong integer. + qlonglong toLongLong(bool *ok = nullptr) const { return m_v.toLongLong(ok); } + + //! Convert this variant to a unsigned longlong integer. + qulonglong toULongLong(bool *ok = nullptr) const { return m_v.toULongLong(ok); } + + //! COnvert to qint64, which is used for all timestamps + qint64 toQInt64(bool *ok = nullptr) const; //! Convert this variant to double. - double toDouble() const { return m_v.toDouble(); } + double toDouble(bool *ok = nullptr) const { return m_v.toDouble(ok); } //! Convert this variant to QDateTime. QDateTime toDateTime() const { return m_v.toDateTime(); } + //! Convert this variant to QUrl. + QUrl toUrl() const { return m_v.toUrl(); } + //! Set the variant to null. void clear() { m_v.clear(); }