mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 08:36:52 +08:00
Using QMetaType::Type instead of QVariant::Type
Auto as per review of refs #319
This commit is contained in:
@@ -136,17 +136,17 @@ namespace BlackGui
|
||||
QVariant CDateTimeFormatter::displayRole(const QVariant &dateTime) const
|
||||
{
|
||||
if (dateTime.isNull()) return "";
|
||||
if (dateTime.type() == QMetaType::QDateTime)
|
||||
if (static_cast<QMetaType::Type>(dateTime.type()) == QMetaType::QDateTime)
|
||||
{
|
||||
QDateTime dt = dateTime.value<QDateTime>();
|
||||
return dt.toString(m_formatString);
|
||||
}
|
||||
else if (dateTime.type() == QMetaType::QDate)
|
||||
else if (static_cast<QMetaType::Type>(dateTime.type()) == QMetaType::QDate)
|
||||
{
|
||||
QDate d = dateTime.value<QDate>();
|
||||
return d.toString(m_formatString);
|
||||
}
|
||||
else if (dateTime.type() == QMetaType::QTime)
|
||||
else if (static_cast<QMetaType::Type>(dateTime.type()) == QMetaType::QTime)
|
||||
{
|
||||
QTime t = dateTime.value<QTime>();
|
||||
return t.toString(m_formatString);
|
||||
|
||||
@@ -232,7 +232,8 @@ int BlackMisc::compareQVariants(const QVariant &v1, const QVariant &v2)
|
||||
if (v1.type() != v2.type()) qFatal("Mismatching types");
|
||||
if (v1.userType() != v2.userType()) qFatal("Mismatching user types");
|
||||
|
||||
switch (v1.type())
|
||||
auto v1Type = static_cast<QMetaType::Type>(v1.type());
|
||||
switch (v1Type)
|
||||
{
|
||||
case QMetaType::QString:
|
||||
case QMetaType::QChar:
|
||||
@@ -274,7 +275,7 @@ int BlackMisc::compareQVariants(const QVariant &v1, const QVariant &v2)
|
||||
}
|
||||
|
||||
// BlackObject
|
||||
if (v1.type() == QVariant::UserType)
|
||||
if (v1Type == QMetaType::User)
|
||||
{
|
||||
const CValueObject *cs1 = CValueObject::fromQVariant(v1);
|
||||
const CValueObject *cs2 = CValueObject::fromQVariant(v2);
|
||||
@@ -285,28 +286,28 @@ int BlackMisc::compareQVariants(const QVariant &v1, const QVariant &v2)
|
||||
}
|
||||
|
||||
// integer types, handling not as double for rounding issues
|
||||
if (v1.type() == QVariant::Int)
|
||||
if (v1Type == QMetaType::Int)
|
||||
{
|
||||
int i1 = v1.value<int>();
|
||||
int i2 = v2.value<int>();
|
||||
if (i1 == i2) return 0;
|
||||
return i1 < i2 ? -1 : 1;
|
||||
}
|
||||
else if (v1.type() == QVariant::UInt)
|
||||
else if (v1Type == QMetaType::UInt)
|
||||
{
|
||||
uint i1 = v1.value<uint>();
|
||||
uint i2 = v2.value<uint>();
|
||||
if (i1 == i2) return 0;
|
||||
return i1 < i2 ? -1 : 1;
|
||||
}
|
||||
else if (v1.type() == QVariant::LongLong)
|
||||
else if (v1Type == QMetaType::LongLong)
|
||||
{
|
||||
long long i1 = v1.value<long long>();
|
||||
long long i2 = v2.value<long long>();
|
||||
if (i1 == i2) return 0;
|
||||
return i1 < i2 ? -1 : 1;
|
||||
}
|
||||
else if (v1.type() == QVariant::ULongLong)
|
||||
else if (v1Type == QMetaType::ULongLong)
|
||||
{
|
||||
unsigned long long i1 = v1.value<unsigned long long>();
|
||||
unsigned long long i2 = v2.value<unsigned long long>();
|
||||
|
||||
@@ -156,7 +156,7 @@ namespace BlackMisc
|
||||
this->m_variant = variant;
|
||||
break;
|
||||
case IndexIcon:
|
||||
if (variant.type() == QMetaType::Int)
|
||||
if (static_cast<QMetaType::Type>(variant.type()) == QMetaType::Int)
|
||||
{
|
||||
CIcons::IconIndex index = static_cast<CIcons::IconIndex>(variant.toInt());
|
||||
this->m_icon = CIconList::iconForIndex(index);
|
||||
|
||||
@@ -106,10 +106,10 @@ namespace BlackMisc
|
||||
const CValueObject *CValueObject::fromQVariant(const QVariant &variant)
|
||||
{
|
||||
if (!variant.isValid()) return nullptr;
|
||||
QVariant::Type t = variant.type();
|
||||
auto t = static_cast<QMetaType::Type>(variant.type());
|
||||
uint ut = variant.userType();
|
||||
if (t != QVariant::UserType) return nullptr; // not a user type
|
||||
if (ut <= QVariant::UserType) return nullptr; // complex Qt type
|
||||
if (t != QMetaType::User) return nullptr; // not a user type
|
||||
if (ut <= static_cast<uint>(QMetaType::User)) return nullptr; // complex Qt type
|
||||
if (variant.canConvert<QDBusArgument>()) return nullptr; // not unstreamed yet
|
||||
|
||||
// this cast cannot be dynamic, so the above conditions are crucical
|
||||
|
||||
@@ -134,6 +134,7 @@ namespace BlackMisc
|
||||
bool isValid() const { return m_v.isValid(); }
|
||||
|
||||
//! Return the metatype ID of the value in this variant, or QMetaType::User if it is a user type.
|
||||
// KB we should think about returning QMetaType::Type directly, as QVariant::Type is deprecated
|
||||
QVariant::Type type() const { return m_v.type(); }
|
||||
|
||||
//! Return the typename of the value in this variant.
|
||||
|
||||
Reference in New Issue
Block a user