summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qml.h
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-04-28 01:32:24 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-04-28 01:32:24 (GMT)
commit4927fb460e12ee8b4dada1025ad042d2b6b9b6f4 (patch)
tree512d035357c8b56859c01ca7d211b86ec986787d /src/declarative/qml/qml.h
parenteae3489b3f2fba9d733ca50eb89dc92a6e96e6f8 (diff)
downloadQt-4927fb460e12ee8b4dada1025ad042d2b6b9b6f4.zip
Qt-4927fb460e12ee8b4dada1025ad042d2b6b9b6f4.tar.gz
Qt-4927fb460e12ee8b4dada1025ad042d2b6b9b6f4.tar.bz2
Use QObject declarative data to store attached properties.
An element's qmlAttachedProperties() function will now only ever get called once per object.
Diffstat (limited to 'src/declarative/qml/qml.h')
-rw-r--r--src/declarative/qml/qml.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/declarative/qml/qml.h b/src/declarative/qml/qml.h
index fb288b7..2d8d83e 100644
--- a/src/declarative/qml/qml.h
+++ b/src/declarative/qml/qml.h
@@ -92,6 +92,22 @@ class QmlContext;
class QmlEngine;
Q_DECLARATIVE_EXPORT QmlContext *qmlContext(const QObject *);
Q_DECLARATIVE_EXPORT QmlEngine *qmlEngine(const QObject *);
+Q_DECLARATIVE_EXPORT QObject *qmlAttachedPropertiesObjectById(int, const QObject *);
+
+template<typename T>
+QObject *qmlAttachedPropertiesObject(const QObject *obj)
+{
+ // ### is this threadsafe?
+ static int idx = -1;
+
+ if(idx == -1)
+ idx = QmlMetaType::attachedPropertiesFuncId(&T::staticMetaObject);
+
+ if(idx == -1 || !obj)
+ return 0;
+
+ return qmlAttachedPropertiesObjectById(obj, idx);
+}
QML_DECLARE_TYPE(QObject);
Q_DECLARE_METATYPE(QVariant);