Treat shorts as int in QVariant::canConvert()
Follow the pattern of char and float, and treat shorts as a more generic type in QVariant::canConvert() Task-number: QTBUG-60914 Change-Id: Ib1cc7941ee47cb0fc0098f22f98a03cd6f6b63fe Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
d28c241ca1
commit
00674a1643
|
|
@ -3523,13 +3523,19 @@ bool QVariant::canConvert(int targetTypeId) const
|
|||
}
|
||||
|
||||
// TODO Reimplement this function, currently it works but it is a historical mess.
|
||||
uint currentType = ((d.type == QMetaType::Float) ? QVariant::Double : d.type);
|
||||
uint currentType = d.type;
|
||||
if (currentType == QMetaType::SChar || currentType == QMetaType::Char)
|
||||
currentType = QMetaType::UInt;
|
||||
if (targetTypeId == QMetaType::SChar || currentType == QMetaType::Char)
|
||||
targetTypeId = QMetaType::UInt;
|
||||
if (uint(targetTypeId) == uint(QMetaType::Float)) targetTypeId = QVariant::Double;
|
||||
|
||||
if (currentType == QMetaType::Short || currentType == QMetaType::UShort)
|
||||
currentType = QMetaType::Int;
|
||||
if (targetTypeId == QMetaType::Short || currentType == QMetaType::UShort)
|
||||
targetTypeId = QMetaType::Int;
|
||||
if (currentType == QMetaType::Float)
|
||||
currentType = QMetaType::Double;
|
||||
if (targetTypeId == QMetaType::Float)
|
||||
targetTypeId = QMetaType::Double;
|
||||
|
||||
if (currentType == uint(targetTypeId))
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -525,6 +525,12 @@ void tst_QVariant::canConvert_data()
|
|||
var = QVariant::fromValue<signed char>(-1);
|
||||
QTest::newRow("SChar")
|
||||
<< var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y;
|
||||
var = QVariant((short)-3);
|
||||
QTest::newRow("Short")
|
||||
<< var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << Y << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y;
|
||||
var = QVariant((ushort)7);
|
||||
QTest::newRow("UShort")
|
||||
<< var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << Y << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y;
|
||||
var = QVariant::fromValue<QJsonValue>(QJsonValue(QStringLiteral("hello")));
|
||||
QTest::newRow("JsonValue")
|
||||
<< var << N << N << Y << N << N << N << N << N << N << Y << N << N << Y << N << N << Y << Y << Y << N << N << N << N << N << N << N << N << Y << N << N << Y << Y;
|
||||
|
|
@ -563,6 +569,8 @@ void tst_QVariant::toInt_data()
|
|||
QTest::newRow( "char" ) << QVariant::fromValue('a') << int('a') << true;
|
||||
signed char signedChar = -13;
|
||||
QTest::newRow( "signed char" ) << QVariant::fromValue(signedChar) << -13 << true;
|
||||
QTest::newRow( "short" ) << QVariant::fromValue(short(-7)) << int(-7) << true;
|
||||
QTest::newRow( "ushort" ) << QVariant::fromValue(ushort(30000)) << 30000 << true;
|
||||
QTest::newRow( "double" ) << QVariant( 3.1415927 ) << 3 << true;
|
||||
QTest::newRow( "float" ) << QVariant( 3.1415927f ) << 3 << true;
|
||||
QTest::newRow( "uint" ) << QVariant( 123u ) << 123 << true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue