summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qeventloop.cpp41
-rw-r--r--src/corelib/kernel/qeventloop.h1
-rw-r--r--src/corelib/kernel/qmetatype.cpp20
-rw-r--r--src/corelib/kernel/qmetatype.h75
-rw-r--r--src/corelib/kernel/qmetatype_p.h47
-rw-r--r--src/corelib/kernel/qmetatypeswitcher_p.h31
-rw-r--r--src/corelib/kernel/qobject.cpp6
-rw-r--r--src/corelib/kernel/qobject_impl.h1
-rw-r--r--src/corelib/kernel/qobjectdefs.h2
-rw-r--r--src/corelib/kernel/qvariant.cpp98
-rw-r--r--src/corelib/kernel/qvariant.h20
-rw-r--r--src/corelib/kernel/qvariant_p.h11
12 files changed, 145 insertions, 208 deletions
diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp
index 8b0ec85679..dfdd178c35 100644
--- a/src/corelib/kernel/qeventloop.cpp
+++ b/src/corelib/kernel/qeventloop.cpp
@@ -322,28 +322,51 @@ class QEventLoopLockerPrivate
{
public:
explicit QEventLoopLockerPrivate(QEventLoopPrivate *loop)
- : loop(loop), app(0)
+ : loop(loop), type(EventLoop)
{
loop->ref();
}
+ explicit QEventLoopLockerPrivate(QThreadPrivate *thread)
+ : thread(thread), type(Thread)
+ {
+ thread->ref();
+ }
+
explicit QEventLoopLockerPrivate(QCoreApplicationPrivate *app)
- : loop(0), app(app)
+ : app(app), type(Application)
{
app->ref();
}
~QEventLoopLockerPrivate()
{
- if (loop)
+ switch (type)
+ {
+ case EventLoop:
loop->deref();
- else
+ break;
+ case Thread:
+ thread->deref();
+ break;
+ default:
app->deref();
+ break;
+ }
}
private:
- QEventLoopPrivate *loop;
- QCoreApplicationPrivate *app;
+ union {
+ QEventLoopPrivate * loop;
+ QThreadPrivate * thread;
+ QCoreApplicationPrivate * app;
+ };
+ enum Type {
+ EventLoop,
+ Thread,
+ Application
+ };
+ const Type type;
};
/*!
@@ -390,6 +413,12 @@ QEventLoopLocker::QEventLoopLocker(QEventLoop *loop)
}
+QEventLoopLocker::QEventLoopLocker(QThread *thread)
+ : d_ptr(new QEventLoopLockerPrivate(static_cast<QThreadPrivate*>(QObjectPrivate::get(thread))))
+{
+
+}
+
/*!
Destroys this event loop locker object
*/
diff --git a/src/corelib/kernel/qeventloop.h b/src/corelib/kernel/qeventloop.h
index 0e7195d6a7..ba082d7d9d 100644
--- a/src/corelib/kernel/qeventloop.h
+++ b/src/corelib/kernel/qeventloop.h
@@ -96,6 +96,7 @@ class Q_CORE_EXPORT QEventLoopLocker
public:
QEventLoopLocker();
explicit QEventLoopLocker(QEventLoop *loop);
+ explicit QEventLoopLocker(QThread *thread);
~QEventLoopLocker();
private:
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index a1baf28f10..003ad1c32d 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -1290,7 +1290,7 @@ namespace {
class TypeDestroyer {
template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted>
struct DestroyerImpl {
- static void Destroy(const int /* type */, T *where) { delete where; }
+ static void Destroy(const int /* type */, void *where) { qMetaTypeDeleteHelper<T>(where); }
};
template<typename T>
struct DestroyerImpl<T, /* IsAcceptedType = */ false> {
@@ -1318,7 +1318,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 *where) { customTypeDestroyer(m_type, (void*)where); }
+ void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestroyer(m_type, (void*)where); }
private:
static void customTypeDestroyer(const int type, void *where)
@@ -1354,11 +1354,11 @@ namespace {
class TypeConstructor {
template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted>
struct ConstructorImpl {
- static void *Construct(const int /*type*/, void *where, const T *copy) { return qMetaTypeConstructHelper(where, copy); }
+ static void *Construct(const int /*type*/, void *where, const void *copy) { return qMetaTypeConstructHelper<T>(where, copy); }
};
template<typename T>
struct ConstructorImpl<T, /* IsAcceptedType = */ false> {
- static void *Construct(const int type, void *where, const T *copy)
+ static void *Construct(const int type, void *where, const void *copy)
{
if (QTypeModuleInfo<T>::IsGui)
return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor(where, copy) : 0;
@@ -1380,7 +1380,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 *copy) { return customTypeConstructor(m_type, m_where, copy); }
+ void *delegate(const QMetaTypeSwitcher::NotBuiltinType *copy) { return customTypeConstructor(m_type, m_where, copy); }
private:
static void *customTypeConstructor(const int type, void *where, const void *copy)
@@ -1440,7 +1440,7 @@ namespace {
class TypeDestructor {
template<typename T, bool IsAcceptedType = DefinedTypesFilter::Acceptor<T>::IsAccepted>
struct DestructorImpl {
- static void Destruct(const int /* type */, T *where) { qMetaTypeDestructHelper(where); }
+ static void Destruct(const int /* type */, void *where) { qMetaTypeDestructHelper<T>(where); }
};
template<typename T>
struct DestructorImpl<T, /* IsAcceptedType = */ false> {
@@ -1468,7 +1468,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 *where) { customTypeDestructor(m_type, (void*)where); }
+ void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestructor(m_type, (void*)where); }
private:
static void customTypeDestructor(const int type, void *where)
@@ -1536,7 +1536,7 @@ public:
template<typename T>
int delegate(const T*) { return SizeOfImpl<T>::Size(m_type); }
- int delegate(const QMetaTypeSwitcher::UnknownType*) { return customTypeSizeOf(m_type); }
+ int delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeSizeOf(m_type); }
private:
static int customTypeSizeOf(const int type)
{
@@ -1606,7 +1606,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 customTypeFlags(m_type); }
+ quint32 delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeFlags(m_type); }
private:
const int m_type;
static quint32 customTypeFlags(const int type)
@@ -1793,7 +1793,7 @@ public:
template<typename T>
void delegate(const T*) { TypeInfoImpl<T>(m_type, info); }
void delegate(const void*) {}
- void delegate(const QMetaTypeSwitcher::UnknownType*) { customTypeInfo(m_type); }
+ void delegate(const QMetaTypeSwitcher::NotBuiltinType*) { customTypeInfo(m_type); }
private:
void customTypeInfo(const uint type)
{
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index 4af77fcedc..beb7294abd 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -200,14 +200,7 @@ public:
LastWidgetsType = QSizePolicy,
HighestInternalId = LastWidgetsType,
-// This logic must match the one in qglobal.h
-#if defined(QT_COORD_TYPE)
- QReal = 0,
-#elif defined(QT_NO_FPU) || defined(Q_PROCESSOR_ARM) || defined(Q_OS_WINCE)
- QReal = Float,
-#else
- QReal = Double,
-#endif
+ QReal = sizeof(qreal) == sizeof(double) ? Double : Float,
User = 256
};
@@ -318,46 +311,57 @@ private:
Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaType::TypeFlags)
template <typename T>
-void qMetaTypeDeleteHelper(T *t)
+void qMetaTypeDeleteHelper(void *t)
{
- delete t;
+ delete static_cast<T*>(t);
}
+template <> inline void qMetaTypeDeleteHelper<void>(void *) {}
template <typename T>
-void *qMetaTypeCreateHelper(const T *t)
+void *qMetaTypeCreateHelper(const void *t)
{
if (t)
return new T(*static_cast<const T*>(t));
return new T();
}
+template <> inline void *qMetaTypeCreateHelper<void>(const void *) { return 0; }
+
template <typename T>
-void qMetaTypeDestructHelper(T *t)
+void qMetaTypeDestructHelper(void *t)
{
Q_UNUSED(t) // Silence MSVC that warns for POD types.
- t->~T();
+ static_cast<T*>(t)->~T();
}
+template <> inline void qMetaTypeDestructHelper<void>(void *) {}
+
template <typename T>
-void *qMetaTypeConstructHelper(void *where, const T *t)
+void *qMetaTypeConstructHelper(void *where, const void *t)
{
if (t)
return new (where) T(*static_cast<const T*>(t));
return new (where) T;
}
+template <> inline void *qMetaTypeConstructHelper<void>(void *, const void *) { return 0; }
+
#ifndef QT_NO_DATASTREAM
template <typename T>
-void qMetaTypeSaveHelper(QDataStream &stream, const T *t)
+void qMetaTypeSaveHelper(QDataStream &stream, const void *t)
{
- stream << *t;
+ stream << *static_cast<const T*>(t);
}
+template <> inline void qMetaTypeSaveHelper<void>(QDataStream &, const void *) {}
+
template <typename T>
-void qMetaTypeLoadHelper(QDataStream &stream, T *t)
+void qMetaTypeLoadHelper(QDataStream &stream, void *t)
{
- stream >> *t;
+ stream >> *static_cast<T*>(t);
}
+
+template <> inline void qMetaTypeLoadHelper<void>(QDataStream &, void *) {}
#endif // QT_NO_DATASTREAM
template <typename T>
@@ -442,15 +446,6 @@ int qRegisterMetaType(const char *typeName
if (typedefOf != -1)
return QMetaType::registerTypedef(typeName, typedefOf);
- typedef void*(*CreatePtr)(const T*);
- CreatePtr cptr = qMetaTypeCreateHelper<T>;
- typedef void(*DeletePtr)(T*);
- DeletePtr dptr = qMetaTypeDeleteHelper<T>;
- typedef void*(*ConstructPtr)(void *, const T*);
- ConstructPtr ipcptr = qMetaTypeConstructHelper<T>;
- typedef void(*DestructPtr)(T*);
- DestructPtr ipdptr = qMetaTypeDestructHelper<T>;
-
QMetaType::TypeFlags flags;
if (!QTypeInfo<T>::isStatic)
flags |= QMetaType::MovableType;
@@ -461,10 +456,10 @@ int qRegisterMetaType(const char *typeName
if (QtPrivate::IsPointerToTypeDerivedFromQObject<T>::Value)
flags |= QMetaType::PointerToQObject;
- return QMetaType::registerType(typeName, reinterpret_cast<QMetaType::Deleter>(dptr),
- reinterpret_cast<QMetaType::Creator>(cptr),
- reinterpret_cast<QMetaType::Destructor>(ipdptr),
- reinterpret_cast<QMetaType::Constructor>(ipcptr),
+ return QMetaType::registerType(typeName, qMetaTypeDeleteHelper<T>,
+ qMetaTypeCreateHelper<T>,
+ qMetaTypeDestructHelper<T>,
+ qMetaTypeConstructHelper<T>,
sizeof(T),
flags);
}
@@ -477,14 +472,8 @@ void qRegisterMetaTypeStreamOperators(const char *typeName
#endif
)
{
- typedef void(*SavePtr)(QDataStream &, const T *);
- typedef void(*LoadPtr)(QDataStream &, T *);
- SavePtr sptr = qMetaTypeSaveHelper<T>;
- LoadPtr lptr = qMetaTypeLoadHelper<T>;
-
qRegisterMetaType<T>(typeName);
- QMetaType::registerStreamOperators(typeName, reinterpret_cast<QMetaType::SaveOperator>(sptr),
- reinterpret_cast<QMetaType::LoadOperator>(lptr));
+ QMetaType::registerStreamOperators(typeName, qMetaTypeSaveHelper<T>, qMetaTypeLoadHelper<T>);
}
#endif // QT_NO_DATASTREAM
@@ -516,16 +505,8 @@ inline int qRegisterMetaType(
template <typename T>
inline int qRegisterMetaTypeStreamOperators()
{
- typedef void(*SavePtr)(QDataStream &, const T *);
- typedef void(*LoadPtr)(QDataStream &, T *);
- SavePtr sptr = qMetaTypeSaveHelper<T>;
- LoadPtr lptr = qMetaTypeLoadHelper<T>;
-
register int id = qMetaTypeId<T>();
- QMetaType::registerStreamOperators(id,
- reinterpret_cast<QMetaType::SaveOperator>(sptr),
- reinterpret_cast<QMetaType::LoadOperator>(lptr));
-
+ QMetaType::registerStreamOperators(id, qMetaTypeSaveHelper<T>, qMetaTypeLoadHelper<T>);
return id;
}
#endif
diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h
index e48c5d3033..b50521c7a6 100644
--- a/src/corelib/kernel/qmetatype_p.h
+++ b/src/corelib/kernel/qmetatype_p.h
@@ -122,31 +122,6 @@ QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_DECLARE_WIDGETS_MODULE_TYPES_ITER)
class QMetaTypeInterface
{
public:
- template<typename T>
- struct Impl {
- static void *creator(const T *t)
- {
- if (t)
- return new T(*t);
- return new T();
- }
-
- static void deleter(T *t) { delete t; }
- static void saver(QDataStream &stream, const T *t) { stream << *t; }
- static void loader(QDataStream &stream, T *t) { stream >> *t; }
- static void destructor(T *t)
- {
- Q_UNUSED(t) // Silence MSVC that warns for POD types.
- t->~T();
- }
- static void *constructor(void *where, const T *t)
- {
- if (t)
- return new (where) T(*static_cast<const T*>(t));
- return new (where) T;
- }
- };
-
QMetaType::Creator creator;
QMetaType::Deleter deleter;
QMetaType::SaveOperator saveOp;
@@ -157,20 +132,10 @@ public:
quint32 flags; // same as QMetaType::TypeFlags
};
-template<>
-struct QMetaTypeInterface::Impl<void> {
- static void *creator(const void *) { return 0; }
- static void deleter(void *) {}
- static void saver(QDataStream &, const void *) {}
- static void loader(QDataStream &, void *) {}
- static void destructor(void *){}
- static void *constructor(void *, const void *) { return 0; }
-};
-
#ifndef QT_NO_DATASTREAM
# define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
- /*saveOp*/(reinterpret_cast<QMetaType::SaveOperator>(QMetaTypeInterface::Impl<Type>::saver)), \
- /*loadOp*/(reinterpret_cast<QMetaType::LoadOperator>(QMetaTypeInterface::Impl<Type>::loader)),
+ /*saveOp*/(qMetaTypeSaveHelper<Type>), \
+ /*loadOp*/(qMetaTypeLoadHelper<Type>),
# define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \
/*saveOp*/ 0, \
/*loadOp*/ 0,
@@ -184,11 +149,11 @@ struct QMetaTypeInterface::Impl<void> {
#define QT_METATYPE_INTERFACE_INIT_IMPL(Type, DATASTREAM_DELEGATE) \
{ \
- /*creator*/(reinterpret_cast<QMetaType::Creator>(QMetaTypeInterface::Impl<Type>::creator)), \
- /*deleter*/(reinterpret_cast<QMetaType::Deleter>(QMetaTypeInterface::Impl<Type>::deleter)), \
+ /*creator*/(qMetaTypeCreateHelper<Type>), \
+ /*deleter*/(qMetaTypeDeleteHelper<Type>), \
DATASTREAM_DELEGATE(Type) \
- /*constructor*/(reinterpret_cast<QMetaType::Constructor>(QMetaTypeInterface::Impl<Type>::constructor)), \
- /*destructor*/(reinterpret_cast<QMetaType::Destructor>(QMetaTypeInterface::Impl<Type>::destructor)), \
+ /*constructor*/(qMetaTypeConstructHelper<Type>), \
+ /*destructor*/(qMetaTypeDestructHelper<Type>), \
/*size*/(QTypeInfo<Type>::sizeOf), \
/*flags*/(!QTypeInfo<Type>::isStatic * QMetaType::MovableType) \
| (QTypeInfo<Type>::isComplex * QMetaType::NeedsConstruction) \
diff --git a/src/corelib/kernel/qmetatypeswitcher_p.h b/src/corelib/kernel/qmetatypeswitcher_p.h
index c1cccfca63..e9c15ea214 100644
--- a/src/corelib/kernel/qmetatypeswitcher_p.h
+++ b/src/corelib/kernel/qmetatypeswitcher_p.h
@@ -59,46 +59,27 @@ QT_BEGIN_NAMESPACE
class QMetaTypeSwitcher {
public:
-
- typedef void *UnknownType;
+ class NotBuiltinType;
template<class ReturnType, class DelegateObject>
static ReturnType switcher(DelegateObject &logic, int type, const void *data);
};
-#define QT_METATYPE_SWICHER_CASE_PRIMITIVE(TypeName, TypeId, Name)\
- case QMetaType::TypeName: return logic.delegate(static_cast<const Name *>(data));
-
-#define QT_METATYPE_SWICHER_CASE_PRIMITIVE_POINTER(TypeName, TypeId, Name)\
- case QMetaType::TypeName: return logic.delegate(static_cast< Name * const *>(data));
-
-#define QT_METATYPE_SWICHER_CASE_POINTER(TypeName, TypeId, Name)\
- case QMetaType::TypeName: return logic.delegate(static_cast< QT_PREPEND_NAMESPACE(Name) * const *>(data));
-
-#define QT_METATYPE_SWICHER_CASE_QCLASS(TypeName, TypeId, Name)\
- case QMetaType::TypeName: return logic.delegate(static_cast<const QT_PREPEND_NAMESPACE(Name) *>(data));
+#define QT_METATYPE_SWICHER_CASE(TypeName, TypeId, Name)\
+ case QMetaType::TypeName: return logic.delegate(static_cast<Name const *>(data));
template<class ReturnType, class DelegateObject>
ReturnType QMetaTypeSwitcher::switcher(DelegateObject &logic, int type, const void *data)
{
switch (QMetaType::Type(type)) {
- QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(QT_METATYPE_SWICHER_CASE_PRIMITIVE)
- QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(QT_METATYPE_SWICHER_CASE_PRIMITIVE_POINTER)
- QT_FOR_EACH_STATIC_CORE_POINTER(QT_METATYPE_SWICHER_CASE_POINTER)
- QT_FOR_EACH_STATIC_CORE_CLASS(QT_METATYPE_SWICHER_CASE_QCLASS)
- QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_METATYPE_SWICHER_CASE_QCLASS)
- QT_FOR_EACH_STATIC_GUI_CLASS(QT_METATYPE_SWICHER_CASE_QCLASS)
- QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_METATYPE_SWICHER_CASE_QCLASS)
+ QT_FOR_EACH_STATIC_TYPE(QT_METATYPE_SWICHER_CASE)
default:
- return logic.delegate(static_cast<const UnknownType *>(data));
+ return logic.delegate(static_cast<NotBuiltinType const *>(data));
}
}
-#undef QT_METATYPE_SWICHER_CASE_PRIMITIVE
-#undef QT_METATYPE_SWICHER_CASE_PRIMITIVE_POINTER
-#undef QT_METATYPE_SWICHER_CASE_QCLASS
-#undef QT_METATYPE_SWICHER_CASE_POINTER
+#undef QT_METATYPE_SWICHER_CASE
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 252a713872..8fa5dcdcff 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -3617,7 +3617,6 @@ QObjectUserData* QObject::userData(uint id) const
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QObject *o) {
-#ifndef Q_BROKEN_DEBUG_STREAM
if (!o)
return dbg << "QObject(0x0) ";
dbg.nospace() << o->metaObject()->className() << '(' << (void *)o;
@@ -3625,11 +3624,6 @@ QDebug operator<<(QDebug dbg, const QObject *o) {
dbg << ", name = " << o->objectName();
dbg << ')';
return dbg.space();
-#else
- qWarning("This compiler doesn't support streaming QObject to QDebug");
- return dbg;
- Q_UNUSED(o);
-#endif
}
#endif
diff --git a/src/corelib/kernel/qobject_impl.h b/src/corelib/kernel/qobject_impl.h
index 5adffb708f..419fcc1dd4 100644
--- a/src/corelib/kernel/qobject_impl.h
+++ b/src/corelib/kernel/qobject_impl.h
@@ -52,7 +52,6 @@ QT_BEGIN_NAMESPACE
namespace QtPrivate {
template <typename T> struct RemoveRef { typedef T Type; };
- template <typename T> struct RemoveRef<const T&> { typedef T Type; };
template <typename T> struct RemoveRef<T&> { typedef T Type; };
template <typename T> struct RemoveConstRef { typedef T Type; };
template <typename T> struct RemoveConstRef<const T&> { typedef T Type; };
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index 45ef8ab3ca..fa0226917f 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -54,7 +54,7 @@ class QByteArray;
class QString;
#ifndef Q_MOC_OUTPUT_REVISION
-#define Q_MOC_OUTPUT_REVISION 63
+#define Q_MOC_OUTPUT_REVISION 64
#endif
// The following macros are our "extensions" to C++
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 2f67ae9287..5eaa93c7b0 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -279,7 +279,7 @@ inline bool qt_convertToBool(const QVariant::Private *const d)
Converts \a d to type \a t, which is placed in \a result.
*/
-static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, bool *ok)
+static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
{
Q_ASSERT(d->type != uint(t));
Q_ASSERT(result);
@@ -732,7 +732,7 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result,
return true;
}
-#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
+#if !defined(QT_NO_DEBUG_STREAM)
static void streamDebug(QDebug dbg, const QVariant &v)
{
QVariant::Private *d = const_cast<QVariant::Private *>(&v.data_ptr());
@@ -752,7 +752,7 @@ const QVariant::Handler qt_kernel_variant_handler = {
compare,
convert,
0,
-#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
+#if !defined(QT_NO_DEBUG_STREAM)
streamDebug
#else
0
@@ -763,8 +763,8 @@ static void dummyConstruct(QVariant::Private *, const void *) { Q_ASSERT_X(false
static void dummyClear(QVariant::Private *) { Q_ASSERT_X(false, "QVariant", "Trying to clear an unknown type"); }
static bool dummyIsNull(const QVariant::Private *d) { Q_ASSERT_X(false, "QVariant::isNull", "Trying to call isNull on an unknown type"); return d->is_null; }
static bool dummyCompare(const QVariant::Private *, const QVariant::Private *) { Q_ASSERT_X(false, "QVariant", "Trying to compare an unknown types"); return false; }
-static bool dummyConvert(const QVariant::Private *, QVariant::Type , void *, bool *) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); return false; }
-#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
+static bool dummyConvert(const QVariant::Private *, int, void *, bool *) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); return false; }
+#if !defined(QT_NO_DEBUG_STREAM)
static void dummyStreamDebug(QDebug, const QVariant &) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); }
#endif
const QVariant::Handler qt_dummy_variant_handler = {
@@ -778,7 +778,7 @@ const QVariant::Handler qt_dummy_variant_handler = {
dummyCompare,
dummyConvert,
0,
-#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
+#if !defined(QT_NO_DEBUG_STREAM)
dummyStreamDebug
#else
0
@@ -840,14 +840,14 @@ static bool customCompare(const QVariant::Private *a, const QVariant::Private *b
return !memcmp(a_ptr, b_ptr, QMetaType::sizeOf(a->type));
}
-static bool customConvert(const QVariant::Private *, QVariant::Type, void *, bool *ok)
+static bool customConvert(const QVariant::Private *, int, void *, bool *ok)
{
if (ok)
*ok = false;
return false;
}
-#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
+#if !defined(QT_NO_DEBUG_STREAM)
static void customStreamDebug(QDebug, const QVariant &) {}
#endif
@@ -862,7 +862,7 @@ const QVariant::Handler qt_custom_variant_handler = {
customCompare,
customConvert,
0,
-#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
+#if !defined(QT_NO_DEBUG_STREAM)
customStreamDebug
#else
0
@@ -1062,9 +1062,9 @@ Q_CORE_EXPORT void QVariantPrivate::unregisterHandler(const int /* Modules::Name
/*!
- \fn QVariant::QVariant(int typeOrUserType, const void *copy)
+ \fn QVariant::QVariant(int typeId, const void *copy)
- Constructs variant of type \a typeOrUserType, and initializes with
+ Constructs variant of type \a typeId, and initializes with
\a copy if \a copy is not 0.
Note that you have to pass the address of the variable you want stored.
@@ -1162,17 +1162,15 @@ QVariant::QVariant(QDataStream &s)
\fn QVariant::QVariant(const char *val)
Constructs a new variant with a string value of \a val.
- The variant creates a deep copy of \a val, using the encoding
- set by QTextCodec::setCodecForCStrings().
+ The variant creates a deep copy of \a val into a QString assuming
+ UTF-8 encoding on the input \a val.
Note that \a val is converted to a QString for storing in the
- variant and QVariant::type() will return QMetaType::QString for
+ variant and QVariant::userType() will return QMetaType::QString for
the variant.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications.
-
- \sa QTextCodec::setCodecForCStrings()
*/
#ifndef QT_NO_CAST_FROM_ASCII
@@ -1375,19 +1373,19 @@ QVariant::QVariant(const char *val)
QVariant::QVariant(Type type)
{ create(type, 0); }
-QVariant::QVariant(int typeOrUserType, const void *copy)
-{ create(typeOrUserType, copy); d.is_null = false; }
+QVariant::QVariant(int typeId, const void *copy)
+{ create(typeId, copy); d.is_null = false; }
/*! \internal
flags is true if it is a pointer type
*/
-QVariant::QVariant(int typeOrUserType, const void *copy, uint flags)
+QVariant::QVariant(int typeId, const void *copy, uint flags)
{
if (flags) { //type is a pointer type
- d.type = typeOrUserType;
+ d.type = typeId;
d.data.ptr = *reinterpret_cast<void *const*>(copy);
} else {
- create(typeOrUserType, copy);
+ create(typeId, copy);
}
d.is_null = false;
}
@@ -1565,7 +1563,7 @@ void QVariant::detach()
*/
const char *QVariant::typeName() const
{
- return typeToName(Type(d.type));
+ return typeToName(d.type);
}
/*!
@@ -1582,17 +1580,17 @@ void QVariant::clear()
}
/*!
- Converts the enum representation of the storage type, \a typ, to
+ Converts the int representation of the storage type, \a typeId, to
its string representation.
Returns a null pointer if the type is QVariant::Invalid or doesn't exist.
*/
-const char *QVariant::typeToName(Type typ)
+const char *QVariant::typeToName(int typeId)
{
- if (typ == Invalid)
+ if (typeId == Invalid)
return 0;
- return QMetaType::typeName(typ);
+ return QMetaType::typeName(typeId);
}
@@ -1842,7 +1840,7 @@ QDataStream& operator<<(QDataStream &s, const QVariant::Type p)
template <typename T>
inline T qVariantToHelper(const QVariant::Private &d, const HandlersManager &handlerManager)
{
- const QVariant::Type targetType = static_cast<const QVariant::Type>(qMetaTypeId<T>());
+ const uint targetType = qMetaTypeId<T>();
if (d.type == targetType)
return *v_cast<T>(&d);
@@ -2163,7 +2161,7 @@ inline T qNumVariantToHelper(const QVariant::Private &d,
return val;
T ret = 0;
- if (!handlerManager[d.type]->convert(&d, QVariant::Type(t), &ret, ok) && ok)
+ if (!handlerManager[d.type]->convert(&d, t, &ret, ok) && ok)
*ok = false;
return ret;
}
@@ -2407,7 +2405,7 @@ static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] =
/*!
Returns true if the variant's type can be cast to the requested
- type, \a t. Such casting is done automatically when calling the
+ type, \a targetTypeId. Such casting is done automatically when calling the
toInt(), toBool(), ... methods.
The following casts are done automatically:
@@ -2439,18 +2437,18 @@ static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] =
\sa convert()
*/
-bool QVariant::canConvert(Type t) const
+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);
- if (uint(t) == uint(QMetaType::Float)) t = QVariant::Double;
+ if (uint(targetTypeId) == uint(QMetaType::Float)) targetTypeId = QVariant::Double;
- if (currentType == uint(t))
+ if (currentType == uint(targetTypeId))
return true;
// FIXME It should be LastCoreType intead of Uuid
- if (currentType > QVariant::Uuid || t > QVariant::Uuid) {
- switch (uint(t)) {
+ if (currentType > int(QMetaType::QUuid) || targetTypeId > int(QMetaType::QUuid)) {
+ switch (uint(targetTypeId)) {
case QVariant::Int:
return currentType == QVariant::KeySequence
|| currentType == QMetaType::ULong
@@ -2492,14 +2490,14 @@ bool QVariant::canConvert(Type t) const
}
}
- if(t == String && currentType == StringList)
+ if (targetTypeId == String && currentType == StringList)
return v_cast<QStringList>(&d)->count() == 1;
else
- return qCanConvertMatrix[t] & (1 << currentType);
+ return qCanConvertMatrix[targetTypeId] & (1 << currentType);
}
/*!
- Casts the variant to the requested type, \a t. If the cast cannot be
+ Casts the variant to the requested type, \a targetTypeId. If the cast cannot be
done, the variant is cleared. Returns true if the current type of
the variant was successfully cast; otherwise returns false.
@@ -2510,23 +2508,23 @@ bool QVariant::canConvert(Type t) const
\sa canConvert(), clear()
*/
-bool QVariant::convert(Type t)
+bool QVariant::convert(int targetTypeId)
{
- if (d.type == uint(t))
+ if (d.type == uint(targetTypeId))
return true;
QVariant oldValue = *this;
clear();
- if (!oldValue.canConvert(t))
+ if (!oldValue.canConvert(targetTypeId))
return false;
- create(t, 0);
+ create(targetTypeId, 0);
if (oldValue.isNull())
return false;
bool isOk = true;
- if (!handlerManager[d.type]->convert(&oldValue.d, t, data(), &isOk))
+ if (!handlerManager[d.type]->convert(&oldValue.d, targetTypeId, data(), &isOk))
isOk = false;
d.is_null = !isOk;
return isOk;
@@ -2540,7 +2538,7 @@ bool QVariant::convert(Type t)
bool QVariant::convert(const int type, void *ptr) const
{
Q_ASSERT(type < int(QMetaType::User));
- return handlerManager[type]->convert(&d, QVariant::Type(type), ptr, 0);
+ return handlerManager[type]->convert(&d, type, ptr, 0);
}
@@ -2607,7 +2605,7 @@ bool QVariant::cmp(const QVariant &v) const
else
return toLongLong() == v.toLongLong();
}
- if (!v2.canConvert(Type(d.type)) || !v2.convert(Type(d.type)))
+ if (!v2.canConvert(d.type) || !v2.convert(d.type))
return false;
}
return handlerManager[d.type]->compare(&d, &v2.d);
@@ -2646,28 +2644,16 @@ bool QVariant::isNull() const
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QVariant &v)
{
-#ifndef Q_BROKEN_DEBUG_STREAM
dbg.nospace() << "QVariant(" << QMetaType::typeName(v.userType()) << ", ";
handlerManager[v.d.type]->debugStream(dbg, v);
dbg.nospace() << ')';
return dbg.space();
-#else
- qWarning("This compiler doesn't support streaming QVariant to QDebug");
- return dbg;
- Q_UNUSED(v);
-#endif
}
QDebug operator<<(QDebug dbg, const QVariant::Type p)
{
-#ifndef Q_BROKEN_DEBUG_STREAM
dbg.nospace() << "QVariant::" << QMetaType::typeName(p);
return dbg.space();
-#else
- qWarning("This compiler doesn't support streaming QVariant::Type to QDebug");
- return dbg;
- Q_UNUSED(p);
-#endif
}
#endif
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index 5fcfe3e696..5da482d5cd 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -194,8 +194,8 @@ class Q_CORE_EXPORT QVariant
inline QVariant();
~QVariant();
QVariant(Type type);
- QVariant(int typeOrUserType, const void *copy);
- QVariant(int typeOrUserType, const void *copy, uint flags);
+ QVariant(int typeId, const void *copy);
+ QVariant(int typeId, const void *copy, uint flags);
QVariant(const QVariant &other);
#ifndef QT_NO_DATASTREAM
@@ -210,7 +210,7 @@ class Q_CORE_EXPORT QVariant
QVariant(double d);
QVariant(float f) { d.is_null = false; d.type = QMetaType::Float; d.data.f = f; }
#ifndef QT_NO_CAST_FROM_ASCII
- QT_ASCII_CAST_WARN_CONSTRUCTOR QVariant(const char *str);
+ QT_ASCII_CAST_WARN QVariant(const char *str);
#endif
QVariant(const QByteArray &bytearray);
@@ -257,8 +257,8 @@ class Q_CORE_EXPORT QVariant
int userType() const;
const char *typeName() const;
- bool canConvert(Type t) const;
- bool convert(Type t);
+ bool canConvert(int targetTypeId) const;
+ bool convert(int targetTypeId);
inline bool isValid() const;
bool isNull() const;
@@ -311,7 +311,7 @@ class Q_CORE_EXPORT QVariant
void load(QDataStream &ds);
void save(QDataStream &ds) const;
#endif
- static const char *typeToName(Type type);
+ static const char *typeToName(int typeId);
static Type nameToType(const char *name);
void *data();
@@ -331,7 +331,7 @@ class Q_CORE_EXPORT QVariant
template<typename T>
bool canConvert() const
- { return canConvert(Type(qMetaTypeId<T>())); }
+ { return canConvert(qMetaTypeId<T>()); }
public:
#ifndef qdoc
@@ -381,8 +381,8 @@ class Q_CORE_EXPORT QVariant
typedef void (*f_save)(const Private *, QDataStream &);
#endif
typedef bool (*f_compare)(const Private *, const Private *);
- typedef bool (*f_convert)(const QVariant::Private *d, Type t, void *, bool *);
- typedef bool (*f_canConvert)(const QVariant::Private *d, Type t);
+ typedef bool (*f_convert)(const QVariant::Private *d, int t, void *, bool *);
+ typedef bool (*f_canConvert)(const QVariant::Private *d, int t);
typedef void (*f_debugStream)(QDebug, const QVariant &);
struct Handler {
f_construct construct;
@@ -527,7 +527,7 @@ namespace QtPrivate {
return *reinterpret_cast<const T *>(v.constData());
if (vid < int(QMetaType::User)) {
T t;
- if (v.convert(QVariant::Type(vid), &t))
+ if (v.convert(vid, &t))
return t;
}
return T();
diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h
index cdae8997a7..a754bc4363 100644
--- a/src/corelib/kernel/qvariant_p.h
+++ b/src/corelib/kernel/qvariant_p.h
@@ -188,7 +188,7 @@ public:
}
bool delegate(const void*) { return true; }
-
+ bool delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return false; }
protected:
const QVariant::Private *m_a;
const QVariant::Private *m_b;
@@ -282,6 +282,7 @@ public:
}
// we need that as sizof(void) is undefined and it is needed in HasIsNullMethod
bool delegate(const void *) { return m_d->is_null; }
+ bool delegate(const QMetaTypeSwitcher::NotBuiltinType *) { return m_d->is_null; }
protected:
const QVariant::Private *m_d;
};
@@ -345,7 +346,7 @@ public:
FilteredConstructor<T>(*this);
}
- void delegate(const QMetaTypeSwitcher::UnknownType*)
+ void delegate(const QMetaTypeSwitcher::NotBuiltinType*)
{
qWarning("Trying to construct an instance of an invalid type, type id: %i", m_x->type);
m_x->type = QVariant::Invalid;
@@ -395,7 +396,7 @@ public:
FilteredDestructor<T> cleaner(m_d);
}
- void delegate(const QMetaTypeSwitcher::UnknownType*)
+ void delegate(const QMetaTypeSwitcher::NotBuiltinType*)
{
qWarning("Trying to destruct an instance of an invalid type, type id: %i", m_d->type);
}
@@ -410,7 +411,7 @@ Q_CORE_EXPORT void registerHandler(const int /* Modules::Names */ name, const QV
Q_CORE_EXPORT void unregisterHandler(const int /* Modules::Names */ name);
}
-#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM)
+#if !defined(QT_NO_DEBUG_STREAM)
template<class Filter>
class QVariantDebugStream
{
@@ -441,7 +442,7 @@ public:
Filtered<T> streamIt(m_debugStream, m_d);
}
- void delegate(const QMetaTypeSwitcher::UnknownType*)
+ void delegate(const QMetaTypeSwitcher::NotBuiltinType*)
{
qWarning("Trying to stream an instance of an invalid type, type id: %i", m_d->type);
}