summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-05-22 03:47:04 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-05-22 03:47:04 (GMT)
commit6ddbc147cadc4d450bb8e20cedf1b99e0fcbf894 (patch)
tree5a63e3cd24eb44072ae67d0f248cdc546d310d77 /src
parent3158bf19bd49f72ca379203ea259e7b2d371f0d4 (diff)
downloadQt-6ddbc147cadc4d450bb8e20cedf1b99e0fcbf894.zip
Qt-6ddbc147cadc4d450bb8e20cedf1b99e0fcbf894.tar.gz
Qt-6ddbc147cadc4d450bb8e20cedf1b99e0fcbf894.tar.bz2
Store the type of the attached properties object
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/qmlmetatype.cpp14
-rw-r--r--src/declarative/qml/qmlmetatype.h24
-rw-r--r--src/declarative/qml/qmlprivate.h96
3 files changed, 89 insertions, 45 deletions
diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp
index 2e490a4..6d44f7a 100644
--- a/src/declarative/qml/qmlmetatype.cpp
+++ b/src/declarative/qml/qmlmetatype.cpp
@@ -112,6 +112,7 @@ public:
QmlPrivate::Func m_opFunc;
const QMetaObject *m_baseMetaObject;
QmlAttachedPropertiesFunc m_attachedPropertiesFunc;
+ const QMetaObject *m_attachedPropertiesType;
int m_parserStatusCast;
QmlPrivate::CreateFunc m_extFunc;
const QMetaObject *m_extMetaObject;
@@ -124,7 +125,7 @@ public:
QmlTypePrivate::QmlTypePrivate()
: m_isInterface(false), m_iid(0), m_typeId(0), m_listId(0), m_qmlListId(0),
- m_opFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0),
+ m_opFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0),
m_parserStatusCast(-1), m_extFunc(0), m_extMetaObject(0), m_index(-1),
m_customParser(0), m_isSetup(false)
{
@@ -149,6 +150,7 @@ QmlType::QmlType(int type, int listType, int qmlListType,
QmlPrivate::Func opFunc, const char *qmlName,
const QMetaObject *metaObject,
QmlAttachedPropertiesFunc attachedPropertiesFunc,
+ const QMetaObject *attachedType,
int parserStatusCast, QmlPrivate::CreateFunc extFunc,
const QMetaObject *extMetaObject, int index,
QmlCustomParser *customParser)
@@ -161,6 +163,7 @@ QmlType::QmlType(int type, int listType, int qmlListType,
d->m_opFunc = opFunc;
d->m_baseMetaObject = metaObject;
d->m_attachedPropertiesFunc = attachedPropertiesFunc;
+ d->m_attachedPropertiesType = attachedType;
d->m_parserStatusCast = parserStatusCast;
d->m_extFunc = extFunc;
d->m_index = index;
@@ -348,6 +351,11 @@ QmlAttachedPropertiesFunc QmlType::attachedPropertiesFunction() const
return d->m_attachedPropertiesFunc;
}
+const QMetaObject *QmlType::attachedPropertiesType() const
+{
+ return d->m_attachedPropertiesType;
+}
+
int QmlType::parserStatusCast() const
{
return d->m_parserStatusCast;
@@ -404,7 +412,7 @@ int QmlMetaType::registerInterface(const QmlPrivate::MetaTypeIds &id,
return index;
}
-int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Func func, const char *cname, const QMetaObject *mo, QmlAttachedPropertiesFunc attach, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *parser)
+int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Func func, const char *cname, const QMetaObject *mo, QmlAttachedPropertiesFunc attach, const QMetaObject *attachMo, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *parser)
{
Q_UNUSED(object);
QWriteLocker lock(metaTypeDataLock());
@@ -421,7 +429,7 @@ int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Fun
int index = data->types.count();
QmlType *type = new QmlType(id.typeId, id.listId, id.qmlListId,
- func, cname, mo, attach, pStatus, extFunc,
+ func, cname, mo, attach, attachMo, pStatus, extFunc,
extmo, index, parser);
data->types.append(type);
diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h
index cc3887c..d10a0f0 100644
--- a/src/declarative/qml/qmlmetatype.h
+++ b/src/declarative/qml/qmlmetatype.h
@@ -59,7 +59,7 @@ class QmlCustomParser;
class Q_DECLARATIVE_EXPORT QmlMetaType
{
public:
- static int registerType(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *);
+ static int registerType(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *);
static int registerInterface(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *);
static bool copy(int type, void *data, const void *copy = 0);
@@ -136,6 +136,7 @@ public:
const QMetaObject *baseMetaObject() const;
QmlAttachedPropertiesFunc attachedPropertiesFunction() const;
+ const QMetaObject *attachedPropertiesType() const;
int parserStatusCast() const;
QVariant fromObject(QObject *) const;
@@ -146,7 +147,7 @@ private:
friend class QmlMetaType;
friend class QmlTypePrivate;
QmlType(int, int, int, QmlPrivate::Func, const char *, int);
- QmlType(int, int, int, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *);
+ QmlType(int, int, int, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *);
~QmlType();
QmlTypePrivate *d;
@@ -165,6 +166,7 @@ int qmlRegisterType(const char *typeName)
return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op<T>, 0,
&T::staticMetaObject,
QmlPrivate::attachedPropertiesFunc<T>(),
+ QmlPrivate::attachedPropertiesMetaObject<T>(),
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
0, 0, 0);
@@ -183,6 +185,7 @@ int qmlRegisterType(const char *qmlName, const char *typeName)
return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>, qmlName,
&T::staticMetaObject,
QmlPrivate::attachedPropertiesFunc<T>(),
+ QmlPrivate::attachedPropertiesMetaObject<T>(),
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
0, 0, 0);
@@ -200,11 +203,15 @@ int qmlRegisterExtendedType(const char *typeName)
QmlAttachedPropertiesFunc attached =
QmlPrivate::attachedPropertiesFunc<E>();
- if (!attached)
+ const QMetaObject * attachedMo =
+ QmlPrivate::attachedPropertiesMetaObject<E>();
+ if (!attached) {
attached = QmlPrivate::attachedPropertiesFunc<T>();
+ attachedMo = QmlPrivate::attachedPropertiesMetaObject<T>();
+ }
return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op<T>, 0,
- &T::staticMetaObject, attached,
+ &T::staticMetaObject, attached, attachedMo,
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
&QmlPrivate::CreateParent<E>::create, &E::staticMetaObject, 0);
@@ -222,13 +229,17 @@ int qmlRegisterExtendedType(const char *qmlName, const char *typeName)
QmlAttachedPropertiesFunc attached =
QmlPrivate::attachedPropertiesFunc<E>();
- if (!attached)
+ const QMetaObject * attachedMo =
+ QmlPrivate::attachedPropertiesMetaObject<E>();
+ if (!attached) {
attached = QmlPrivate::attachedPropertiesFunc<T>();
+ attachedMo = QmlPrivate::attachedPropertiesMetaObject<T>();
+ }
return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>,
qmlName,
&T::staticMetaObject,
- attached,
+ attached, attachedMo,
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
&QmlPrivate::CreateParent<E>::create,
@@ -263,6 +274,7 @@ int qmlRegisterCustomType(const char *qmlName, const char *typeName, QmlCustomPa
return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>, qmlName,
&T::staticMetaObject,
QmlPrivate::attachedPropertiesFunc<T>(),
+ QmlPrivate::attachedPropertiesMetaObject<T>(),
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
0, 0, parser);
diff --git a/src/declarative/qml/qmlprivate.h b/src/declarative/qml/qmlprivate.h
index 590e0c0..2a9c503 100644
--- a/src/declarative/qml/qmlprivate.h
+++ b/src/declarative/qml/qmlprivate.h
@@ -123,57 +123,81 @@ namespace QmlPrivate
}
};
- template<typename T, int N>
- struct AttachedPropertySelector
- {
- static inline QmlAttachedPropertiesFunc func()
- {
- return 0;
- }
- };
- template<typename T>
- struct AttachedPropertySelector<T, 1>
- {
- static inline QmlAttachedPropertiesFunc func()
- {
- return &T::qmlAttachedProperties;
- }
- };
-
- template < typename T >
- class has_attachedProperties {
+ template <typename T>
+ class has_attachedPropertiesMember
+ {
typedef int yes_type;
typedef char no_type;
+ template <int>
+ struct Selector {};
- template<typename S, QObject *(S::*)(QObject *)>
- struct dummy {};
-
- template<typename S, QObject *(S::*)(QObject *) const>
- struct dummy_const {};
-
- template<typename S, QObject *(*) (QObject *)>
- struct dummy_static {};
+ template <typename S>
+ static yes_type test(Selector<sizeof(&S::qmlAttachedProperties)>*);
- template<typename S>
- static no_type check(dummy<S, &S::qmlAttachedProperties> *);
+ template <typename S>
+ static no_type test(...);
- template<typename S>
- static no_type check(dummy_const<S, &S::qmlAttachedProperties> *);
+ public:
+ static bool const value = sizeof(test<T>(0)) == sizeof(yes_type);
+ };
- template<typename S>
- static yes_type check(dummy_static<S, &S::qmlAttachedProperties> *);
+ template <typename T, bool hasMember>
+ class has_attachedPropertiesMethod
+ {
+ typedef int yes_type;
+ typedef char no_type;
- template<typename S>
+ template<typename ReturnType>
+ static yes_type check(ReturnType *(*)(QObject *));
static no_type check(...);
public:
- static bool const value = sizeof(check<T>(0)) == sizeof(yes_type);
+ static bool const value = sizeof(check(&T::qmlAttachedProperties)) == sizeof(yes_type);
};
+ template <typename T>
+ class has_attachedPropertiesMethod<T, false>
+ {
+ public:
+ static bool const value = false;
+ };
+
+ template<typename T, int N>
+ class AttachedPropertySelector
+ {
+ public:
+ static inline QmlAttachedPropertiesFunc func() { return 0; }
+ static inline const QMetaObject *metaObject() { return 0; }
+ };
+ template<typename T>
+ class AttachedPropertySelector<T, 1>
+ {
+ static inline QObject *attachedProperties(QObject *obj) {
+ return T::qmlAttachedProperties(obj);
+ }
+ template<typename ReturnType>
+ static inline const QMetaObject *attachedPropertiesMetaObject(ReturnType *(*)(QObject *)) {
+ return &ReturnType::staticMetaObject;
+ }
+ public:
+ static inline QmlAttachedPropertiesFunc func() {
+ return &attachedProperties;
+ }
+ static inline const QMetaObject *metaObject() {
+ return attachedPropertiesMetaObject(&T::qmlAttachedProperties);
+ }
+ };
+
template<typename T>
inline QmlAttachedPropertiesFunc attachedPropertiesFunc()
{
- return AttachedPropertySelector<T, has_attachedProperties<T>::value>::func();
+ return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::func();
+ }
+
+ template<typename T>
+ inline const QMetaObject *attachedPropertiesMetaObject()
+ {
+ return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::metaObject();
}
struct MetaTypeIds {