Registered QUuid in the metatype system as a builtin type.

Change-Id: I6be6129d9f6bf468ba8a5805cfa0f6f79199afb3
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Reviewed-by: Prasanth Ullattil <prasanth.ullattil@nokia.com>
This commit is contained in:
Denis Dzyubenko 2012-01-02 16:25:17 +01:00 committed by Qt by Nokia
parent 99eb505103
commit 92f9678055
7 changed files with 73 additions and 3 deletions

View File

@ -50,6 +50,7 @@
#include "qvector.h"
#include "qlocale.h"
#include "qeasingcurve.h"
#include "quuid.h"
#include "qvariant.h"
#include "qmetatypeswitcher_p.h"
@ -788,6 +789,9 @@ bool QMetaType::save(QDataStream &stream, int type, const void *data)
return false;
qMetaTypeWidgetsHelper[type - FirstWidgetsType].saveOp(stream, data);
break;
case QMetaType::QUuid:
stream << *static_cast<const NS(QUuid)*>(data);
break;
default: {
const QVector<QCustomTypeInfo> * const ct = customTypes();
if (!ct)
@ -995,6 +999,9 @@ bool QMetaType::load(QDataStream &stream, int type, void *data)
return false;
qMetaTypeWidgetsHelper[type - FirstWidgetsType].loadOp(stream, data);
break;
case QMetaType::QUuid:
stream >> *static_cast< NS(QUuid)*>(data);
break;
default: {
const QVector<QCustomTypeInfo> * const ct = customTypes();
if (!ct)
@ -1115,6 +1122,8 @@ void *QMetaType::create(int type, const void *copy)
case QMetaType::QEasingCurve:
return new NS(QEasingCurve)(*static_cast<const NS(QEasingCurve)*>(copy));
#endif
case QMetaType::QUuid:
return new NS(QUuid)(*static_cast<const NS(QUuid)*>(copy));
case QMetaType::Void:
return 0;
default:
@ -1212,6 +1221,8 @@ void *QMetaType::create(int type, const void *copy)
case QMetaType::QEasingCurve:
return new NS(QEasingCurve);
#endif
case QMetaType::QUuid:
return new NS(QUuid);
case QMetaType::Void:
return 0;
default:
@ -1379,6 +1390,9 @@ void QMetaType::destroy(int type, void *data)
delete static_cast< NS(QEasingCurve)* >(data);
break;
#endif
case QMetaType::QUuid:
delete static_cast< NS(QUuid)* >(data);
break;
case QMetaType::Void:
break;
default: {

View File

@ -98,6 +98,7 @@ QT_MODULE(Core)
F(QPointF, 26, QPointF) \
F(QRegExp, 27, QRegExp) \
F(QEasingCurve, 29, QEasingCurve) \
F(QUuid, 30, QUuid) \
F(QVariant, 138, QVariant) \
#define QT_FOR_EACH_STATIC_CORE_POINTER(F)\
@ -182,7 +183,7 @@ public:
// these are merged with QVariant
QT_FOR_EACH_STATIC_TYPE(QT_DEFINE_METATYPE_ID)
LastCoreType = QEasingCurve,
LastCoreType = QUuid,
FirstGuiType = QFont,
LastGuiType = QPolygonF,
FirstWidgetsType = QIcon,

View File

@ -52,6 +52,7 @@
#include "qstringlist.h"
#include "qurl.h"
#include "qlocale.h"
#include "quuid.h"
#include "private/qvariant_p.h"
#include "qmetatype_p.h"
@ -345,6 +346,9 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result,
case QVariant::Url:
*str = v_cast<QUrl>(d)->toString();
break;
case QVariant::Uuid:
*str = v_cast<QUuid>(d)->toString();
break;
default:
return false;
}
@ -709,6 +713,15 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result,
return *ok;
}
#endif
case QVariant::Uuid:
switch (d->type) {
case QVariant::String:
*static_cast<QUuid *>(result) = QUuid(*v_cast<QString>(d));
break;
default:
return false;
}
break;
default:
return false;
}
@ -807,6 +820,9 @@ static void streamDebug(QDebug dbg, const QVariant &v)
dbg.nospace() << v.toRectF();
break;
#endif
case QVariant::Uuid:
dbg.nospace() << v.value<QUuid>().toString();
break;
case QVariant::BitArray:
//dbg.nospace() << v.toBitArray();
break;
@ -1073,6 +1089,7 @@ Q_CORE_EXPORT void QVariantPrivate::unregisterHandler(const int /* Modules::Name
\value DateTime a QDateTime
\value Double a double
\value EasingCurve a QEasingCurve
\value Uuid a QUuid
\value Font a QFont
\value Hash a QVariantHash
\value Icon a QIcon
@ -2402,7 +2419,7 @@ static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] =
| 1 << QVariant::UInt | 1 << QVariant::Bool | 1 << QVariant::Double
| 1 << QVariant::Date | 1 << QVariant::Time | 1 << QVariant::DateTime
| 1 << QVariant::LongLong | 1 << QVariant::ULongLong | 1 << QVariant::Char
| 1 << QVariant::Url,
| 1 << QVariant::Url | 1 << QVariant::Uuid,
/*QStringList*/ 1 << QVariant::List | 1 << QVariant::String,
@ -2441,7 +2458,9 @@ static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] =
/*QHash*/ 0,
/*QEasingCurve*/ 0
/*QEasingCurve*/ 0,
/*QUuid*/ 1 << QVariant::String
};
/*!

View File

@ -123,6 +123,7 @@ class Q_CORE_EXPORT QVariant
RegExp = QMetaType::QRegExp,
Hash = QMetaType::QVariantHash,
EasingCurve = QMetaType::QEasingCurve,
Uuid = QMetaType::QUuid,
LastCoreType = QMetaType::LastCoreType,
Font = QMetaType::QFont,

View File

@ -79,6 +79,7 @@
#include "qstringlist.h"
#include "qurl.h"
#include "qlocale.h"
#include "quuid.h"
#ifndef QT_NO_GEOM_VARIANT
#include "qsize.h"

View File

@ -446,6 +446,9 @@ template<> struct TestValueFactory<QMetaType::QPointF> {
template<> struct TestValueFactory<QMetaType::QEasingCurve> {
static QEasingCurve *create() { return new QEasingCurve(QEasingCurve::InOutElastic); }
};
template<> struct TestValueFactory<QMetaType::QUuid> {
static QUuid *create() { return new QUuid(); }
};
template<> struct TestValueFactory<QMetaType::QRegExp> {
static QRegExp *create()
{

View File

@ -76,6 +76,9 @@ private slots:
void hash();
void qvariant();
void qvariant_conversion();
public:
// Variables
QUuid uuidA;
@ -327,7 +330,35 @@ void tst_QUuid::hash()
QCOMPARE(qHash(QUuid(uuidA.toString())), h);
}
void tst_QUuid::qvariant()
{
QUuid uuid = QUuid::createUuid();
QVariant v = QVariant::fromValue(uuid);
QVERIFY(!v.isNull());
QCOMPARE(v.type(), QVariant::Uuid);
QUuid uuid2 = v.value<QUuid>();
QVERIFY(!uuid2.isNull());
QCOMPARE(uuid, uuid2);
}
void tst_QUuid::qvariant_conversion()
{
QUuid uuid = QUuid::createUuid();
QVariant v = QVariant::fromValue(uuid);
QVERIFY(v.canConvert<QString>());
QCOMPARE(v.toString(), uuid.toString());
QCOMPARE(v.value<QString>(), uuid.toString());
QVERIFY(!v.canConvert<int>());
QVERIFY(!v.canConvert<QStringList>());
// try reverse conversion QString -> QUuid
QVariant sv = QVariant::fromValue(uuid.toString());
QCOMPARE(sv.type(), QVariant::String);
QVERIFY(sv.canConvert<QUuid>());
QCOMPARE(sv.value<QUuid>(), uuid);
}
QTEST_MAIN(tst_QUuid)
#include "tst_quuid.moc"