Code cleanup in QVariant and QMetaType.
QMetaTypeGuiHelper was generalized and renamed to QMetaTypeInterface. From now all types will have common interface which can be used for basic operations. Change-Id: I50d67f4a8081fa0f75c9d530a8211593ec37bc55 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
parent
dae1df576f
commit
ce4343a52f
@ -287,42 +287,14 @@ static const struct { const char * typeName; int typeNameLength; int type; } typ
|
||||
{0, 0, QMetaType::Void}
|
||||
};
|
||||
|
||||
struct QMetaTypeGuiHelper
|
||||
{
|
||||
QMetaType::Creator creator;
|
||||
QMetaType::Deleter deleter;
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
QMetaType::SaveOperator saveOp;
|
||||
QMetaType::LoadOperator loadOp;
|
||||
#endif
|
||||
QMetaType::Constructor constructor;
|
||||
QMetaType::Destructor destructor;
|
||||
int size;
|
||||
};
|
||||
Q_CORE_EXPORT const QMetaTypeGuiHelper *qMetaTypeGuiHelper = 0;
|
||||
Q_CORE_EXPORT const QMetaTypeGuiHelper *qMetaTypeWidgetsHelper = 0;
|
||||
Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper = 0;
|
||||
Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper = 0;
|
||||
|
||||
class QCustomTypeInfo
|
||||
class QCustomTypeInfo : public QMetaTypeInterface
|
||||
{
|
||||
public:
|
||||
QCustomTypeInfo() : typeName(), creator(0), deleter(0)
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
, saveOp(0), loadOp(0)
|
||||
#endif
|
||||
, constructor(0), destructor(0), size(0)
|
||||
{}
|
||||
|
||||
QByteArray typeName;
|
||||
QMetaType::Creator creator;
|
||||
QMetaType::Deleter deleter;
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
QMetaType::SaveOperator saveOp;
|
||||
QMetaType::LoadOperator loadOp;
|
||||
#endif
|
||||
int alias;
|
||||
QMetaType::Constructor constructor;
|
||||
QMetaType::Destructor destructor;
|
||||
int size;
|
||||
};
|
||||
|
||||
Q_DECLARE_TYPEINFO(QCustomTypeInfo, Q_MOVABLE_TYPE);
|
||||
|
@ -111,6 +111,72 @@ QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_DECLARE_WIDGETS_MODULE_TYPES_ITER)
|
||||
#undef QT_DECLARE_GUI_MODULE_TYPES_ITER
|
||||
#undef QT_DECLARE_WIDGETS_MODULE_TYPES_ITER
|
||||
|
||||
class QMetaTypeInterface
|
||||
{
|
||||
private:
|
||||
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; }
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
static void saver(QDataStream &stream, const T *t) { stream << *t; }
|
||||
static void loader(QDataStream &stream, T *t) { stream >> *t; }
|
||||
#endif // QT_NO_DATASTREAM
|
||||
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;
|
||||
}
|
||||
};
|
||||
public:
|
||||
template<typename T>
|
||||
QMetaTypeInterface(T * = 0)
|
||||
: creator(reinterpret_cast<QMetaType::Creator>(Impl<T>::creator))
|
||||
, deleter(reinterpret_cast<QMetaType::Deleter>(Impl<T>::deleter))
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
, saveOp(reinterpret_cast<QMetaType::SaveOperator>(Impl<T>::saver))
|
||||
, loadOp(reinterpret_cast<QMetaType::LoadOperator>(Impl<T>::loader))
|
||||
#endif
|
||||
, constructor(reinterpret_cast<QMetaType::Constructor>(Impl<T>::constructor))
|
||||
, destructor(reinterpret_cast<QMetaType::Destructor>(Impl<T>::destructor))
|
||||
, size(sizeof(T))
|
||||
{}
|
||||
|
||||
QMetaTypeInterface()
|
||||
: creator(0)
|
||||
, deleter(0)
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
, saveOp(0)
|
||||
, loadOp(0)
|
||||
#endif
|
||||
, constructor(0)
|
||||
, destructor(0)
|
||||
, size(0)
|
||||
{}
|
||||
|
||||
QMetaType::Creator creator;
|
||||
QMetaType::Deleter deleter;
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
QMetaType::SaveOperator saveOp;
|
||||
QMetaType::LoadOperator loadOp;
|
||||
#endif
|
||||
QMetaType::Constructor constructor;
|
||||
QMetaType::Destructor destructor;
|
||||
int size;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QMETATYPE_P_H
|
||||
|
@ -474,157 +474,16 @@ const QVariant::Handler qt_gui_variant_handler = {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct QMetaTypeGuiHelper
|
||||
{
|
||||
QMetaType::Creator creator;
|
||||
QMetaType::Deleter deleter;
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
QMetaType::SaveOperator saveOp;
|
||||
QMetaType::LoadOperator loadOp;
|
||||
#endif
|
||||
QMetaType::Constructor constructor;
|
||||
QMetaType::Destructor destructor;
|
||||
int size;
|
||||
extern Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper;
|
||||
|
||||
#define QT_IMPL_METATYPEINTERFACE_GUI_TYPES(MetaTypeName, MetaTypeId, RealName) \
|
||||
QMetaTypeInterface(static_cast<RealName*>(0)),
|
||||
|
||||
static const QMetaTypeInterface qVariantGuiHelper[] = {
|
||||
QT_FOR_EACH_STATIC_GUI_CLASS(QT_IMPL_METATYPEINTERFACE_GUI_TYPES)
|
||||
};
|
||||
|
||||
extern Q_CORE_EXPORT const QMetaTypeGuiHelper *qMetaTypeGuiHelper;
|
||||
|
||||
|
||||
#ifdef QT_NO_DATASTREAM
|
||||
# define Q_DECL_METATYPE_HELPER(TYPE) \
|
||||
typedef void *(*QCreate##TYPE)(const TYPE *); \
|
||||
static const QCreate##TYPE qCreate##TYPE = qMetaTypeCreateHelper<TYPE>; \
|
||||
typedef void (*QDelete##TYPE)(TYPE *); \
|
||||
static const QDelete##TYPE qDelete##TYPE = qMetaTypeDeleteHelper<TYPE>; \
|
||||
typedef void *(*QConstruct##TYPE)(void *, const TYPE *); \
|
||||
static const QConstruct##TYPE qConstruct##TYPE = qMetaTypeConstructHelper<TYPE>; \
|
||||
typedef void (*QDestruct##TYPE)(TYPE *); \
|
||||
static const QDestruct##TYPE qDestruct##TYPE = qMetaTypeDestructHelper<TYPE>;
|
||||
#else
|
||||
# define Q_DECL_METATYPE_HELPER(TYPE) \
|
||||
typedef void *(*QCreate##TYPE)(const TYPE *); \
|
||||
static const QCreate##TYPE qCreate##TYPE = qMetaTypeCreateHelper<TYPE>; \
|
||||
typedef void (*QDelete##TYPE)(TYPE *); \
|
||||
static const QDelete##TYPE qDelete##TYPE = qMetaTypeDeleteHelper<TYPE>; \
|
||||
typedef void *(*QConstruct##TYPE)(void *, const TYPE *); \
|
||||
static const QConstruct##TYPE qConstruct##TYPE = qMetaTypeConstructHelper<TYPE>; \
|
||||
typedef void (*QDestruct##TYPE)(TYPE *); \
|
||||
static const QDestruct##TYPE qDestruct##TYPE = qMetaTypeDestructHelper<TYPE>; \
|
||||
typedef void (*QSave##TYPE)(QDataStream &, const TYPE *); \
|
||||
static const QSave##TYPE qSave##TYPE = qMetaTypeSaveHelper<TYPE>; \
|
||||
typedef void (*QLoad##TYPE)(QDataStream &, TYPE *); \
|
||||
static const QLoad##TYPE qLoad##TYPE = qMetaTypeLoadHelper<TYPE>;
|
||||
#endif
|
||||
|
||||
Q_DECL_METATYPE_HELPER(QFont)
|
||||
Q_DECL_METATYPE_HELPER(QPixmap)
|
||||
Q_DECL_METATYPE_HELPER(QBrush)
|
||||
Q_DECL_METATYPE_HELPER(QColor)
|
||||
Q_DECL_METATYPE_HELPER(QPalette)
|
||||
Q_DECL_METATYPE_HELPER(QImage)
|
||||
Q_DECL_METATYPE_HELPER(QPolygon)
|
||||
Q_DECL_METATYPE_HELPER(QRegion)
|
||||
Q_DECL_METATYPE_HELPER(QBitmap)
|
||||
#ifndef QT_NO_CURSOR
|
||||
Q_DECL_METATYPE_HELPER(QCursor)
|
||||
#endif
|
||||
#ifndef QT_NO_SHORTCUT
|
||||
Q_DECL_METATYPE_HELPER(QKeySequence)
|
||||
#endif
|
||||
Q_DECL_METATYPE_HELPER(QPen)
|
||||
Q_DECL_METATYPE_HELPER(QTextLength)
|
||||
Q_DECL_METATYPE_HELPER(QTextFormat)
|
||||
Q_DECL_METATYPE_HELPER(QMatrix)
|
||||
Q_DECL_METATYPE_HELPER(QTransform)
|
||||
#ifndef QT_NO_MATRIX4X4
|
||||
Q_DECL_METATYPE_HELPER(QMatrix4x4)
|
||||
#endif
|
||||
#ifndef QT_NO_VECTOR2D
|
||||
Q_DECL_METATYPE_HELPER(QVector2D)
|
||||
#endif
|
||||
#ifndef QT_NO_VECTOR3D
|
||||
Q_DECL_METATYPE_HELPER(QVector3D)
|
||||
#endif
|
||||
#ifndef QT_NO_VECTOR4D
|
||||
Q_DECL_METATYPE_HELPER(QVector4D)
|
||||
#endif
|
||||
#ifndef QT_NO_QUATERNION
|
||||
Q_DECL_METATYPE_HELPER(QQuaternion)
|
||||
#endif
|
||||
Q_DECL_METATYPE_HELPER(QPolygonF)
|
||||
|
||||
#ifdef QT_NO_DATASTREAM
|
||||
# define Q_IMPL_METATYPE_HELPER(TYPE) \
|
||||
{ reinterpret_cast<QMetaType::Creator>(qCreate##TYPE), \
|
||||
reinterpret_cast<QMetaType::Deleter>(qDelete##TYPE), \
|
||||
reinterpret_cast<QMetaType::Constructor>(qConstruct##TYPE), \
|
||||
reinterpret_cast<QMetaType::Destructor>(qDestruct##TYPE), \
|
||||
sizeof(TYPE) \
|
||||
}
|
||||
#else
|
||||
# define Q_IMPL_METATYPE_HELPER(TYPE) \
|
||||
{ reinterpret_cast<QMetaType::Creator>(qCreate##TYPE), \
|
||||
reinterpret_cast<QMetaType::Deleter>(qDelete##TYPE), \
|
||||
reinterpret_cast<QMetaType::SaveOperator>(qSave##TYPE), \
|
||||
reinterpret_cast<QMetaType::LoadOperator>(qLoad##TYPE), \
|
||||
reinterpret_cast<QMetaType::Constructor>(qConstruct##TYPE), \
|
||||
reinterpret_cast<QMetaType::Destructor>(qDestruct##TYPE), \
|
||||
sizeof(TYPE) \
|
||||
}
|
||||
#endif
|
||||
|
||||
static const QMetaTypeGuiHelper qVariantGuiHelper[] = {
|
||||
Q_IMPL_METATYPE_HELPER(QFont),
|
||||
Q_IMPL_METATYPE_HELPER(QPixmap),
|
||||
Q_IMPL_METATYPE_HELPER(QBrush),
|
||||
Q_IMPL_METATYPE_HELPER(QColor),
|
||||
Q_IMPL_METATYPE_HELPER(QPalette),
|
||||
Q_IMPL_METATYPE_HELPER(QImage),
|
||||
Q_IMPL_METATYPE_HELPER(QPolygon),
|
||||
Q_IMPL_METATYPE_HELPER(QRegion),
|
||||
Q_IMPL_METATYPE_HELPER(QBitmap),
|
||||
#ifdef QT_NO_CURSOR
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
#else
|
||||
Q_IMPL_METATYPE_HELPER(QCursor),
|
||||
#endif
|
||||
#ifdef QT_NO_SHORTCUT
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
#else
|
||||
Q_IMPL_METATYPE_HELPER(QKeySequence),
|
||||
#endif
|
||||
Q_IMPL_METATYPE_HELPER(QPen),
|
||||
Q_IMPL_METATYPE_HELPER(QTextLength),
|
||||
Q_IMPL_METATYPE_HELPER(QTextFormat),
|
||||
Q_IMPL_METATYPE_HELPER(QMatrix),
|
||||
Q_IMPL_METATYPE_HELPER(QTransform),
|
||||
#ifndef QT_NO_MATRIX4X4
|
||||
Q_IMPL_METATYPE_HELPER(QMatrix4x4),
|
||||
#else
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
#endif
|
||||
#ifndef QT_NO_VECTOR2D
|
||||
Q_IMPL_METATYPE_HELPER(QVector2D),
|
||||
#else
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
#endif
|
||||
#ifndef QT_NO_VECTOR3D
|
||||
Q_IMPL_METATYPE_HELPER(QVector3D),
|
||||
#else
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
#endif
|
||||
#ifndef QT_NO_VECTOR4D
|
||||
Q_IMPL_METATYPE_HELPER(QVector4D),
|
||||
#else
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
#endif
|
||||
#ifndef QT_NO_QUATERNION
|
||||
Q_IMPL_METATYPE_HELPER(QQuaternion),
|
||||
#else
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
#endif
|
||||
Q_IMPL_METATYPE_HELPER(QPolygonF)
|
||||
};
|
||||
#undef QT_IMPL_METATYPEINTERFACE_GUI_TYPES
|
||||
|
||||
static const QVariant::Handler *qt_guivariant_last_handler = 0;
|
||||
int qRegisterGuiVariant()
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "qsizepolicy.h"
|
||||
|
||||
#include "private/qvariant_p.h"
|
||||
#include <private/qmetatype_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -137,81 +138,16 @@ static const QVariant::Handler widgets_handler = {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct QMetaTypeGuiHelper
|
||||
{
|
||||
QMetaType::Creator creator;
|
||||
QMetaType::Deleter deleter;
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
QMetaType::SaveOperator saveOp;
|
||||
QMetaType::LoadOperator loadOp;
|
||||
#endif
|
||||
QMetaType::Constructor constructor;
|
||||
QMetaType::Destructor destructor;
|
||||
int size;
|
||||
extern Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper;
|
||||
|
||||
#define QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES(MetaTypeName, MetaTypeId, RealName) \
|
||||
QMetaTypeInterface(static_cast<RealName*>(0)),
|
||||
|
||||
static const QMetaTypeInterface qVariantWidgetsHelper[] = {
|
||||
QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES)
|
||||
};
|
||||
|
||||
extern Q_CORE_EXPORT const QMetaTypeGuiHelper *qMetaTypeWidgetsHelper;
|
||||
|
||||
|
||||
#ifdef QT_NO_DATASTREAM
|
||||
# define Q_DECL_METATYPE_HELPER(TYPE) \
|
||||
typedef void *(*QCreate##TYPE)(const TYPE *); \
|
||||
static const QCreate##TYPE qCreate##TYPE = qMetaTypeCreateHelper<TYPE>; \
|
||||
typedef void (*QDelete##TYPE)(TYPE *); \
|
||||
static const QDelete##TYPE qDelete##TYPE = qMetaTypeDeleteHelper<TYPE>; \
|
||||
typedef void *(*QConstruct##TYPE)(void *, const TYPE *); \
|
||||
static const QConstruct##TYPE qConstruct##TYPE = qMetaTypeConstructHelper<TYPE>; \
|
||||
typedef void (*QDestruct##TYPE)(TYPE *); \
|
||||
static const QDestruct##TYPE qDestruct##TYPE = qMetaTypeDestructHelper<TYPE>;
|
||||
#else
|
||||
# define Q_DECL_METATYPE_HELPER(TYPE) \
|
||||
typedef void *(*QCreate##TYPE)(const TYPE *); \
|
||||
static const QCreate##TYPE qCreate##TYPE = qMetaTypeCreateHelper<TYPE>; \
|
||||
typedef void (*QDelete##TYPE)(TYPE *); \
|
||||
static const QDelete##TYPE qDelete##TYPE = qMetaTypeDeleteHelper<TYPE>; \
|
||||
typedef void *(*QConstruct##TYPE)(void *, const TYPE *); \
|
||||
static const QConstruct##TYPE qConstruct##TYPE = qMetaTypeConstructHelper<TYPE>; \
|
||||
typedef void (*QDestruct##TYPE)(TYPE *); \
|
||||
static const QDestruct##TYPE qDestruct##TYPE = qMetaTypeDestructHelper<TYPE>; \
|
||||
typedef void (*QSave##TYPE)(QDataStream &, const TYPE *); \
|
||||
static const QSave##TYPE qSave##TYPE = qMetaTypeSaveHelper<TYPE>; \
|
||||
typedef void (*QLoad##TYPE)(QDataStream &, TYPE *); \
|
||||
static const QLoad##TYPE qLoad##TYPE = qMetaTypeLoadHelper<TYPE>;
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_ICON
|
||||
Q_DECL_METATYPE_HELPER(QIcon)
|
||||
#endif
|
||||
Q_DECL_METATYPE_HELPER(QSizePolicy)
|
||||
|
||||
#ifdef QT_NO_DATASTREAM
|
||||
# define Q_IMPL_METATYPE_HELPER(TYPE) \
|
||||
{ reinterpret_cast<QMetaType::Creator>(qCreate##TYPE), \
|
||||
reinterpret_cast<QMetaType::Deleter>(qDelete##TYPE), \
|
||||
reinterpret_cast<QMetaType::Constructor>(qConstruct##TYPE), \
|
||||
reinterpret_cast<QMetaType::Destructor>(qDestruct##TYPE), \
|
||||
sizeof(TYPE) \
|
||||
}
|
||||
#else
|
||||
# define Q_IMPL_METATYPE_HELPER(TYPE) \
|
||||
{ reinterpret_cast<QMetaType::Creator>(qCreate##TYPE), \
|
||||
reinterpret_cast<QMetaType::Deleter>(qDelete##TYPE), \
|
||||
reinterpret_cast<QMetaType::SaveOperator>(qSave##TYPE), \
|
||||
reinterpret_cast<QMetaType::LoadOperator>(qLoad##TYPE), \
|
||||
reinterpret_cast<QMetaType::Constructor>(qConstruct##TYPE), \
|
||||
reinterpret_cast<QMetaType::Destructor>(qDestruct##TYPE), \
|
||||
sizeof(TYPE) \
|
||||
}
|
||||
#endif
|
||||
|
||||
static const QMetaTypeGuiHelper qVariantWidgetsHelper[] = {
|
||||
#ifdef QT_NO_ICON
|
||||
{0, 0, 0, 0},
|
||||
#else
|
||||
Q_IMPL_METATYPE_HELPER(QIcon),
|
||||
#endif
|
||||
Q_IMPL_METATYPE_HELPER(QSizePolicy),
|
||||
};
|
||||
#undef QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES
|
||||
|
||||
extern Q_GUI_EXPORT const QVariant::Handler *qt_widgets_variant_handler;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user