diff options
author | Jędrzej Nowacki <jedrzej.nowacki@nokia.com> | 2012-05-04 15:19:17 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-08 11:47:29 +0200 |
commit | 1e432f0a88b25098819fc9684b54606ba3a05123 (patch) | |
tree | dc01912358b31857ce9edea706a57e0c7015d726 /src/corelib/kernel/qvariant.cpp | |
parent | 4169e20662d0bcf52d6a278f85f44f9dacad7a68 (diff) |
Introduce a new built-in type: signed char.
C++ distinguish between "char", "signed char" and
"unsigned char", they are three independent types.
Fix QVariant behavior on ARM. On ARM "char" may mean
"unsigned char", but we depends on the sign during
a numerical conversions.
Change-Id: I610ce3fb88ed5964b67f3ae442d264fe16b2d261
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qvariant.cpp')
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 0b3e0418d0..30ca728208 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -152,6 +152,8 @@ static qlonglong qMetaTypeNumber(const QVariant::Private *d) return d->data.ll; case QMetaType::Char: return qlonglong(d->data.c); + case QMetaType::SChar: + return qlonglong(d->data.sc); case QMetaType::Short: return qlonglong(d->data.s); case QMetaType::Long: @@ -199,6 +201,7 @@ static qlonglong qConvertToNumber(const QVariant::Private *d, bool *ok) case QVariant::Double: case QVariant::Int: case QMetaType::Char: + case QMetaType::SChar: case QMetaType::Short: case QMetaType::Long: case QMetaType::Float: @@ -232,6 +235,7 @@ static qulonglong qConvertToUnsignedNumber(const QVariant::Private *d, bool *ok) case QVariant::Double: case QVariant::Int: case QMetaType::Char: + case QMetaType::SChar: case QMetaType::Short: case QMetaType::Long: case QMetaType::Float: @@ -289,6 +293,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) *str = QString(*v_cast<QChar>(d)); break; case QMetaType::Char: + case QMetaType::SChar: case QMetaType::UChar: *str = QChar::fromLatin1(d->data.c); break; @@ -350,6 +355,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) case QVariant::Int: case QVariant::LongLong: case QMetaType::Char: + case QMetaType::SChar: case QMetaType::Short: case QMetaType::Long: case QMetaType::Float: @@ -487,6 +493,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) *ba = QByteArray::number(d->data.f, 'g', FLT_DIG); break; case QMetaType::Char: + case QMetaType::SChar: case QMetaType::UChar: *ba = QByteArray(1, d->data.c); break; @@ -535,6 +542,11 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) *static_cast<qulonglong *>(result) = qConvertToUnsignedNumber(d, ok); return *ok; } + case QMetaType::SChar: { + signed char s = qConvertToNumber(d, ok); + *static_cast<signed char*>(result) = s; + return *ok; + } case QMetaType::UChar: { *static_cast<uchar *>(result) = qConvertToUnsignedNumber(d, ok); return *ok; @@ -555,6 +567,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) case QVariant::Int: case QVariant::LongLong: case QMetaType::Char: + case QMetaType::SChar: case QMetaType::Short: case QMetaType::Long: case QMetaType::Float: @@ -591,6 +604,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) case QVariant::LongLong: case QVariant::Int: case QMetaType::Char: + case QMetaType::SChar: case QMetaType::Short: case QMetaType::Long: *f = double(qMetaTypeNumber(d)); @@ -626,6 +640,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) case QVariant::LongLong: case QVariant::Int: case QMetaType::Char: + case QMetaType::SChar: case QMetaType::Short: case QMetaType::Long: *f = float(qMetaTypeNumber(d)); @@ -2440,11 +2455,17 @@ static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] = bool QVariant::canConvert(int targetTypeId) const { // TODO Reimplement this function, currently it works but it is a historical mess. - const uint currentType = ((d.type == QMetaType::Float) ? QVariant::Double : d.type); + uint currentType = ((d.type == QMetaType::Float) ? QVariant::Double : 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 == uint(targetTypeId)) return true; + if (targetTypeId < 0 || targetTypeId >= QMetaType::User) return false; @@ -2452,12 +2473,16 @@ bool QVariant::canConvert(int targetTypeId) const if (currentType > int(QMetaType::QUuid) || targetTypeId > int(QMetaType::QUuid)) { switch (uint(targetTypeId)) { case QVariant::Int: - return currentType == QVariant::KeySequence - || currentType == QMetaType::ULong + if (currentType == QVariant::KeySequence) + return true; + // fall through + case QVariant::UInt: + return currentType == QMetaType::ULong || currentType == QMetaType::Long || currentType == QMetaType::UShort || currentType == QMetaType::UChar || currentType == QMetaType::Char + || currentType == QMetaType::SChar || currentType == QMetaType::Short; case QVariant::Image: return currentType == QVariant::Pixmap || currentType == QVariant::Bitmap; @@ -2482,6 +2507,7 @@ bool QVariant::canConvert(int targetTypeId) const return currentType == QVariant::Color || currentType == QVariant::Pixmap; case QMetaType::Long: case QMetaType::Char: + case QMetaType::SChar: case QMetaType::UChar: case QMetaType::ULong: case QMetaType::Short: |