1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtCore module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "qmetatype.h"
60 namespace QModulesPrivate {
61 enum Names { Core, Gui, Widgets, Unknown, ModulesCount /* ModulesCount has to be at the end */ };
63 static inline int moduleForType(const int typeId)
65 if (typeId <= QMetaType::LastCoreType)
67 if (typeId <= QMetaType::LastGuiType)
69 if (typeId <= QMetaType::LastWidgetsType)
80 IsCore = !QTypeInfo<T>::isComplex, // Primitive types are in Core
87 #define QT_ASSIGN_TYPE_TO_MODULE(TYPE, MODULE) \
89 class QTypeModuleInfo<TYPE > \
93 IsCore = (((MODULE) == (QModulesPrivate::Core))), \
94 IsWidget = (((MODULE) == (QModulesPrivate::Widgets))), \
95 IsGui = (((MODULE) == (QModulesPrivate::Gui))), \
96 IsUnknown = !(IsCore || IsWidget || IsGui) \
98 static inline int module() { return MODULE; } \
99 Q_STATIC_ASSERT((IsUnknown && !(IsCore || IsWidget || IsGui)) \
100 || (IsCore && !(IsUnknown || IsWidget || IsGui)) \
101 || (IsWidget && !(IsUnknown || IsCore || IsGui)) \
102 || (IsGui && !(IsUnknown || IsCore || IsWidget))); \
106 #define QT_DECLARE_CORE_MODULE_TYPES_ITER(TypeName, TypeId, Name) \
107 QT_ASSIGN_TYPE_TO_MODULE(Name, QModulesPrivate::Core);
108 #define QT_DECLARE_GUI_MODULE_TYPES_ITER(TypeName, TypeId, Name) \
109 QT_ASSIGN_TYPE_TO_MODULE(Name, QModulesPrivate::Gui);
110 #define QT_DECLARE_WIDGETS_MODULE_TYPES_ITER(TypeName, TypeId, Name) \
111 QT_ASSIGN_TYPE_TO_MODULE(Name, QModulesPrivate::Widgets);
113 QT_FOR_EACH_STATIC_CORE_CLASS(QT_DECLARE_CORE_MODULE_TYPES_ITER)
114 QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_DECLARE_CORE_MODULE_TYPES_ITER)
115 QT_FOR_EACH_STATIC_GUI_CLASS(QT_DECLARE_GUI_MODULE_TYPES_ITER)
116 QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_DECLARE_WIDGETS_MODULE_TYPES_ITER)
118 #undef QT_DECLARE_CORE_MODULE_TYPES_ITER
119 #undef QT_DECLARE_GUI_MODULE_TYPES_ITER
120 #undef QT_DECLARE_WIDGETS_MODULE_TYPES_ITER
122 class QMetaTypeInterface
125 QMetaType::Creator creator;
126 QMetaType::Deleter deleter;
127 QMetaType::SaveOperator saveOp;
128 QMetaType::LoadOperator loadOp;
129 QMetaType::Constructor constructor;
130 QMetaType::Destructor destructor;
132 quint32 flags; // same as QMetaType::TypeFlags
135 #ifndef QT_NO_DATASTREAM
136 # define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
137 /*saveOp*/(qMetaTypeSaveHelper<Type>), \
138 /*loadOp*/(qMetaTypeLoadHelper<Type>),
139 # define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \
143 # define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \
146 # define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
147 QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type)
150 #define QT_METATYPE_INTERFACE_INIT_IMPL(Type, DATASTREAM_DELEGATE) \
152 /*creator*/(qMetaTypeCreateHelper<Type>), \
153 /*deleter*/(qMetaTypeDeleteHelper<Type>), \
154 DATASTREAM_DELEGATE(Type) \
155 /*constructor*/(qMetaTypeConstructHelper<Type>), \
156 /*destructor*/(qMetaTypeDestructHelper<Type>), \
157 /*size*/(QTypeInfo<Type>::sizeOf), \
158 /*flags*/QtPrivate::QMetaTypeTypeFlags<Type>::Flags \
162 /* These QT_METATYPE_INTERFACE_INIT* macros are used to initialize QMetaTypeInterface instance.
164 - QT_METATYPE_INTERFACE_INIT(Type) -> It takes Type argument and creates all necessary wrapper functions for the Type,
165 it detects if QT_NO_DATASTREAM was defined. Probably it is the macro that you want to use.
167 - QT_METATYPE_INTERFACE_INIT_EMPTY() -> It initializes an empty QMetaTypeInterface instance.
169 - QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(Type) -> Temporary workaround for missing auto-detection of data stream
170 operators. It creates same instance as QT_METATYPE_INTERFACE_INIT(Type) but with null stream operators callbacks.
172 #define QT_METATYPE_INTERFACE_INIT(Type) QT_METATYPE_INTERFACE_INIT_IMPL(Type, QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL)
173 #define QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(Type) QT_METATYPE_INTERFACE_INIT_IMPL(Type, QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL)
174 #define QT_METATYPE_INTERFACE_INIT_EMPTY() \
178 QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL() \
185 namespace QtMetaTypePrivate {
187 struct TypeDefinition {
188 static const bool IsAvailable = true;
191 // Ignore these types, as incomplete
192 #ifdef QT_BOOTSTRAPPED
193 template<> struct TypeDefinition<QBitArray> { static const bool IsAvailable = false; };
194 template<> struct TypeDefinition<QEasingCurve> { static const bool IsAvailable = false; };
195 template<> struct TypeDefinition<QJsonArray> { static const bool IsAvailable = false; };
196 template<> struct TypeDefinition<QJsonDocument> { static const bool IsAvailable = false; };
197 template<> struct TypeDefinition<QJsonObject> { static const bool IsAvailable = false; };
198 template<> struct TypeDefinition<QJsonValue> { static const bool IsAvailable = false; };
199 template<> struct TypeDefinition<QModelIndex> { static const bool IsAvailable = false; };
200 template<> struct TypeDefinition<QUrl> { static const bool IsAvailable = false; };
202 #ifdef QT_NO_GEOM_VARIANT
203 template<> struct TypeDefinition<QRect> { static const bool IsAvailable = false; };
204 template<> struct TypeDefinition<QRectF> { static const bool IsAvailable = false; };
205 template<> struct TypeDefinition<QSize> { static const bool IsAvailable = false; };
206 template<> struct TypeDefinition<QSizeF> { static const bool IsAvailable = false; };
207 template<> struct TypeDefinition<QLine> { static const bool IsAvailable = false; };
208 template<> struct TypeDefinition<QLineF> { static const bool IsAvailable = false; };
209 template<> struct TypeDefinition<QPoint> { static const bool IsAvailable = false; };
210 template<> struct TypeDefinition<QPointF> { static const bool IsAvailable = false; };
213 template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = false; };
215 #if defined(QT_BOOTSTRAPPED) || defined(QT_NO_REGEXP)
216 template<> struct TypeDefinition<QRegularExpression> { static const bool IsAvailable = false; };
218 #ifdef QT_NO_SHORTCUT
219 template<> struct TypeDefinition<QKeySequence> { static const bool IsAvailable = false; };
222 template<> struct TypeDefinition<QCursor> { static const bool IsAvailable = false; };
224 #ifdef QT_NO_MATRIX4X4
225 template<> struct TypeDefinition<QMatrix4x4> { static const bool IsAvailable = false; };
227 #ifdef QT_NO_VECTOR2D
228 template<> struct TypeDefinition<QVector2D> { static const bool IsAvailable = false; };
230 #ifdef QT_NO_VECTOR3D
231 template<> struct TypeDefinition<QVector3D> { static const bool IsAvailable = false; };
233 #ifdef QT_NO_VECTOR4D
234 template<> struct TypeDefinition<QVector4D> { static const bool IsAvailable = false; };
236 #ifdef QT_NO_QUATERNION
237 template<> struct TypeDefinition<QQuaternion> { static const bool IsAvailable = false; };
239 } //namespace QtMetaTypePrivate
243 #endif // QMETATYPE_P_H