summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetatype.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel/qmetatype.cpp')
-rw-r--r--src/corelib/kernel/qmetatype.cpp108
1 files changed, 77 insertions, 31 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index fc9053520c..7ddf187b88 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -63,6 +63,11 @@
# include "qurl.h"
# include "qvariant.h"
# include "qabstractitemmodel.h"
+# include "qregularexpression.h"
+# include "qjsonvalue.h"
+# include "qjsonobject.h"
+# include "qjsonarray.h"
+# include "qjsondocument.h"
#endif
#ifndef QT_NO_GEOM_VARIANT
@@ -110,10 +115,17 @@ template<> struct TypeDefinition<QBitArray> { static const bool IsAvailable = fa
template<> struct TypeDefinition<QUrl> { static const bool IsAvailable = false; };
template<> struct TypeDefinition<QEasingCurve> { static const bool IsAvailable = false; };
template<> struct TypeDefinition<QModelIndex> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QJsonValue> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QJsonObject> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QJsonArray> { static const bool IsAvailable = false; };
+template<> struct TypeDefinition<QJsonDocument> { static const bool IsAvailable = false; };
#endif
#ifdef QT_NO_REGEXP
template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = false; };
#endif
+#if defined(QT_BOOTSTRAPPED) || defined(QT_NO_REGEXP)
+template<> struct TypeDefinition<QRegularExpression> { static const bool IsAvailable = false; };
+#endif
} // namespace
/*!
@@ -219,6 +231,7 @@ template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = fals
\value QPoint QPoint
\value QUrl QUrl
\value QRegExp QRegExp
+ \value QRegularExpression QRegularExpression
\value QDateTime QDateTime
\value QPointF QPointF
\value QPalette QPalette
@@ -240,8 +253,13 @@ template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = fals
\value QVector4D QVector4D
\value QQuaternion QQuaternion
\value QEasingCurve QEasingCurve
+ \value QJsonValue QJsonValue
+ \value QJsonObject QJsonObject
+ \value QJsonArray QJsonArray
+ \value QJsonDocument QJsonDocument
\value User Base value for user types
+ \value UnknownType This is an invalid type id. It is returned from QMetaType for types that are not registered
\omitvalue FirstGuiType
\omitvalue FirstWidgetsType
@@ -311,7 +329,7 @@ static const struct { const char * typeName; int typeNameLength; int type; } typ
QT_FOR_EACH_STATIC_TYPE(QT_ADD_STATIC_METATYPE)
QT_FOR_EACH_STATIC_ALIAS_TYPE(QT_ADD_STATIC_METATYPE_ALIASES_ITER)
QT_FOR_EACH_STATIC_HACKS_TYPE(QT_ADD_STATIC_METATYPE_HACKS_ITER)
- {0, 0, QMetaType::Void}
+ {0, 0, QMetaType::UnknownType}
};
Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper = 0;
@@ -348,10 +366,7 @@ Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
void QMetaType::registerStreamOperators(const char *typeName, SaveOperator saveOp,
LoadOperator loadOp)
{
- int idx = type(typeName);
- if (!idx)
- return;
- registerStreamOperators(idx, saveOp, loadOp);
+ registerStreamOperators(type(typeName), saveOp, loadOp);
}
/*! \internal
@@ -435,7 +450,7 @@ static int qMetaTypeCustomType_unlocked(const char *typeName, int length)
{
const QVector<QCustomTypeInfo> * const ct = customTypes();
if (!ct)
- return 0;
+ return QMetaType::UnknownType;
for (int v = 0; v < ct->count(); ++v) {
const QCustomTypeInfo &customInfo = ct->at(v);
@@ -446,7 +461,7 @@ static int qMetaTypeCustomType_unlocked(const char *typeName, int length)
return v + QMetaType::User;
}
}
- return 0;
+ return QMetaType::UnknownType;
}
/*! \internal
@@ -457,7 +472,7 @@ static int qMetaTypeCustomType_unlocked(const char *typeName, int length)
int QMetaType::registerType(const char *typeName, Deleter deleter,
Creator creator)
{
- return registerType(typeName, deleter, creator, qMetaTypeDestructHelper<void>, qMetaTypeConstructHelper<void>, 0, TypeFlags());
+ return registerType(typeName, deleter, creator, qMetaTypeDestructHelper<void>, qMetaTypeConstructHelper<void>, 0, TypeFlags(), 0);
}
/*! \internal
@@ -472,8 +487,9 @@ int QMetaType::registerType(const char *typeName, Deleter deleter,
Creator creator,
Destructor destructor,
Constructor constructor,
- int size, TypeFlags flags)
+ int size, TypeFlags flags, const QMetaObject *metaObject)
{
+ Q_UNUSED(metaObject);
QVector<QCustomTypeInfo> *ct = customTypes();
if (!ct || !typeName || !deleter || !creator || !destructor || !constructor)
return -1;
@@ -489,11 +505,11 @@ int QMetaType::registerType(const char *typeName, Deleter deleter,
int previousSize = 0;
int previousFlags = 0;
- if (!idx) {
+ if (idx == UnknownType) {
QWriteLocker locker(customTypesLock());
idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
normalizedTypeName.size());
- if (!idx) {
+ if (idx == UnknownType) {
QCustomTypeInfo inf;
inf.typeName = normalizedTypeName;
inf.creator = creator;
@@ -559,12 +575,12 @@ int QMetaType::registerTypedef(const char* typeName, int aliasId)
int idx = qMetaTypeStaticType(normalizedTypeName.constData(),
normalizedTypeName.size());
- if (!idx) {
+ if (idx == UnknownType) {
QWriteLocker locker(customTypesLock());
idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
normalizedTypeName.size());
- if (!idx) {
+ if (idx == UnknownType) {
QCustomTypeInfo inf;
inf.typeName = normalizedTypeName;
inf.alias = aliasId;
@@ -593,17 +609,20 @@ int QMetaType::registerTypedef(const char* typeName, int aliasId)
*/
bool QMetaType::isRegistered(int type)
{
- if (type >= 0 && type < User) {
- // predefined type
+ // predefined type
+ if ((type >= FirstCoreType && type <= LastCoreType)
+ || (type >= FirstGuiType && type <= LastGuiType)
+ || (type >= FirstWidgetsType && type <= LastWidgetsType)) {
return true;
}
+
QReadLocker locker(customTypesLock());
const QVector<QCustomTypeInfo> * const ct = customTypes();
return ((type >= User) && (ct && ct->count() > type - User) && !ct->at(type - User).typeName.isEmpty());
}
/*!
- Returns a handle to the type called \a typeName, or 0 if there is
+ Returns a handle to the type called \a typeName, or QMetaType::UnknownType if there is
no such type.
\sa isRegistered(), typeName(), Type
@@ -612,17 +631,17 @@ int QMetaType::type(const char *typeName)
{
int length = qstrlen(typeName);
if (!length)
- return 0;
+ return UnknownType;
int type = qMetaTypeStaticType(typeName, length);
- if (!type) {
+ if (type == UnknownType) {
QReadLocker locker(customTypesLock());
type = qMetaTypeCustomType_unlocked(typeName, length);
#ifndef QT_NO_QOBJECT
- if (!type) {
+ if (type == UnknownType) {
const NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
type = qMetaTypeStaticType(normalizedTypeName.constData(),
normalizedTypeName.size());
- if (!type) {
+ if (type == UnknownType) {
type = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
normalizedTypeName.size());
}
@@ -653,11 +672,16 @@ bool QMetaType::save(QDataStream &stream, int type, const void *data)
return false;
switch(type) {
+ case QMetaType::UnknownType:
case QMetaType::Void:
case QMetaType::VoidStar:
case QMetaType::QObjectStar:
case QMetaType::QWidgetStar:
case QMetaType::QModelIndex:
+ case QMetaType::QJsonValue:
+ case QMetaType::QJsonObject:
+ case QMetaType::QJsonArray:
+ case QMetaType::QJsonDocument:
return false;
case QMetaType::Long:
stream << qlonglong(*static_cast<const long *>(data));
@@ -779,10 +803,15 @@ bool QMetaType::save(QDataStream &stream, int type, const void *data)
break;
#endif
#ifndef QT_BOOTSTRAPPED
+#ifndef QT_NO_REGEXP
+ case QMetaType::QRegularExpression:
+ stream << *static_cast<const NS(QRegularExpression)*>(data);
+ break;
+#endif // QT_NO_REGEXP
case QMetaType::QEasingCurve:
stream << *static_cast<const NS(QEasingCurve)*>(data);
break;
-#endif
+#endif // QT_BOOTSTRAPPED
case QMetaType::QFont:
case QMetaType::QPixmap:
case QMetaType::QBrush:
@@ -858,11 +887,16 @@ bool QMetaType::load(QDataStream &stream, int type, void *data)
return false;
switch(type) {
+ case QMetaType::UnknownType:
case QMetaType::Void:
case QMetaType::VoidStar:
case QMetaType::QObjectStar:
case QMetaType::QWidgetStar:
case QMetaType::QModelIndex:
+ case QMetaType::QJsonValue:
+ case QMetaType::QJsonObject:
+ case QMetaType::QJsonArray:
+ case QMetaType::QJsonDocument:
return false;
case QMetaType::Long: {
qlonglong l;
@@ -990,10 +1024,15 @@ bool QMetaType::load(QDataStream &stream, int type, void *data)
break;
#endif
#ifndef QT_BOOTSTRAPPED
+#ifndef QT_NO_REGEXP
+ case QMetaType::QRegularExpression:
+ stream >> *static_cast< NS(QRegularExpression)*>(data);
+ break;
+#endif // QT_NO_REGEXP
case QMetaType::QEasingCurve:
stream >> *static_cast< NS(QEasingCurve)*>(data);
break;
-#endif
+#endif // QT_BOOTSTRAPPED
case QMetaType::QFont:
case QMetaType::QPixmap:
case QMetaType::QBrush:
@@ -1084,6 +1123,7 @@ public:
template<typename T>
void *delegate(const T *copy) { return CreatorImpl<T>::Create(m_type, copy); }
void *delegate(const void*) { return 0; }
+ void *delegate(const QMetaTypeSwitcher::UnknownType *) { return 0; }
void *delegate(const QMetaTypeSwitcher::NotBuiltinType *copy)
{
QMetaType::Creator creator;
@@ -1146,6 +1186,7 @@ public:
template<typename T>
void delegate(const T *where) { DestroyerImpl<T>::Destroy(m_type, const_cast<T*>(where)); }
void delegate(const void *) {}
+ void delegate(const QMetaTypeSwitcher::UnknownType*) {}
void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestroyer(m_type, (void*)where); }
private:
@@ -1209,6 +1250,7 @@ public:
template<typename T>
void *delegate(const T *copy) { return ConstructorImpl<T>::Construct(m_type, m_where, copy); }
void *delegate(const void *) { return m_where; }
+ void *delegate(const QMetaTypeSwitcher::UnknownType*) { return m_where; }
void *delegate(const QMetaTypeSwitcher::NotBuiltinType *copy) { return customTypeConstructor(m_type, m_where, copy); }
private:
@@ -1298,6 +1340,7 @@ public:
template<typename T>
void delegate(const T *where) { DestructorImpl<T>::Destruct(m_type, const_cast<T*>(where)); }
void delegate(const void *) {}
+ void delegate(const QMetaTypeSwitcher::UnknownType*) {}
void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestructor(m_type, (void*)where); }
private:
@@ -1367,6 +1410,7 @@ public:
template<typename T>
int delegate(const T*) { return SizeOfImpl<T>::Size(m_type); }
+ int delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; }
int delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeSizeOf(m_type); }
private:
static int customTypeSizeOf(const int type)
@@ -1433,6 +1477,7 @@ public:
template<typename T>
quint32 delegate(const T*) { return FlagsImpl<T>::Flags(m_type); }
quint32 delegate(const void*) { return 0; }
+ quint32 delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; }
quint32 delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeFlags(m_type); }
private:
const int m_type;
@@ -1620,6 +1665,7 @@ public:
template<typename T>
void delegate(const T*) { TypeInfoImpl<T>(m_type, info); }
void delegate(const void*) {}
+ void delegate(const QMetaTypeSwitcher::UnknownType*) {}
void delegate(const QMetaTypeSwitcher::NotBuiltinType*) { customTypeInfo(m_type); }
private:
void customTypeInfo(const uint type)
@@ -1640,7 +1686,7 @@ QMetaType QMetaType::typeInfo(const int type)
{
TypeInfo typeInfo(type);
QMetaTypeSwitcher::switcher<void>(typeInfo, type, 0);
- return typeInfo.info.creator || !type ? QMetaType(QMetaType::NoExtensionFlags
+ return typeInfo.info.creator || type == Void ? QMetaType(QMetaType::NoExtensionFlags
, static_cast<const QMetaTypeInterface *>(0) // typeInfo::info is a temporary variable, we can't return address of it.
, typeInfo.info.creator
, typeInfo.info.deleter
@@ -1650,27 +1696,25 @@ QMetaType QMetaType::typeInfo(const int type)
, typeInfo.info.destructor
, typeInfo.info.size
, typeInfo.info.flags
- , type)
- : QMetaType(-1);
+ , type
+ , 0)
+ : QMetaType(UnknownType);
}
QMetaType::QMetaType(const int typeId)
: m_typeId(typeId)
{
- if (Q_UNLIKELY(typeId == -1)) {
+ if (Q_UNLIKELY(typeId == UnknownType)) {
// Constructs invalid QMetaType instance.
m_extensionFlags = 0xffffffff;
Q_ASSERT(!isValid());
} else {
// TODO it can be better.
*this = QMetaType::typeInfo(typeId);
- if (m_typeId > 0 && !m_creator) {
+ if (m_typeId == UnknownType)
m_extensionFlags = 0xffffffff;
- m_typeId = -1;
- }
- if (m_typeId == QMetaType::Void) {
+ else if (m_typeId == QMetaType::Void)
m_extensionFlags = CreateEx | DestroyEx | ConstructEx | DestructEx;
- }
}
}
@@ -1686,6 +1730,7 @@ QMetaType::QMetaType(const QMetaType &other)
, m_typeFlags(other.m_typeFlags)
, m_extensionFlags(other.m_extensionFlags)
, m_typeId(other.m_typeId)
+ , m_metaObject(other.m_metaObject)
{}
QMetaType &QMetaType::operator =(const QMetaType &other)
@@ -1701,6 +1746,7 @@ QMetaType &QMetaType::operator =(const QMetaType &other)
m_extensionFlags = other.m_extensionFlags;
m_extension = other.m_extension; // space reserved for future use
m_typeId = other.m_typeId;
+ m_metaObject = other.m_metaObject;
return *this;
}