summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetatype_p.h
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>2011-11-29 15:42:33 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-04 14:25:25 +0100
commit08863b6fdaa8383e2274826db3ec42c4d4f11576 (patch)
treea3cc772ada845bffa60f5b186defeb469bf1f5af /src/corelib/kernel/qmetatype_p.h
parent52fc6694b87e93fe0828424bb26d9279785de3e7 (diff)
Refactor QVariant handlers.
QVariant implementation is based on delegation to a handler. The handler has rather simple construction, it is a set of function that implements a switch statement over known types and redirects calls to a right method of an encapsulated types instance. Unfortunately after qt modularization project, it is not easy to use types directly from different modules, as they can be undefined or completely unaccessible. Which means that each module has to implement own handler to cooperate correctly with QVariant. We can suspect that list of modules known to QVariant will grow and it is not limited to GUI, Widgets and Core, therefore it would be nice to have an unified, from performance and source code point of view, way of working with handlers. This patch is an attempt to cleanup handlers. Keynotes: - Each handler is working only on types defined in the same module - Core handler implements handling of primitive types too - Custom types have an own handler - Each handler is independent which means that dispatch between handlers is done on QVariant level - Handlers might be registered / unregistered using same interface Change-Id: Ib096df65e2c4ce464bc7a684aade5af7d1264c24 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/kernel/qmetatype_p.h')
-rw-r--r--src/corelib/kernel/qmetatype_p.h34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h
index 46c5697678..391f37c93d 100644
--- a/src/corelib/kernel/qmetatype_p.h
+++ b/src/corelib/kernel/qmetatype_p.h
@@ -57,11 +57,22 @@
QT_BEGIN_NAMESPACE
-enum { /* TYPEMODULEINFO flags */
- Q_CORE_TYPE = 1,
- Q_GUI_TYPE = 2,
- Q_WIDGET_TYPE = 3
-};
+namespace QModulesPrivate {
+enum Names { Core, Gui, Widgets, Unknown, ModulesCount /* ModulesCount has to be at the end */ };
+
+static inline int moduleForType(const int typeId)
+{
+ if (typeId <= QMetaType::LastCoreType)
+ return Core;
+ if (typeId <= QMetaType::LastGuiType)
+ return Gui;
+ if (typeId <= QMetaType::LastWidgetsType)
+ return Widgets;
+ if (typeId <= QMetaType::LastCoreExtType)
+ return Core;
+ return Unknown;
+}
+}
template <typename T>
class QTypeModuleInfo
@@ -73,7 +84,6 @@ public:
IsGui = false,
IsUnknown = !IsCore
};
- static inline int module() { return IsCore ? Q_CORE_TYPE : 0; }
};
#define QT_ASSIGN_TYPE_TO_MODULE(TYPE, MODULE) \
@@ -82,9 +92,9 @@ class QTypeModuleInfo<TYPE > \
{ \
public: \
enum Module { \
- IsCore = (((MODULE) == (Q_CORE_TYPE))), \
- IsWidget = (((MODULE) == (Q_WIDGET_TYPE))), \
- IsGui = (((MODULE) == (Q_GUI_TYPE))), \
+ IsCore = (((MODULE) == (QModulesPrivate::Core))), \
+ IsWidget = (((MODULE) == (QModulesPrivate::Widgets))), \
+ IsGui = (((MODULE) == (QModulesPrivate::Gui))), \
IsUnknown = !(IsCore || IsWidget || IsGui) \
}; \
static inline int module() { return MODULE; } \
@@ -96,11 +106,11 @@ public: \
#define QT_DECLARE_CORE_MODULE_TYPES_ITER(TypeName, TypeId, Name) \
- QT_ASSIGN_TYPE_TO_MODULE(Name, Q_CORE_TYPE);
+ QT_ASSIGN_TYPE_TO_MODULE(Name, QModulesPrivate::Core);
#define QT_DECLARE_GUI_MODULE_TYPES_ITER(TypeName, TypeId, Name) \
- QT_ASSIGN_TYPE_TO_MODULE(Name, Q_GUI_TYPE);
+ QT_ASSIGN_TYPE_TO_MODULE(Name, QModulesPrivate::Gui);
#define QT_DECLARE_WIDGETS_MODULE_TYPES_ITER(TypeName, TypeId, Name) \
- QT_ASSIGN_TYPE_TO_MODULE(Name, Q_WIDGET_TYPE);
+ QT_ASSIGN_TYPE_TO_MODULE(Name, QModulesPrivate::Widgets);
QT_FOR_EACH_STATIC_CORE_CLASS(QT_DECLARE_CORE_MODULE_TYPES_ITER)
QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_DECLARE_CORE_MODULE_TYPES_ITER)