diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-08-18 07:59:31 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-08-18 07:59:31 (GMT) |
commit | 223746067a9a1b3f5c6195868b5e510311608ca1 (patch) | |
tree | f8dfc604a035075e4a7e6d20e0930a6c6cfc4db8 | |
parent | e4fad48d5e5ac227381bb9fba05dfb31a8338ed5 (diff) | |
download | Qt-223746067a9a1b3f5c6195868b5e510311608ca1.zip Qt-223746067a9a1b3f5c6195868b5e510311608ca1.tar.gz Qt-223746067a9a1b3f5c6195868b5e510311608ca1.tar.bz2 |
Resolve attached property typenames in correct context.
The imports of the component containing the reference to the
attached property are used to resolve typenames, rather than
assuming "Qt" namespace.
-rw-r--r-- | src/declarative/qml/qmlcontext.cpp | 18 | ||||
-rw-r--r-- | src/declarative/qml/qmlcontext.h | 3 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 5 | ||||
-rw-r--r-- | src/declarative/qml/qmlmetaproperty.cpp | 20 |
4 files changed, 38 insertions, 8 deletions
diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index 451dbcc..b73471a 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -451,4 +451,22 @@ void QmlContext::setBaseUrl(const QUrl &baseUrl) d_func()->url = baseUrl; } +/*! + Returns the base url of the component, or the containing component + if none is set. +*/ +QUrl QmlContext::baseUrl() const +{ + Q_D(const QmlContext); + const QmlContext* p = this; + while (p && p->d_func()->url.isEmpty()) { + p = p->parentContext(); + } + if (p) + return p->d_func()->url; + else + return QUrl(); +} + + QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlcontext.h b/src/declarative/qml/qmlcontext.h index 70a81fc..65d711c 100644 --- a/src/declarative/qml/qmlcontext.h +++ b/src/declarative/qml/qmlcontext.h @@ -56,6 +56,8 @@ class QString; class QmlEngine; class QmlRefCount; class QmlContextPrivate; +class QmlCompositeTypeData; + class Q_DECLARATIVE_EXPORT QmlContext : public QObject { Q_OBJECT @@ -76,6 +78,7 @@ public: QUrl resolvedUrl(const QUrl &); void setBaseUrl(const QUrl &); + QUrl baseUrl() const; private: friend class QmlVME; diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 6756642..558bd49 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -191,7 +191,10 @@ QmlEnginePrivate::queryObject(const QString &propName, { QScriptClass::QueryFlags rv = 0; - QmlMetaProperty prop(obj, propName, rootContext); + QmlContext *ctxt = QmlEngine::contextForObject(obj); + if (!ctxt) + ctxt = rootContext; + QmlMetaProperty prop(obj, propName, ctxt); if (prop.type() == QmlMetaProperty::Invalid) { QPair<const QMetaObject *, QString> key = qMakePair(obj->metaObject(), propName); diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index c1736cb..e69746e 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -41,6 +41,7 @@ #include "qmlmetaproperty.h" #include "qmlmetaproperty_p.h" +#include "qmlcompositetypedata_p.h" #include <qml.h> #include <private/qfxperf_p.h> #include <QStringList> @@ -216,14 +217,19 @@ void QmlMetaPropertyPrivate::initProperty(QObject *obj, const QString &name) if (name.isEmpty() || !obj) return; - if (name.at(0).isUpper()) { + if (enginePrivate && name.at(0).isUpper()) { // Attached property - // XXX name should be resolved with QmlEngine::resolveType(), not like this! - QmlType *t = QmlMetaType::qmlType("Qt/"+name.toLatin1(),-1,-1); - if (t && t->attachedPropertiesFunction()) { - attachedFunc = t->index(); - if (attachedFunc != -1) - type = QmlMetaProperty::Property | QmlMetaProperty::Attached; + QmlCompositeTypeData *typeData = + enginePrivate->typeManager.get(context->baseUrl()); + + if (typeData) { + QmlType *t = 0; + enginePrivate->resolveType(typeData->imports, name.toLatin1(), &t, 0); + if (t && t->attachedPropertiesFunction()) { + attachedFunc = t->index(); + if (attachedFunc != -1) + type = QmlMetaProperty::Property | QmlMetaProperty::Attached; + } } return; |