summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qmlcontext.cpp18
-rw-r--r--src/declarative/qml/qmlcontext.h3
-rw-r--r--src/declarative/qml/qmlengine.cpp5
-rw-r--r--src/declarative/qml/qmlmetaproperty.cpp20
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;