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 | |
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')
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 7 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 7 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 32 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.h | 1 |
4 files changed, 40 insertions, 7 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 2756dd5241..448b6e3938 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -161,6 +161,7 @@ struct DefinedTypesFilter { \value ULong \c{unsigned long} \value ULongLong ULongLong \value UShort \c{unsigned short} + \value SChar \c{signed char} \value UChar \c{unsigned char} \value Float \c float \value QObjectStar QObject * @@ -718,6 +719,9 @@ bool QMetaType::save(QDataStream &stream, int type, const void *data) case QMetaType::UShort: stream << *static_cast<const ushort *>(data); break; + case QMetaType::SChar: + stream << *static_cast<const signed char *>(data); + break; case QMetaType::UChar: stream << *static_cast<const uchar *>(data); break; @@ -937,6 +941,9 @@ bool QMetaType::load(QDataStream &stream, int type, void *data) case QMetaType::UShort: stream >> *static_cast<ushort *>(data); break; + case QMetaType::SChar: + stream >> *static_cast<signed char *>(data); + break; case QMetaType::UChar: stream >> *static_cast<uchar *>(data); break; diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 595da53562..33e7fa43f1 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -77,6 +77,7 @@ QT_BEGIN_NAMESPACE F(UShort, 36, ushort) \ F(UChar, 37, uchar) \ F(Float, 38, float) \ + F(SChar, 49, signed char) \ #define QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(F)\ F(VoidStar, 31, void*) \ @@ -160,8 +161,7 @@ QT_BEGIN_NAMESPACE F(UChar, -1, uchar, "unsigned char") \ F(LongLong, -1, qlonglong, "long long") \ F(ULongLong, -1, qulonglong, "unsigned long long") \ - F(Char, -1, char, "qint8") \ - F(Char, -1, char, "signed char") \ + F(SChar, -1, signed char, "qint8") \ F(UChar, -1, uchar, "quint8") \ F(Short, -1, short, "qint16") \ F(UShort, -1, ushort, "quint16") \ @@ -205,7 +205,7 @@ public: QT_FOR_EACH_STATIC_TYPE(QT_DEFINE_METATYPE_ID) FirstCoreType = Bool, - LastCoreType = QJsonDocument, + LastCoreType = SChar, FirstGuiType = QFont, LastGuiType = QPolygonF, FirstWidgetsType = QIcon, @@ -821,7 +821,6 @@ QT_END_NAMESPACE Q_DECLARE_BUILTIN_METATYPE(Name, MetaTypeName) QT_FOR_EACH_STATIC_TYPE(QT_DECLARE_BUILTIN_METATYPE_ITER) -Q_DECLARE_BUILTIN_METATYPE(signed char, Char) #undef QT_DECLARE_BUILTIN_METATYPE_ITER 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: diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index cd8ac9823d..67cec6875a 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -360,6 +360,7 @@ class Q_CORE_EXPORT QVariant char c; uchar uc; short s; + signed char sc; ushort us; int i; uint u; |